Sha256: 4fdc88d1b6432785bb37b59b64f646f56c68aa92b082308c8dfe4a105a8b150f
Contents?: true
Size: 1.2 KB
Versions: 2
Compression:
Stored size: 1.2 KB
Contents
require "net/http" require "http" require "logger" module Lichess class Client attr_reader :token attr_accessor :logger def initialize(token, logger: nil) @token = token @logger = logger || Logger.new(STDOUT) @logger.level = Logger::INFO @http = HTTP.use(logging: {logger: @logger}) end def users @users_gateway ||= UsersGateway.new(self) end def games @games_gateway ||= GamesGateway.new(self) end 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 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 private def base_url "https://lichess.org" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ruby-lichess-0.4.0 | lib/lichess/client.rb |
ruby-lichess-0.3.0 | lib/lichess/client.rb |