Class: Steam::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/steam-api/client.rb

Overview

Client object used to communicate with the steam webapi

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Client

Returns a new instance of Client.



4
5
6
# File 'lib/steam-api/client.rb', line 4

def initialize(url)
  @conn = Faraday.new(url: url)
end

Instance Method Details

#get(resource, params: {}, key: Steam.apikey) ⇒ Object

overriding the get method of Faraday to make things simpler.

Parameters:

  • resource (String)

    the resource you’re targeting

  • params (Hash) (defaults to: {})

    Hash of parameters to pass to the resource

  • key (String) (defaults to: Steam.apikey)

    Steam API key



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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