Class: Bnet::Diablo3::Career

Inherits:
BnetResource show all
Defined in:
lib/bnet/diablo3/career.rb

Constant Summary collapse

PARAMS_MAPPING =
{
  "lastHeroPlayed" => :last_hero_played,
  "lastUpdated" => :last_updated,
  "kills" => :kills,
  "timePlayed" => :time_played,
  "fallenHeroes" => :fallen_heroes,
  "paragonLevel" => :paragon_level,
  "paragonLevelHardcore" => :paragon_level_hardcore,
  "battleTag" => :battle_tag,
  "progression" => :progression
}

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

#battle_tagObject

Returns the value of attribute battle_tag.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def battle_tag
  @battle_tag
end

#fallen_heroesObject

Returns the value of attribute fallen_heroes.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def fallen_heroes
  @fallen_heroes
end

#heroesObject

Returns the value of attribute heroes.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def heroes
  @heroes
end

#killsObject

Returns the value of attribute kills.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def kills
  @kills
end

#last_hero_playedObject

Returns the value of attribute last_hero_played.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def last_hero_played
  @last_hero_played
end

#last_updatedObject

Returns the value of attribute last_updated.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def last_updated
  @last_updated
end

#paragon_levelObject

Returns the value of attribute paragon_level.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def paragon_level
  @paragon_level
end

#paragon_level_hardcoreObject

Returns the value of attribute paragon_level_hardcore.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def paragon_level_hardcore
  @paragon_level_hardcore
end

#progressionObject

Returns the value of attribute progression.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def progression
  @progression
end

#raw_attributesObject

Returns the value of attribute raw_attributes.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def raw_attributes
  @raw_attributes
end

#regionObject

Returns the value of attribute region.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def region
  @region
end

#time_playedObject

Returns the value of attribute time_played.



3
4
5
# File 'lib/bnet/diablo3/career.rb', line 3

def time_played
  @time_played
end

Class Method Details

.find(args) ⇒ Object

Perform a query for the Diablo 3 character profile.

Arguments

Required
  :battle_tag - Player Battletag (ex. PlayerOne#1309)
  :region     - Account region (ex. 'us')
Optional
  :locale     - String locale (default: 'en_US')
  :api_key    - String API key

Example

Bnet::Diablo3::Career.find(battle_tag: ‘PlayerOne#1309’, region: ‘us’)

Returns a Career object with the following attributes

:heroes, :last_hero_played, :last_updated, :kills, :time_played,
:fallen_heroes, :paragon_level, :paragon_level_hardcore, :battle_tag,
:progression, :region

Note : Autoloads the associated hero records from the Hero API as well



44
45
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/diablo3/career.rb', line 44

def self.find args
  battle_tag = args[:battle_tag].gsub('#', '-')
  region     = args[:region]
  api_key    = args[:api_key] || Bnet.configuration.api_key
  locale     = args[:locale] || 'en_US'

  base_api = Bnet::Diablo3.new(region: region)
  call_url = base_api.url + "profile/#{battle_tag}/?apikey=#{api_key}&locale=#{locale}"

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

    if Bnet::API.valid_call?(data.status, raw_response)
      career = from_api(raw_response)
      career.raw_attributes = raw_response
      career.region = region

      assign_heroes_from_raw_heroes(career, raw_response["heroes"]) if raw_response["heroes"]
    else
      career = nil
    end

  rescue OpenURI::HTTPError => e
    career = nil
  end

  return career
end

.from_api(response) ⇒ Object



74
75
76
77
78
# File 'lib/bnet/diablo3/career.rb', line 74

def self.from_api(response)
  career = super(response)
  career.raw_attributes = response
  return career
end