Class: SteamLadder

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

Instance Method Summary collapse

Constructor Details

#initialize(key, url = 'https://steamladder.com/api/v1') ⇒ SteamLadder

Returns a new instance of SteamLadder.



6
7
8
9
# File 'lib/steam_ladder.rb', line 6

def initialize(key, url = 'https://steamladder.com/api/v1')
  @key = key
  @url = url
end

Instance Method Details

#ladder(type, country = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/steam_ladder.rb', line 34

def ladder(type, country = nil)
  url = "#{@url}/ladder/#{type}/"
  url += "#{country}/" if country

  json = http_get(url)
  JSON.parse(json, object_class: OpenStruct)
end

#profile(steam_id_64) ⇒ Object



11
12
13
14
# File 'lib/steam_ladder.rb', line 11

def profile(steam_id_64)
  json = http_get("#{@url}/profile/#{steam_id_64}/")
  JSON.parse(json, object_class: OpenStruct)
end

#update_profile(steam_id_64) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/steam_ladder.rb', line 16

def update_profile(steam_id_64)
  json = http_post("#{@url}/profile/#{steam_id_64}/")
  response = JSON.parse(json, object_class: OpenStruct)

  if response.error
    OpenStruct.new(
      success: false,
      error: response.error,
      last_update: response.last_update
    )
  else
    OpenStruct.new(
      success: true,
      last_update: response.steam_stats.last_update
    )
  end
end