Class: Clashinator::League

Inherits:
Base
  • Object
show all
Defined in:
lib/clashinator/league.rb

Overview

This class represents the league model

Constant Summary

Constants inherited from Base

Base::CLASS_MAP, Base::OBJECT_MAP

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

prepare_options, #verify_array_of_classes, #verify_hash_that_are_objects

Methods included from Camelizable

#to_camel_case

Methods included from Underscorable

#to_underscore

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, options = {})
  # only available for legend_league
  response = prepare_response_season_rankings(
    league_id, season_id, http, options
  )
  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, options = {})
  new_options = prepare_options(options)
  response = http.get("/v1/leagues/#{league_id}/seasons", new_options)
  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, options = {})
  new_options = prepare_options(options)
  response = http.get('/v1/leagues', new_options)
  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