Module: ChessPubApiClient

Defined in:
lib/chess_pub_api_client/version.rb,
lib/chess_pub_api_client/chess_pub_api_client.rb

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.get_club(url_id) ⇒ Object



82
83
84
85
86
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 82

def get_club(url_id)
  uri = URI("https://api.chess.com/pub/club/#{url_id}")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_club_matches(url_id) ⇒ Object



94
95
96
97
98
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 94

def get_club_matches(url_id)
  uri = URI("https://api.chess.com/pub/club/#{url_id}/matches")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_club_members(url_id) ⇒ Object



88
89
90
91
92
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 88

def get_club_members(url_id)
  uri = URI("https://api.chess.com/pub/club/#{url_id}/members")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_country(iso) ⇒ Object



135
136
137
138
139
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 135

def get_country(iso)
  uri = URI("https://api.chess.com/pub/country/#{iso}")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_country_clubs(iso) ⇒ Object



147
148
149
150
151
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 147

def get_country_clubs(iso)
  uri = URI("https://api.chess.com/pub/country/#{iso}/clubs")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_country_players(iso) ⇒ Object



141
142
143
144
145
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 141

def get_country_players(iso)
  uri = URI("https://api.chess.com/pub/country/#{iso}/players")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_daily_puzzleObject



153
154
155
156
157
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 153

def get_daily_puzzle
  uri = URI("https://api.chess.com/pub/puzzle")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_daily_puzzle_randomObject



159
160
161
162
163
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 159

def get_daily_puzzle_random
  uri = URI("https://api.chess.com/pub/puzzle/random")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_leaderboardsObject



171
172
173
174
175
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 171

def get_leaderboards
  uri = URI("https://api.chess.com/pub/leaderboards")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_player(username) ⇒ Object



6
7
8
9
10
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 6

def get_player(username)
  uri = URI("https://api.chess.com/pub/player/#{username}")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_player_clubs(username) ⇒ Object



64
65
66
67
68
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 64

def get_player_clubs(username)
  uri = URI("https://api.chess.com/pub/player/#{username}/clubs")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_player_current_games(username) ⇒ Object



30
31
32
33
34
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 30

def get_player_current_games(username)
  uri = URI("https://api.chess.com/pub/player/#{username}/games")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_player_current_games_to_move(username) ⇒ Object



36
37
38
39
40
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 36

def get_player_current_games_to_move(username)
  uri = URI("https://api.chess.com/pub/player/#{username}/games/to-move")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_player_games_archives(username, year: nil, month: nil) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 42

def get_player_games_archives(username, year: nil, month: nil)
  if year && month
    uri = URI("https://api.chess.com/pub/player/#{username}/games/#{year}/#{month}")
  else
    uri = URI("https://api.chess.com/pub/player/#{username}/games/archives")
  end
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_player_games_archives_pgn(username, year: nil, month: nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 52

def get_player_games_archives_pgn(username, year: nil, month: nil)
  # TODO: Set appropriate headers required here
  uri = URI("https://api.chess.com/pub/player/#{username}/games/#{year}/#{month}/pgn")
  res = Net::HTTP.get_response(uri)
  case res.code
  when "200"
    return res.body
  else
    raise StandardError.new("Error. HTTP Status Code: #{res.code}. JSON body: #{res.body}")
  end
end

.get_player_matches(username) ⇒ Object



70
71
72
73
74
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 70

def get_player_matches(username)
  uri = URI("https://api.chess.com/pub/player/#{username}/matches")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_player_online_status(username) ⇒ Object



24
25
26
27
28
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 24

def get_player_online_status(username)
  uri = URI("https://api.chess.com/pub/player/#{username}/is-online")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_player_stats(username) ⇒ Object



18
19
20
21
22
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 18

def get_player_stats(username)
  uri = URI("https://api.chess.com/pub/player/#{username}/stats")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_player_tournaments(username) ⇒ Object



76
77
78
79
80
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 76

def get_player_tournaments(username)
  uri = URI("https://api.chess.com/pub/player/#{username}/tournaments")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_streamersObject



165
166
167
168
169
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 165

def get_streamers
  uri = URI("https://api.chess.com/pub/streamers")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_team_live_match(id, board: nil) ⇒ Object



124
125
126
127
128
129
130
131
132
133
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 124

def get_team_live_match(id, board: nil)
  if board
    uri = URI("https://api.chess.com/pub/match/live/#{id}/#{board}")
  else
    uri = URI("https://api.chess.com/pub/match/live/#{id}")
  end
  
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_team_match(id, board: nil) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 113

def get_team_match(id, board: nil)
  if board
    uri = URI("https://api.chess.com/pub/match/#{id}/#{board}")
  else
    uri = URI("https://api.chess.com/pub/match/#{id}")
  end

  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_titled_players(title) ⇒ Object



12
13
14
15
16
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 12

def get_titled_players(title)
  uri = URI("https://api.chess.com/pub/titled/#{title}")
  res = Net::HTTP.get_response(uri)
  handle_response(res)
end

.get_tournament(url_id, round: nil, group: nil) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/chess_pub_api_client/chess_pub_api_client.rb', line 100

def get_tournament(url_id, round: nil, group: nil)
  if round && group
    uri = URI("https://api.chess.com/pub/tournament/#{url_id}/#{round}/#{group}")
  elsif round 
    uri = URI("https://api.chess.com/pub/tournament/#{url_id}/#{round}")
  else
    uri = URI("https://api.chess.com/pub/tournament/#{url_id}")
  end

  res = Net::HTTP.get_response(uri)
  handle_response(res)
end