Class: ChgkRating::Client

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

Instance Method Summary collapse

Instance Method Details

#player(id, lazy = false) ⇒ ChgkRating::Models::Player

Returns a single Player

Parameters:

  • id (String or Integer)

    Player’s id

  • lazy (Boolean) (defaults to: false)

    Should the Player be lazily loaded? Default is ‘false`.

Returns:

Raises:



21
22
23
# File 'lib/chgk_rating/client.rb', line 21

def player(id, lazy = false)
  ChgkRating::Models::Player.new id, lazy: lazy
end

#player_rating(player_or_id, release_id) ⇒ ChgkRating::Models::PlayerRating

Returns rating for a given Player in a given release

Parameters:

Returns:

Raises:



71
72
73
# File 'lib/chgk_rating/client.rb', line 71

def player_rating(player_or_id, release_id)
  player(player_or_id, true).rating(release_id)
end

#player_ratings(player_or_id) ⇒ ChgkRating::Collection::Ratings

Returns an array-like Ratings collection for a given Player.

Parameters:

Returns:

  • (ChgkRating::Collection::Ratings)

    The collection of ratings.

Raises:



171
172
173
# File 'lib/chgk_rating/client.rb', line 171

def player_ratings(player_or_id)
  player(player_or_id, true).ratings
end

#player_tournaments(player_or_id, season_id = nil) ⇒ ChgkRating::Collection::PlayerTournaments

Returns a collection of Tournaments that the Player has participated in

Parameters:

Returns:

  • (ChgkRating::Collection::PlayerTournaments)

    The collection of tournaments.



152
153
154
155
# File 'lib/chgk_rating/client.rb', line 152

def player_tournaments(player_or_id, season_id = nil)
  ChgkRating::Collections::PlayerTournaments.new player: player_or_id,
                                                 season_id: season_id
end

#players(params = {}) ⇒ ChgkRating::Collection::Players

Returns an array-like Players collection that contains Player models

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :page (String or Integer)

    The requested page. Default is 1, and there are 1000 results per page.

  • :lazy (Boolean)

    Should the Player models be marked as lazily loaded? Note that the models will still contain all the information returned by the API.

  • :collection (Enumerable)

    An array or collection of Players that will be used to build a new collection. If this option is provided, API request will not be sent.

Returns:

  • (ChgkRating::Collection::Players)

    The collection of Players.



120
121
122
# File 'lib/chgk_rating/client.rb', line 120

def players(params = {})
  ChgkRating::Collections::Players.new params
end

#recap(team_or_id, season_id) ⇒ ChgkRating::Models::Recap

Returns a single Recap for a given Team

Parameters:

Returns:

Raises:



31
32
33
# File 'lib/chgk_rating/client.rb', line 31

def recap(team_or_id, season_id)
  team(team_or_id, true).recap(season_id)
end

#recaps(team_or_id) ⇒ ChgkRating::Collection::Recaps

Returns an hash-like Recaps collection for a given team, grouped by seasons. Seasons act as keys, whereas Recap models - as values.

Parameters:

Returns:

  • (ChgkRating::Collection::Recaps)

    The collection of recaps.

Raises:



130
131
132
# File 'lib/chgk_rating/client.rb', line 130

def recaps(team_or_id)
  team(team_or_id, true).recaps
end

#search_players(params) ⇒ ChgkRating::Collection::Players::Search

Returns a Players collection based on the search criteria.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :name (String)

    Player’s name

  • :surname (String)

    Player’s surname

  • :patronymic (String)

    Player’s patronymic

  • :page (String or Integer)

    The requested page. Default is 1, and there are 1000 results per page.

Returns:

  • (ChgkRating::Collection::Players::Search)

    Found Players.



84
85
86
# File 'lib/chgk_rating/client.rb', line 84

def search_players(params)
  ChgkRating::Collections::Players.search request: params
end

#search_teams(params) ⇒ ChgkRating::Collection::Teams::Search

Returns a Teams collection based on the search criteria.

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (params):

  • :name (String)

    Team’s name

  • :town (String)

    Team’s town of origin

  • :page (String or Integer)

    The requested page. Default is 1, and there are 1000 results per page.

Returns:

  • (ChgkRating::Collection::Teams::Search)

    Found Teams.



94
95
96
# File 'lib/chgk_rating/client.rb', line 94

def search_teams(params)
  ChgkRating::Collections::Teams.search request: params
end

#team(id, lazy = false) ⇒ ChgkRating::Models::Team

Returns a single Team

Parameters:

  • id (String or Integer)

    Team’s id

  • lazy (Boolean) (defaults to: false)

    Should the Team be lazily loaded? Default is ‘false`.

Returns:

Raises:



11
12
13
# File 'lib/chgk_rating/client.rb', line 11

def team(id, lazy = false)
  ChgkRating::Models::Team.new id, lazy: lazy
