Class: DotaApiWrapper::Player
- Defined in:
- lib/dota_api_wrapper/player.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#player_info ⇒ Object
Returns the value of attribute player_info.
-
#steam_id ⇒ Object
Returns the value of attribute steam_id.
Instance Method Summary collapse
-
#account_id ⇒ Object
Converts 64bits steam id to 32bits.
-
#initialize(steam_id) ⇒ Player
constructor
A new instance of Player.
-
#method_missing(name, *args, &block) ⇒ Object
If the parameter name exists in the hash, it will be returned In other case in will raise an exception ‘NoMethodError’.
- #retrieve_info ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(steam_id) ⇒ Player
Returns a new instance of Player.
10 11 12 |
# File 'lib/dota_api_wrapper/player.rb', line 10 def initialize(steam_id) @steamid = steam_id end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
If the parameter name exists in the hash, it will be returned In other case in will raise an exception ‘NoMethodError’
16 17 18 |
# File 'lib/dota_api_wrapper/player.rb', line 16 def method_missing(name, *args, &block) player_info.key?(name.to_s) ? player_info[name.to_s] : super end |
Instance Attribute Details
#player_info ⇒ Object
Returns the value of attribute player_info.
8 9 10 |
# File 'lib/dota_api_wrapper/player.rb', line 8 def player_info @player_info end |
#steam_id ⇒ Object
Returns the value of attribute steam_id.
7 8 9 |
# File 'lib/dota_api_wrapper/player.rb', line 7 def steam_id @steam_id end |
Instance Method Details
#account_id ⇒ Object
Converts 64bits steam id to 32bits
21 22 23 24 25 |
# File 'lib/dota_api_wrapper/player.rb', line 21 def account_id return if player_info['steamid'].nil? player_info['steamid'].to_i - 76561197960265728 end |
#retrieve_info ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/dota_api_wrapper/player.rb', line 31 def retrieve_info query_params = { 'key' => API_KEY, 'steamids' => @steamid } api_result = get('/GetPlayerSummaries/v0002', query: query_params, headers: {}) return if api_result.empty? api_result['response']['players'][0] end |