class Bnet::Diablo3::Hero
Constants
- PARAMS_MAPPING
Attributes
active_skills[RW]
arcane_resist[RW]
armor[RW]
attack_speed[RW]
battle_tag[RW]
block_amount_max[RW]
block_amount_min[RW]
block_chance[RW]
career[RW]
cold_resist[RW]
crit_chance[RW]
crit_damage[RW]
damage[RW]
damage_increase[RW]
damage_reduction[RW]
dead[RW]
dexterity[RW]
fire_resist[RW]
followers[RW]
gender[RW]
gold_find[RW]
hardcore[RW]
hero_class[RW]
hero_id[RW]
intelligence[RW]
items[RW]
last_update[RW]
level[RW]
life[RW]
life_on_Hit[RW]
life_per_kill[RW]
life_steal[RW]
lightning_resist[RW]
magic_find[RW]
name[RW]
paragon_level[RW]
passive_skills[RW]
physical_resist[RW]
poison_resist[RW]
primary_resource[RW]
raw_attributes[RW]
region[RW]
seasonal[RW]
secondary_resource[RW]
strength[RW]
thorns[RW]
vitality[RW]
Public Class Methods
find(args)
click to toggle source
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
# 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)
click to toggle source
Create an instance by passing in the args from the response
Calls superclass method
Bnet::BnetResource::from_api
# 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
Private Class Methods
assign_followers_from_raw_followers(hero, raw_followers)
click to toggle source
# File lib/bnet/diablo3/hero.rb, line 128 def self.assign_followers_from_raw_followers(hero, raw_followers) hero.followers = raw_followers.collect do |follower_type, follower_props| Bnet::Diablo3::Follower.from_api(follower_type, follower_props) end return hero end
assign_items_from_raw_items(hero, raw_items)
click to toggle source
# File lib/bnet/diablo3/hero.rb, line 136 def self.assign_items_from_raw_items(hero, raw_items) hero.items = raw_items.collect do |location, item_props| Bnet::Diablo3::Item.from_api(location, item_props) end return hero end
assign_skills_from_raw_skills(hero, raw_skills)
click to toggle source
# File lib/bnet/diablo3/hero.rb, line 144 def self.assign_skills_from_raw_skills(hero, raw_skills) hero.active_skills = raw_skills["active"].collect do |active_skill| Bnet::Diablo3::Skill.from_api(active_skill) unless active_skill.empty? end hero.passive_skills = raw_skills["passive"].collect do |passive_skill| Bnet::Diablo3::Skill.from_api(passive_skill) unless passive_skill.empty? end return hero end
assign_stats_from_raw_stats(hero, raw_stats)
click to toggle source
# File lib/bnet/diablo3/hero.rb, line 156 def self.assign_stats_from_raw_stats(hero, raw_stats) hero.life = raw_stats["life"] hero.damage = raw_stats["damage"] hero.attack_speed = raw_stats["attackSpeed"] hero.armor = raw_stats["armor"] hero.strength = raw_stats["strength"] hero.dexterity = raw_stats["dexterity"] hero.vitality = raw_stats["vitality"] hero.intelligence = raw_stats["intelligence"] hero.physical_resist = raw_stats["physicalResist"] hero.fire_resist = raw_stats["fireResist"] hero.cold_resist = raw_stats["coldResist"] hero.lightning_resist = raw_stats["lightningResist"] hero.poison_resist = raw_stats["poisonResist"] hero.arcane_resist = raw_stats["arcaneResist"] hero.crit_damage = raw_stats["critDamage"] hero.block_chance = raw_stats["blockChance"] hero.block_amount_min = raw_stats["blockAmountMin"] hero.block_amount_max = raw_stats["blockAmountMax"] hero.damage_increase = raw_stats["damageIncrease"] hero.crit_chance = raw_stats["critChance"] hero.damage_reduction = raw_stats["damageReduction"] hero.thorns = raw_stats["thorns"] hero.life_steal = raw_stats["lifeSteal"] hero.life_per_kill = raw_stats["lifePerKill"] hero.gold_find = raw_stats["goldFind"] hero.magic_find = raw_stats["magicFind"] hero.life_on_Hit = raw_stats["lifeOnHit"] hero.primary_resource = raw_stats["primaryResource"] hero.secondary_resource = raw_stats["secondaryResource"] return hero end
Public Instance Methods
reload()
click to toggle source
TODO Extract finder_args to a method then move this ‘reload ` method to super class
# 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