Class: Rakuten::Response
- Inherits:
-
Object
- Object
- Rakuten::Response
- Defined in:
- lib/rakuten/response.rb
Constant Summary collapse
- JSON =
ActiveSupport::JSON
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #error ⇒ Object
- #errors ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(body) ⇒ Response
constructor
A new instance of Response.
- #result ⇒ Object
- #success? ⇒ Boolean
Constructor Details
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
6 7 8 |
# File 'lib/rakuten/response.rb', line 6 def raw @raw end |
Instance Method Details
#empty? ⇒ Boolean
20 21 22 |
# File 'lib/rakuten/response.rb', line 20 def empty? status_code == 0 end |
#error ⇒ Object
30 31 32 |
# File 'lib/rakuten/response.rb', line 30 def error errors.first or Rakuten::ApiError.new("Request failed without errors returned") end |
#errors ⇒ Object
24 25 26 27 28 |
# File 'lib/rakuten/response.rb', line 24 def errors @errors ||= _errors.map do |error| Rakuten::ApiError[error['code']].new *error.values_at('message', 'help') end end |
#failed? ⇒ Boolean
16 17 18 |
# File 'lib/rakuten/response.rb', line 16 def failed? status_code == -1 end |
#result ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rakuten/response.rb', line 34 def result if success? fetch(:result, {}).except('success') else raise error end end |
#success? ⇒ Boolean
12 13 14 |
# File 'lib/rakuten/response.rb', line 12 def success? status_code != -1 end |