Class: Lichess::UsersGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/lichess/users_gateway.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (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



22
23
24
25
26
27
28
29
30
31
# File 'lib/lichess/users_gateway.rb', line 22

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_tenObject



33
34
35
36
# File 'lib/lichess/users_gateway.rb', line 33

def all_top_ten
  path = "/player"
  JSON.parse(@client.get(path).body)
end

#get(username) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/lichess/users_gateway.rb', line 11

def get(username)
  path = "/api/user/#{username}"
  result = @client.get(path)

  if result.code == 404
    raise Lichess::Exception::UserNotFound.new("#{username} not found")
  end

  JSON.parse(result.body)
end

#leaderboard(variant, number_of_users = 10) ⇒ Object



38
39
40
41
# File 'lib/lichess/users_gateway.rb', line 38

def leaderboard(variant, number_of_users = 10)
  path = "/player/top/#{number_of_users}/#{variant}"
  JSON.parse(@client.get(path).body)
end