Class: Bnet::Diablo3::Hero

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

Constant Summary collapse

PARAMS_MAPPING =
{
  "paragonLevel" => :paragon_level,
  "seasonal" => :seasonal,
  "name" => :name,
  "id" => :hero_id,
  "level" => :level,
  "hardcore" => :hardcore,
  "gender" => :gender,
  "dead" => :dead,
  "class" => :hero_class,
  "last-updated" => :last_updated
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BnetResource

#initialize

Constructor Details

This class inherits a constructor from Bnet::BnetResource

Instance Attribute Details

#active_skillsObject

TODO:Implement def career

@career = #DO

end



36
37
38
# File 'lib/bnet/diablo3/hero.rb', line 36

def active_skills
  @active_skills
end

#arcane_resistObject

Returns the value of attribute arcane_resist.



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

def arcane_resist
  @arcane_resist
end

#armorObject

Returns the value of attribute armor.



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

def armor
  @armor
end

#attack_speedObject

Returns the value of attribute attack_speed.



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

def attack_speed
  @attack_speed
end

#battle_tagObject

Returns the value of attribute battle_tag.



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

def battle_tag
  @battle_tag
end

#block_amount_maxObject

Returns the value of attribute block_amount_max.



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

def block_amount_max
  @block_amount_max
end

#block_amount_minObject

Returns the value of attribute block_amount_min.



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

def block_amount_min
  @block_amount_min
end

#block_chanceObject

Returns the value of attribute block_chance.



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

def block_chance
  @block_chance
end

#careerObject

Returns the value of attribute career.



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

def career
  @career
end

#cold_resistObject

Returns the value of attribute cold_resist.



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

def cold_resist
  @cold_resist
end

#crit_chanceObject

Returns the value of attribute crit_chance.



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

def crit_chance
  @crit_chance
end

#crit_damageObject

Returns the value of attribute crit_damage.



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

def crit_damage
  @crit_damage
end

#damageObject

Returns the value of attribute damage.



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

def damage
  @damage
end

#damage_increaseObject

Returns the value of attribute damage_increase.



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

def damage_increase
  @damage_increase
end

#damage_reductionObject

Returns the value of attribute damage_reduction.



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

def damage_reduction
  @damage_reduction
end

#deadObject

Returns the value of attribute dead.



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

def dead
  @dead
end

#dexterityObject

Returns the value of attribute dexterity.



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

def dexterity
  @dexterity
end

#fire_resistObject

Returns the value of attribute fire_resist.



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

def fire_resist
  @fire_resist
end

#followersObject

Returns the value of attribute followers.



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

def followers
  @followers
end

#genderObject

Returns the value of attribute gender.



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

def gender
  @gender
end

#gold_findObject

Returns the value of attribute gold_find.



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

def gold_find
  @gold_find
end

#hardcoreObject

Returns the value of attribute hardcore.



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

def hardcore
  @hardcore
end

#hero_classObject

Returns the value of attribute hero_class.



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

def hero_class
  @hero_class
end

#hero_idObject

Returns the value of attribute hero_id.



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

def hero_id
  @hero_id
end

#intelligenceObject

Returns the value of attribute intelligence.



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

def intelligence
  @intelligence
end

#itemsObject

Returns the value of attribute items.



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

def items
  @items
end

#last_updateObject

Returns the value of attribute last_update.



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

def last_update
  @last_update
end

#levelObject

Returns the value of attribute level.



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

def level
  @level
end

#lifeObject

Returns the value of attribute life.



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

def life
  @life
end

#life_on_HitObject

Returns the value of attribute life_on_Hit.



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

def life_on_Hit
  @life_on_Hit
end

#life_per_killObject

Returns the value of attribute life_per_kill.



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

def life_per_kill
  @life_per_kill
end

#life_stealObject

Returns the value of attribute life_steal.



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

def life_steal
  @life_steal
end

#lightning_resistObject

Returns the value of attribute lightning_resist.



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

def lightning_resist
  @lightning_resist
end

#magic_findObject

Returns the value of attribute magic_find.



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

def magic_find
  @magic_find
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#paragon_levelObject

Returns the value of attribute paragon_level.



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

def paragon_level
  @paragon_level
end

#passive_skillsObject

Returns the value of attribute passive_skills.



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

def passive_skills
  @passive_skills
end

#physical_resistObject

Returns the value of attribute physical_resist.



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

def physical_resist
  @physical_resist
end

#poison_resistObject

Returns the value of attribute poison_resist.



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

def poison_resist
  @poison_resist
end

#primary_resourceObject

Returns the value of attribute primary_resource.



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

def primary_resource
  @primary_resource
end

#raw_attributesObject

Returns the value of attribute raw_attributes.



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

def raw_attributes
  @raw_attributes
end

#regionObject

Returns the value of attribute region.



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

def region
  @region
end

#seasonalObject

Returns the value of attribute seasonal.



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

def seasonal
  @seasonal
end

#secondary_resourceObject

Returns the value of attribute secondary_resource.



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

def secondary_resource
  @secondary_resource
end

#strengthObject

Returns the value of attribute strength.



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

def strength
  @strength
end

#thornsObject

Returns the value of attribute thorns.



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

def thorns
  @thorns
end

#vitalityObject

Returns the value of attribute vitality.



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

def vitality
  @vitality
end

Class Method Details

.find(args) ⇒ Object

Perform a query for the D3 career’s hero

Arguments

Required
  :battle_tag - Player Battletag (ex. PlayerOne#1309)
  :region     - Account region (ex. 'us')
  :hero_id    - You can get this from an existing Career object
                or from the website url when you view a hero
Optional
  :locale     - String locale (default: 'en_US')
  :api_key    - String API key

Example

Bnet::Diablo3::Hero.find(battle_tag: ‘PlayerOne-1309’, region: ‘us’, hero_id: 1304986)

Returns a Hero object with the following attributes

:paragon_level, :seasonal, :name, :hero_id,
:level, :hardcore, :gender, :dead, :hero_class, :last_update,
:active_skills, :passive_skills, :region, :battle_tag, :career


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/bnet/diablo3/hero.rb', line 79

def self.find args
  battle_tag = args[:battle_tag]
  region     = args[:region]
  hero_id    = args[:hero_id]
  locale     = args[:locale] || 'en_US'
  api_key    = args[:api_key] || Bnet.configuration.api_key

  if battle_tag
    battle_tag.gsub!('#', '-')
  end

  base_api = Bnet::Diablo3.new(region: region)
  call_url = base_api.url + "profile/#{battle_tag}/hero/#{hero_id}?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)
      bnet_object = from_api(raw_response)
    else
      bnet_object = nil
    end

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

  return bnet_object
end

.from_api(response) ⇒ Object

Create an instance by passing in the args from the response



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/bnet/diablo3/hero.rb', line 111

def self.from_api(response)
  hero = super(response)

  hero.raw_attributes = response

  if hero
    assign_skills_from_raw_skills(hero, response["skills"]) if response["skills"]
    assign_stats_from_raw_stats(hero, response["stats"]) if response["stats"]
    assign_items_from_raw_items(hero, response["items"]) if response["items"]
    assign_followers_from_raw_followers(hero, response["followers"]) if response["followers"]
  end

  return hero
end

Instance Method Details

#reloadObject

TODO Extract finder_args to a method then move this ‘reload ` method to super class



50
51
52
53
54
55
56
# File 'lib/bnet/diablo3/hero.rb', line 50

def reload
  finder_args = {battle_tag: battle_tag, region: region, hero_id: hero_id}
  fetched_record = self.class.find(finder_args)
  fetched_record.instance_variables.each do |ivar|
    self.instance_variable_set(ivar, fetched_record.instance_variable_get(ivar))
  end
end