Class: PubgRuby::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/pubg_ruby/profile.rb

Class Method Summary collapse

Class Method Details

.from_nickname(nickname) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/pubg_ruby/profile.rb', line 5

def self.from_nickname(nickname)
  stats = HTTP.headers('TRN-Api-Key' => PubgRuby.configuration.api_key)
    .get("https://pubgtracker.com/api/profile/pc/#{nickname}")

  begin
    JSON.parse(stats)
  rescue
    raise ApiError, 'PUBGTracker API responded unexpectedly.  Please try again'
  end
end

.from_steam(steam_id) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/pubg_ruby/profile.rb', line 16

def self.from_steam(steam_id)
  stats = HTTP.headers('TRN-Api-Key' => PubgRuby.configuration.api_key)
    .get("https://pubgtracker.com/api/search?steamId=#{steam_id}")

  begin
    from_nickname JSON.parse(stats)['Nickname']
  rescue
    raise PlayerNotFoundError, 'Player not found'
  end
end