Class: Clashinator::League
Overview
This class represents the league model
Constant Summary
Constants inherited from Base
Base::CLASS_MAP, Base::OBJECT_MAP
Class Method Summary collapse
- .league_info(http, league_id) ⇒ Object
- .league_season_rankings(http, league_id, season_id, options = {}) ⇒ Object
- .league_seasons(http, league_id, options = {}) ⇒ Object
- .list_leagues(http, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(attrs) ⇒ League
constructor
A new instance of League.
Methods inherited from Base
prepare_options, #verify_array_of_classes, #verify_hash_that_are_objects
Methods included from Camelizable
Methods included from Underscorable
Constructor Details
#initialize(attrs) ⇒ League
Returns a new instance of League.
4 5 6 |
# File 'lib/clashinator/league.rb', line 4 def initialize(attrs) super(attrs) end |
Class Method Details
.league_info(http, league_id) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/clashinator/league.rb', line 21 def self.league_info(http, league_id) response = http.get("/v1/leagues/#{league_id}") parsed = JSON.parse(response.body) return new(parsed) if response.success? raise parsed['message'] unless response.success? end |
.league_season_rankings(http, league_id, season_id, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/clashinator/league.rb', line 42 def self.league_season_rankings(http, league_id, season_id, = {}) # only available for legend_league response = prepare_response_season_rankings( league_id, season_id, http, ) parsed = JSON.parse(response.body) if response.success? return Clashinator::ArrayResource.new( Clashinator::PlayerRanking, parsed['items'], parsed['paging'] ) end raise parsed['reason'] unless response.success? end |
.league_seasons(http, league_id, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/clashinator/league.rb', line 29 def self.league_seasons(http, league_id, = {}) = () response = http.get("/v1/leagues/#{league_id}/seasons", ) parsed = JSON.parse(response.body) if response.success? return Clashinator::ArrayResource.new( Clashinator::Season, parsed['items'], parsed['paging'] ) end raise parsed['reason'] unless response.success? end |
.list_leagues(http, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/clashinator/league.rb', line 8 def self.list_leagues(http, = {}) = () response = http.get('/v1/leagues', ) parsed = JSON.parse(response.body) if response.success? return Clashinator::ArrayResource.new( Clashinator::League, parsed['items'], parsed['paging'] ) end raise parsed['message'] unless response.success? end |