Class: DotaApiWrapper::Player

Inherits:
Base
  • Object
show all
Defined in:
lib/dota_api_wrapper/player.rb

Constant Summary

Constants inherited from Base

Base::API_KEY, Base::BASE_URI

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#get, retrieve_info

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_infoObject

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_idObject

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_idObject

Converts 64bits steam id to 32bits



21
22
23
24
25
# File 'lib/dota_api_wrapper/player.rb', line 21

def 
  return if player_info['steamid'].nil?

  player_info['steamid'].to_i - 76561197960265728
end

#retrieve_infoObject



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