Class: DotaApiWrapper::Hero

Inherits:
Econ show all
Defined in:
lib/dota_api_wrapper/hero.rb

Constant Summary

Constants inherited from Base

Base::API_KEY, Base::BASE_URI

Instance Attribute Summary collapse

Attributes inherited from Econ

#language

Instance Method Summary collapse

Methods inherited from Base

#get, retrieve_info

Constructor Details

#initialize(lang = 'en_us') ⇒ Hero

Returns a new instance of Hero.



7
8
9
10
# File 'lib/dota_api_wrapper/hero.rb', line 7

def initialize(lang = 'en_us')
  super(lang)
  @heroes = retrieve_heroes
end

Instance Attribute Details

#heroesObject

Returns the value of attribute heroes.



5
6
7
# File 'lib/dota_api_wrapper/hero.rb', line 5

def heroes
  @heroes
end

Instance Method Details

#find_by_id(id) ⇒ Object



24
25
26
# File 'lib/dota_api_wrapper/hero.rb', line 24

def find_by_id(id)
  heroes[id]
end

#retrieve_heroesObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dota_api_wrapper/hero.rb', line 12

def retrieve_heroes
  query_params = { 'key' => API_KEY, 'language' => language }
  api_result = get('/GetHeroes/v0001', query: query_params, headers: {})

  return if api_result.empty?

  res = {}
  api_result['result']['heroes'].each { |a| res[a['id']] = a }

  res
end