Class: RakutenApi::Base::Response
- Inherits:
-
Object
- Object
- RakutenApi::Base::Response
- Defined in:
- lib/rakuten_api/base/response.rb
Direct Known Subclasses
GenreSearch::Response, ItemRanking::Response, ItemSearch::Response
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #error? ⇒ Boolean
- #error_message ⇒ Object
-
#initialize(faraday_response = nil) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(faraday_response = nil) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 |
# File 'lib/rakuten_api/base/response.rb', line 9 def initialize(faraday_response = nil) raise RakutenApi::Error.new('not specified Faraday::Response') if !faraday_response.nil? && !faraday_response.kind_of?(::Faraday::Response) @status = faraday_response.nil? ? nil : faraday_response.status @body = json_parse(faraday_response.nil? ? '' : faraday_response.body) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/rakuten_api/base/response.rb', line 7 def body @body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/rakuten_api/base/response.rb', line 6 def status @status end |
Instance Method Details
#error? ⇒ Boolean
19 20 21 |
# File 'lib/rakuten_api/base/response.rb', line 19 def error? !success? end |
#error_message ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/rakuten_api/base/response.rb', line 23 def nil if success? = '' += @body['error'] + ': ' if @body.include? 'error' += @body['error_description'] if @body.include? 'error_description' == '' ? 'no error message' : ; end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/rakuten_api/base/response.rb', line 15 def success? @status == 200 end |