Class: Bnet::Starcraft2::Ladder

Inherits:
BnetResource show all
Defined in:
lib/bnet/starcraft2/ladder.rb

Constant Summary collapse

PARAMS_MAPPING =

TODO make character object for :characters

{
  "ladderName"        => :ladder_name,
  "ladderId"          => :ladder_id,
  "division"          => :division,
  "rank"              => :rank,
  "league"            => :league,
  "matchMakingQueue" => :matchmaking_queue,
  "wins"              => :wins,
  "losses"            => :losses
}

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from BnetResource

from_api, #initialize

Constructor Details

This class inherits a constructor from Bnet::BnetResource

Instance Attribute Details

#charactersObject

Returns the value of attribute characters.



2
3
4
# File 'lib/bnet/starcraft2/ladder.rb', line 2

def characters
  @characters
end

#divisionObject

Returns the value of attribute division.



2
3
4
# File 'lib/bnet/starcraft2/ladder.rb', line 2

def division
  @division
end

#ladder_idObject

Returns the value of attribute ladder_id.



2
3
4
# File 'lib/bnet/starcraft2/ladder.rb', line 2

def ladder_id
  @ladder_id
end

#ladder_nameObject

Returns the value of attribute ladder_name.



2
3
4
# File 'lib/bnet/starcraft2/ladder.rb', line 2

def ladder_name
  @ladder_name
end

#leagueObject

Returns the value of attribute league.



2
3
4
# File 'lib/bnet/starcraft2/ladder.rb', line 2

def league
  @league
end

#lossesObject

Returns the value of attribute losses.



2
3
4
# File 'lib/bnet/starcraft2/ladder.rb', line 2

def losses
  @losses
end

#matchmaking_queueObject

Returns the value of attribute matchmaking_queue.



2
3
4
# File 'lib/bnet/starcraft2/ladder.rb', line 2

def matchmaking_queue
  @matchmaking_queue
end

#rankObject

Returns the value of attribute rank.



2
3
4
# File 'lib/bnet/starcraft2/ladder.rb', line 2

def rank
  @rank
end

#raw_attributesObject

Returns the value of attribute raw_attributes.



2
3
4
# File 'lib/bnet/starcraft2/ladder.rb', line 2

def raw_attributes
  @raw_attributes
end

#winsObject

Returns the value of attribute wins.



2
3
4
# File 'lib/bnet/starcraft2/ladder.rb', line 2

def wins
  @wins
end

Class Method Details

.find_current(profile, args = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bnet/starcraft2/ladder.rb', line 18

def self.find_current(profile, args = {})
  profile_id = profile.profile_id
  name = profile.name
  realm = profile.realm || '1'
  locale = args[:locale] || 'en_US'
  api_key  = args[:api_key] || Bnet.configuration.api_key

  client = Bnet::Starcraft2.new(region: profile.region)
  call_url = client.url + "profile/#{profile_id}/#{realm}/#{name}/ladders?apikey=#{api_key}&locale=#{locale}"

  begin
    data = open(call_url)
    raw_collection_response = JSON.parse(data.read)

    if Bnet::API.valid_call?(data.status, raw_collection_response)
      ladders = collection_from_api(raw_collection_response["currentSeason"])
    else
      ladders = []
    end

  rescue OpenURI::HTTPError => e
    ladders = []
  end

  return ladders

end

.find_previous(profile, args = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bnet/starcraft2/ladder.rb', line 46

def self.find_previous(profile, args ={} )
  profile_id = profile.profile_id
  name = profile.name
  realm = profile.realm || '1'
  locale = args[:locale] || 'en_US'
  api_key  = args[:api_key] || Bnet.configuration.api_key

  client = Bnet::Starcraft2.new(region: profile.region)
  call_url = client.url + "profile/#{profile_id}/#{realm}/#{name}/ladders?apikey=#{api_key}&locale=#{locale}"

  begin
    data = open(call_url)
    raw_collection_response = JSON.parse(data.read)

    if Bnet::API.valid_call?(data.status, raw_collection_response)
      ladders = collection_from_api(raw_collection_response["previousSeason"])
    else
      ladders = []
    end

  rescue OpenURI::HTTPError => e
    ladders = []
  end

  return ladders

end