Class: Lichess::GamesGateway
- Inherits:
-
Object
- Object
- Lichess::GamesGateway
- Defined in:
- lib/lichess/games_gateway.rb
Constant Summary collapse
- MAX_GAMES =
30
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #export(game_id) ⇒ Object
-
#initialize(client) ⇒ GamesGateway
constructor
A new instance of GamesGateway.
- #ongoing_games ⇒ Object
- #users_games(user_id, options = {}, &blk) ⇒ Object
Constructor Details
#initialize(client) ⇒ GamesGateway
Returns a new instance of GamesGateway.
9 10 11 |
# File 'lib/lichess/games_gateway.rb', line 9 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/lichess/games_gateway.rb', line 5 def client @client end |
Instance Method Details
#export(game_id) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lichess/games_gateway.rb', line 13 def export(game_id) path = "/game/export/#{game_id}" http_headers = {} http_headers[:accept] = "application/json" http_headers[:content_type] = "application/json" result = @client.get(path, http_headers: http_headers) JSON.parse(result.body) end |
#ongoing_games ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/lichess/games_gateway.rb', line 44 def ongoing_games path = "/api/account/playing" result = @client.get(path) JSON.parse(result.body) end |
#users_games(user_id, options = {}, &blk) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lichess/games_gateway.rb', line 24 def users_games(user_id, = {}, &blk) num_games = [:num_games] || 10 if num_games > MAX_GAMES raise Exception::TooManyGames.new("Cannot request more than 30 games") end path = "/api/games/user/#{user_id}?max=#{num_games}" path << "&ongoing=#{[:ongoing]}" if [:ongoing] path << "&perfType=#{[:perf]}" if [:perf] path << "&vs=#{[:vs]}" if [:vs] result = @client.get(path, http_headers: ndjson_headers) stringio = StringIO.new(result.body) NDJSON::Parser.new(stringio).each do |json| yield json end end |