class SteamLadder

Public Class Methods

new(key, url = 'https://steamladder.com/api/v1') click to toggle source
# File lib/steam_ladder.rb, line 6
def initialize(key, url = 'https://steamladder.com/api/v1')
  @key = key
  @url = url
end

Public Instance Methods

ladder(type, country = nil) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

http_get(url) click to toggle source
# File lib/steam_ladder.rb, line 44
def http_get(url)
  HTTP.headers(authorization: "Token #{@key}")
      .get(url)
end
http_post(url) click to toggle source
# File lib/steam_ladder.rb, line 49
def http_post(url)
  HTTP.headers(authorization: "Token #{@key}")
      .post(url)
end