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:


19
20
21
# File 'lib/chgk_rating/client.rb', line 19

def player(id, lazy = false)
  ChgkRating::Models::Player.new id, lazy: lazy
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.


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

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

#rating(team_or_id, release_id) ⇒ ChgkRating::Models::Rating

Returns Rating for a given Team in a given release

Parameters:

Returns:

Raises:


59
60
61
# File 'lib/chgk_rating/client.rb', line 59

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

#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:


138
139
140
# File 'lib/chgk_rating/client.rb', line 138

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

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

Returns a single Recap for a given Team

Parameters:

Returns:

Raises:


29
30
31
# File 'lib/chgk_rating/client.rb', line 29

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:


118
119
120
# File 'lib/chgk_rating/client.rb', line 118

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.


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

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.


82
83
84
# File 'lib/chgk_rating/client.rb', line 82

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:


9
10
11
# File 'lib/chgk_rating/client.rb', line 9

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:


49
50
51
# File 'lib/chgk_rating/client.rb', line 49

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

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

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

Parameters:

Returns:

  • (ChgkRating::Collection::TournamentPlayers)

    The collection of results.

Raises:


169
170
171
# File 'lib/chgk_rating/client.rb', line 169

def team_players_at_tournament(tournament_or_id, team_or_id)
  team_at_tournament(tournament_or_id, team_or_id).players
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:


158
159
160
# File 'lib/chgk_rating/client.rb', line 158

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.


96
97
98
# File 'lib/chgk_rating/client.rb', line 96

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:


147
148
149
# File 'lib/chgk_rating/client.rb', line 147

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:


39
40
41
# File 'lib/chgk_rating/client.rb', line 39

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:


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

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