end

#team_at_tournament(tournament_or_id, team_or_id) ⇒ ChgkRating::Models::TournamentTeam

Returns a single TournamentTeam

Parameters:

  • tournament_or_id (String, Integer or Tournament)

    Tournament to load team for.

  • team_or_id (String, Integer or Team)

    Team to search for.

Returns:

Raises:



51
52
53
# File 'lib/chgk_rating/client.rb', line 51

def team_at_tournament(tournament_or_id, team_or_id)
  tournament(tournament_or_id, true).team_by(team_or_id)
end

#team_players_at_tournament(tournament_or_id, team_or_id) ⇒ ChgkRating::Collection::TournamentTeamPlayers

Returns an array-like TournamentTeamPlayers collection containing roster for a given team at a given tournament.

Parameters:

Returns:

  • (ChgkRating::Collection::TournamentTeamPlayers)

    The collection of results.

Raises:



202
203
204
# File 'lib/chgk_rating/client.rb', line 202

def team_players_at_tournament(tournament_or_id, team_or_id)
  team_at_tournament(tournament_or_id, team_or_id).players
end

#team_rating(team_or_id, release_id) ⇒ ChgkRating::Models::TeamRating

Returns rating for a given Team in a given release

Parameters:

Returns:

Raises:



61
62
63
# File 'lib/chgk_rating/client.rb', line 61

def team_rating(team_or_id, release_id)
  team(team_or_id, true).rating(release_id)
end

#team_ratings(team_or_id) ⇒ ChgkRating::Collection::Ratings

Returns an array-like Ratings collection for a given Team.

Parameters:

Returns:

  • (ChgkRating::Collection::Ratings)

    The collection of ratings.

Raises:



162
163
164
# File 'lib/chgk_rating/client.rb', line 162

def team_ratings(team_or_id)
  team(team_or_id, true).ratings
end

#team_results_at_tournament(tournament_or_id, team_or_id) ⇒ ChgkRating::Collection::TournamentTeamResults

Returns an array-like TournamentTeamResults collection with results for a given team in a given tournament

Parameters:

Returns:

  • (ChgkRating::Collection::TournamentTeamResults)

    The collection of results.

Raises:



191
192
193
# File 'lib/chgk_rating/client.rb', line 191

def team_results_at_tournament(tournament_or_id, team_or_id)
  team_at_tournament(tournament_or_id, team_or_id).results
end

#teams(params = {}) ⇒ ChgkRating::Collection::Teams

Returns an array-like Teams collection that contains Team models

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :page (String or Integer)

    The requested page. Default is 1, and there are 1000 results per page.

  • :lazy (Boolean)

    Should the Teams models be marked as lazily loaded? Note that the models will still contain all the information returned by the API.

  • :collection (Enumerable)

    An array or collection of Teams that will be used to build a new collection. If this option is provided, API request will not be sent.

Returns:

  • (ChgkRating::Collection::Teams)

    The collection of Teams.



108
109
110
# File 'lib/chgk_rating/client.rb', line 108

def teams(params = {})
  ChgkRating::Collections::Teams.new params
end

#teams_at_tournament(tournament_or_id) ⇒ ChgkRating::Collection::Ratings

Returns an array-like TournamentTeams collection specifying which teams participated in a given tournament

Parameters:

Returns:

  • (ChgkRating::Collection::Ratings)

    The collection of teams.

Raises:



180
181
182
# File 'lib/chgk_rating/client.rb', line 180

def teams_at_tournament(tournament_or_id)
  tournament(tournament_or_id, true).team_list
end

#tournament(id, lazy = false) ⇒ ChgkRating::Models::Tournament

Returns a single Tournament

Parameters:

  • id (String or Integer)

    Tournament’s id

  • lazy (Boolean) (defaults to: false)

    Should the Tournament be lazily loaded? Default is ‘false`.

Returns:

Raises:



41
42
43
# File 'lib/chgk_rating/client.rb', line 41

def tournament(id, lazy = false)
  ChgkRating::Models::Tournament.new id, lazy: lazy
end

#tournaments(team_or_id: nil, season_id: nil, params: {}) ⇒ ChgkRating::Collection::Tournaments

Returns a collection of Tournaments based on the given criteria

Parameters:

  • team_or_id (String, Integer or ChgkRating::Models::Team) (defaults to: nil)

    Team to load tournaments for.

  • season_id (String or Integer) (defaults to: nil)

    Season to load tournaments for

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params:):

  • :page (String or Integer)

    The requested page. Default is 1

Returns:

  • (ChgkRating::Collection::Tournaments)

    The collection of tournaments.

Raises:



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

def tournaments(team_or_id: nil, season_id: nil, params: {})
  ChgkRating::Collections::Tournaments.new params.merge(
    team: team_or_id, season_id: season_id
  )
end