module ChessPubApiClient

Constants

VERSION

Public Class Methods

get_club(url_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_puzzle() click to toggle source
# 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_random() click to toggle source
# 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_leaderboards() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_streamers() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Class Methods

handle_response(response) click to toggle source
# File lib/chess_pub_api_client/chess_pub_api_client.rb, line 179
def handle_response(response)
  case response.code
  when "200"
    return JSON.parse(response.body, symbolize_names: true)
  else
    raise StandardError.new("Error. HTTP Status Code: #{response.code}. JSON body: #{response.body}")
  end
end