class Steam::Client

Client object used to communicate with the steam webapi

Public Class Methods

new(url) click to toggle source
# File lib/steam-api/client.rb, line 4
def initialize(url)
  @conn = Faraday.new(url: url)
end

Public Instance Methods

get(resource, params: {}, key: Steam.apikey) click to toggle source

overriding the get method of Faraday to make things simpler. @param [String] resource the resource you're targeting @param [Hash] params Hash of parameters to pass to the resource @param [String] key Steam API key

# File lib/steam-api/client.rb, line 12
def get(resource, params: {}, key: Steam.apikey)
  params[:key] = key
  response = @conn.get resource, params
  JSON.parse(response.body)
  # response
rescue JSON::ParserError
  puts response.body
  # If the steam web api returns an error it's virtually never in json, so
  #   lets pretend that we're getting some sort of consistant response
  #   for errors.
  raise Steam::UnavailableError if response.status == '503'

  { error: '500 Internal Server Error' }
end