Class: HaveAPI::Spec::ApiResponse
- Inherits:
-
Object
- Object
- HaveAPI::Spec::ApiResponse
- Defined in:
- lib/haveapi/spec/api_response.rb
Overview
This class wraps raw reply from the API and provides a more friendly interface.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #envelope ⇒ Object
- #errors ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(body) ⇒ ApiResponse
constructor
A new instance of ApiResponse.
- #message ⇒ Object
- #ok? ⇒ Boolean
- #response ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(body) ⇒ ApiResponse
Returns a new instance of ApiResponse.
5 6 7 |
# File 'lib/haveapi/spec/api_response.rb', line 5 def initialize(body) @data = JSON.parse(body, symbolize_names: true) end |
Instance Method Details
#[](k) ⇒ Object
37 38 39 |
# File 'lib/haveapi/spec/api_response.rb', line 37 def [](k) @data[:response][k] end |
#envelope ⇒ Object
9 10 11 |
# File 'lib/haveapi/spec/api_response.rb', line 9 def envelope @data end |
#errors ⇒ Object
33 34 35 |
# File 'lib/haveapi/spec/api_response.rb', line 33 def errors @data[:errors] end |
#message ⇒ Object
29 30 31 |
# File 'lib/haveapi/spec/api_response.rb', line 29 def @data[:message] end |
#ok? ⇒ Boolean
17 18 19 |
# File 'lib/haveapi/spec/api_response.rb', line 17 def ok? @data[:status] end |
#response ⇒ Object
25 26 27 |
# File 'lib/haveapi/spec/api_response.rb', line 25 def response @data[:response] end |
#status ⇒ Object
13 14 15 |
# File 'lib/haveapi/spec/api_response.rb', line 13 def status @data[:status] end |