Class: Lichess::UsersGateway
- Inherits:
-
Object
- Object
- Lichess::UsersGateway
- Defined in:
- lib/lichess/users_gateway.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #activity(username) ⇒ Object
- #all_top_ten ⇒ Object
- #get(usernames) ⇒ Object
-
#initialize(client) ⇒ UsersGateway
constructor
A new instance of UsersGateway.
- #leaderboard(variant, number_of_users = 10) ⇒ Object
Constructor Details
#initialize(client) ⇒ UsersGateway
Returns a new instance of UsersGateway.
7 8 9 |
# File 'lib/lichess/users_gateway.rb', line 7 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/lichess/users_gateway.rb', line 5 def client @client end |
Instance Method Details
#activity(username) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lichess/users_gateway.rb', line 27 def activity(username) path = "/api/user/#{username}/activity" result = @client.get(path) if result.body.to_s == "[]" raise Lichess::Exception::UserNotFound.new("#{username} not found") end JSON.parse(result.body) end |
#all_top_ten ⇒ Object
38 39 40 41 |
# File 'lib/lichess/users_gateway.rb', line 38 def all_top_ten path = "/player" JSON.parse(@client.get(path).body) end |
#get(usernames) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lichess/users_gateway.rb', line 11 def get(usernames) if usernames.is_a?(Array) path = "/api/users" result = @client.post(path, body: usernames.join(",")) else path = "/api/user/#{usernames}" result = @client.get(path) end if result.code == 404 raise Lichess::Exception::UserNotFound.new("#{usernames} not found") end JSON.parse(result.body) end |
#leaderboard(variant, number_of_users = 10) ⇒ Object
43 44 45 46 |
# File 'lib/lichess/users_gateway.rb', line 43 def leaderboard(variant, number_of_users = 10) path = "/player/top/#{number_of_users}/#{variant}" JSON.parse(@client.get(path).body) end |