Class: Steam::Client
- Inherits:
-
Object
- Object
- Steam::Client
- Defined in:
- lib/steam-api/client.rb
Overview
Client object used to communicate with the steam webapi
Instance Method Summary collapse
-
#get(resource, params: {}, key: Steam.apikey) ⇒ Object
overriding the get method of Faraday to make things simpler.
-
#initialize(url) ⇒ Client
constructor
A new instance of Client.
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.
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 |