Class: Openlive::Response
Instance Attribute Summary collapse
- #response ⇒ Faraday::Response readonly
Attributes inherited from Base
Instance Method Summary collapse
-
#body ⇒ Hash, Nil
Parse the response from the server.
-
#error_message ⇒ String
Convenience method for fetching the error message.
-
#initialize(faraday_response) ⇒ Response
constructor
Initialize the response object.
-
#method_missing(method_name, *opts, &block) ⇒ String
Simple method missing accessor for reading returned attributes.
-
#status ⇒ Integer
Return the response status.
-
#success? ⇒ Truthy
Was the request successful?.
Methods inherited from Base
#connection, connection, handle_response, #oauth, oauth, #refresh
Constructor Details
#initialize(faraday_response) ⇒ Response
Initialize the response object
9 10 11 |
# File 'lib/openlive/response.rb', line 9 def initialize(faraday_response) @response = faraday_response end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *opts, &block) ⇒ String
Simple method missing accessor for reading returned attributes
50 51 52 |
# File 'lib/openlive/response.rb', line 50 def method_missing(method_name, *opts, &block) body[method_name.to_s] if body.is_a?(Hash) end |
Instance Attribute Details
#response ⇒ Faraday::Response (readonly)
4 5 6 |
# File 'lib/openlive/response.rb', line 4 def response @response end |
Instance Method Details
#body ⇒ Hash, Nil
Parse the response from the server
30 31 32 33 34 |
# File 'lib/openlive/response.rb', line 30 def body @body ||= ( JSON.parse(response.body) if response.body.length > 0 ) end |
#error_message ⇒ String
Convenience method for fetching the error message
39 40 41 42 43 44 45 |
# File 'lib/openlive/response.rb', line 39 def if !success? body end rescue JSON::ParserError => ex ex. end |
#status ⇒ Integer
Return the response status
23 24 25 |
# File 'lib/openlive/response.rb', line 23 def status response.status end |
#success? ⇒ Truthy
Was the request successful?
16 17 18 |
# File 'lib/openlive/response.rb', line 16 def success? response.success? end |