class Lichess::Client
Attributes
logger[RW]
token[R]
Public Class Methods
new(token, logger: nil)
click to toggle source
# File lib/lichess/client.rb, line 10 def initialize(token, logger: nil) @token = token @logger = logger || Logger.new(STDOUT) @logger.level = Logger::INFO @http = HTTP.use(logging: {logger: @logger}) end
Public Instance Methods
games()
click to toggle source
# File lib/lichess/client.rb, line 21 def games @games_gateway ||= GamesGateway.new(self) end
get(path, http_headers: {})
click to toggle source
# File lib/lichess/client.rb, line 25 def get(path, http_headers: {}) url = "#{base_url}#{path}" http_headers[:accept] ||= "application/vnd.lichess.v3+json" http_headers[:content_type] ||= "application/json" http_headers[:authorization] ||= "Bearer #{@token}" response = @http .headers(http_headers) .get(url) return response end
post(path, body: nil, http_headers: {})
click to toggle source
# File lib/lichess/client.rb, line 39 def post(path, body: nil, http_headers: {}) url = "#{base_url}#{path}" http_headers[:accept] ||= "application/vnd.lichess.v3+json" http_headers[:content_type] ||= "application/json" response = @http .headers(http_headers) .post(url, body: body) return response end
users()
click to toggle source
# File lib/lichess/client.rb, line 17 def users @users_gateway ||= UsersGateway.new(self) end
Private Instance Methods
base_url()
click to toggle source
# File lib/lichess/client.rb, line 54 def base_url "https://lichess.org" end