class Lichess::UsersGateway

Attributes

client[R]

Public Class Methods

new(client) click to toggle source
# File lib/lichess/users_gateway.rb, line 7
def initialize(client)
  @client = client
end

Public Instance Methods

activity(username) click to toggle source
# 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() click to toggle source
# File lib/lichess/users_gateway.rb, line 38
def all_top_ten
  path = "/player"
  JSON.parse(@client.get(path).body)
end
get(usernames) click to toggle source
# 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) click to toggle source
# 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