Class: Bnet::Starcraft2::Match

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

Constant Summary collapse

PARAMS_MAPPING =
{
  "map" => :map,
  "type" => :match_type,
  "decision" => :decision,
  "speed" => :speed,
  "date" => :date
}

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from BnetResource

#initialize

Constructor Details

This class inherits a constructor from Bnet::BnetResource

Instance Attribute Details

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#decisionObject

Returns the value of attribute decision.



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

def decision
  @decision
end

#mapObject

Returns the value of attribute map.



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

def map
  @map
end

#match_typeObject

Returns the value of attribute match_type.



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

def match_type
  @match_type
end

#raw_attributesObject

Returns the value of attribute raw_attributes.



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

def raw_attributes
  @raw_attributes
end

#speedObject

Returns the value of attribute speed.



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

def speed
  @speed
end

Class Method Details

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bnet/starcraft2/match.rb', line 12

def self.all(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}/matches?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)
      matches = raw_collection_response["matches"].collect do |raw_response|
        match = from_api(raw_response)
        match
      end
    else
      matches = []
    end

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

  return matches

end

.from_api(raw_response) ⇒ Object



43
44
45
46
47
# File 'lib/bnet/starcraft2/match.rb', line 43

def self.from_api(raw_response)
  match = super(raw_response)
  match.raw_attributes = raw_response
  match
end