Class: Lichess::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/lichess/client.rb', line 8

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/lichess/client.rb', line 6

def token
  @token
end

Instance Method Details

#gamesObject



16
17
18
# File 'lib/lichess/client.rb', line 16

def games
  @games_gateway ||= GamesGateway.new(self)
end

#get(path, http_headers: {}) ⇒ Object



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

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: {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/lichess/client.rb', line 34

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)

  return response
end

#usersObject



12
13
14
# File 'lib/lichess/client.rb', line 12

def users
  @users_gateway ||= UsersGateway.new(self)
end