Class: Withings::Api::ApiResponse
- Inherits:
-
Object
- Object
- Withings::Api::ApiResponse
- Includes:
- ResultsHelpers
- Defined in:
- lib/withings-api/api_response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(string_or_json, body_class) ⇒ ApiResponse
constructor
A new instance of ApiResponse.
Methods included from ResultsHelpers
Constructor Details
#initialize(string_or_json, body_class) ⇒ ApiResponse
Returns a new instance of ApiResponse.
13 14 15 16 17 18 19 20 21 |
# File 'lib/withings-api/api_response.rb', line 13 def initialize(string_or_json, body_class) hash = coerce_hash string_or_json @status = hash["status"] || raise(InvalidFormat, :status_field_missing) if hash.key?("body") @body = body_class.new(hash["body"]) end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/withings-api/api_response.rb', line 5 def body @body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/withings-api/api_response.rb', line 5 def status @status end |
Class Method Details
.create!(http_response, body_class) ⇒ Object
7 8 9 10 11 |
# File 'lib/withings-api/api_response.rb', line 7 def self.create!(http_response, body_class) raise HttpNotSuccessError.new(http_response.code, http_response.body) if http_response.code != '200' self.new(http_response.body, body_class) end |