class Bnet::Starcraft2::Ladder

Constants

PARAMS_MAPPING

TODO make character object for :characters

Attributes

characters[RW]
division[RW]
ladder_id[RW]
ladder_name[RW]
league[RW]
losses[RW]
matchmaking_queue[RW]
rank[RW]
raw_attributes[RW]
wins[RW]

Public Class Methods

find_current(profile, args = {}) click to toggle source
# 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 ={} ) click to toggle source
# 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

Private Class Methods

collection_from_api(raw_collection_response) click to toggle source
# File lib/bnet/starcraft2/ladder.rb, line 76
def self.collection_from_api(raw_collection_response)
  ladders = raw_collection_response.collect do |raw_response|
    raw_characters = raw_response["characters"]
    raw_ladders = raw_response["ladder"].collect do |raw_ladder|
      ladder = from_api(raw_ladder)
      ladder.characters = raw_characters
      ladder
    end

    raw_ladders
  end

  ladders.flatten!

end