Class: Strutta::API
Overview
Strutta API engine Handles API requests and errors
Constant Summary
Constants included from Version
Version::VERSION, Version::VERSION_PATH
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#host ⇒ Object
Returns the value of attribute host.
-
#path ⇒ Object
Returns the value of attribute path.
-
#session ⇒ Object
Returns the value of attribute session.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#call(method, url, params = {}) ⇒ Hash
Makes an API call.
-
#games(id = nil) ⇒ Strutta::Games
Instantiates a Strutta::Games object.
-
#initialize(token, host = 'http://strutta-api.herokuapp.com/', path = Version::VERSION_PATH) ⇒ Strutta::API
constructor
Initializes the Strutta API wrapper.
Constructor Details
permalink #initialize(token, host = 'http://strutta-api.herokuapp.com/', path = Version::VERSION_PATH) ⇒ Strutta::API
Initializes the Strutta API wrapper
29 30 31 32 33 34 35 36 37 |
# File 'lib/strutta-api.rb', line 29 def initialize(token, host = 'http://strutta-api.herokuapp.com/', path = Version::VERSION_PATH) fail Error, 'You must provide a Strutta API key' unless token @host = host @path = path @token = token @session = Excon.new @host @debug = debug end |
Instance Attribute Details
permalink #debug ⇒ Object
Returns the value of attribute debug.
21 22 23 |
# File 'lib/strutta-api.rb', line 21 def debug @debug end |
permalink #host ⇒ Object
Returns the value of attribute host.
21 22 23 |
# File 'lib/strutta-api.rb', line 21 def host @host end |
permalink #path ⇒ Object
Returns the value of attribute path.
21 22 23 |
# File 'lib/strutta-api.rb', line 21 def path @path end |
permalink #session ⇒ Object
Returns the value of attribute session.
21 22 23 |
# File 'lib/strutta-api.rb', line 21 def session @session end |
permalink #token ⇒ Object
Returns the value of attribute token.
21 22 23 |
# File 'lib/strutta-api.rb', line 21 def token @token end |
Instance Method Details
permalink #call(method, url, params = {}) ⇒ Hash
Makes an API call
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/strutta-api.rb', line 45 def call(method, url, params = {}) params = JSON.generate(params) r = @session.send(method, path: "#{@path}#{url}", headers: api_headers, body: params) # Delete calls have no JSON return return true if r.status == 204 # Raise exceptions on error response codes cast_error(r.status, r.body) if r.status >= 400 JSON.parse(r.body) end |
permalink #games(id = nil) ⇒ Strutta::Games
Instantiates a Strutta::Games object
62 63 64 |
# File 'lib/strutta-api.rb', line 62 def games(id = nil) Games.new id, self end |