Class: Easy::Api::Result
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Easy::Api::Result
- Defined in:
- lib/easy/api/result.rb
Overview
Encapsulates the response data of an API call
Expected values to be added are: #status_code success error (see Easy::Api::Error#new)
Instance Attribute Summary collapse
-
#error ⇒ Easy::Api::Error?
An instance of Easy::Api::Error or nil if there is no error.
-
#status_code ⇒ Integer
The HTTP status code to respond with.
-
#success ⇒ true, false
Represents whether the request succeeded or not.
Instance Method Summary collapse
-
#as_json(options = {}) ⇒ Hash
Used by Rails to render the result as json.
-
#to_xml(options = {}) ⇒ Hash
Used by Rails to parse the result as xml.
Instance Attribute Details
#error ⇒ Easy::Api::Error?
An instance of Easy::Api::Error or nil if there is no error
15 16 17 |
# File 'lib/easy/api/result.rb', line 15 def error @error end |
#status_code ⇒ Integer
The HTTP status code to respond with
28 29 30 |
# File 'lib/easy/api/result.rb', line 28 def status_code @status_code || raise("Easy::Api::Result needs a status_code!") end |
#success ⇒ true, false
Represents whether the request succeeded or not
21 22 23 |
# File 'lib/easy/api/result.rb', line 21 def success @success || false end |
Instance Method Details
#as_json(options = {}) ⇒ Hash
Used by Rails to render the result as json
Will always contain ‘success’, the error if there is one, and any dynamic attributes.
36 37 38 |
# File 'lib/easy/api/result.rb', line 36 def as_json(={}) convert_to_hash end |
#to_xml(options = {}) ⇒ Hash
Used by Rails to parse the result as xml
Will always contain ‘success’, the error if there is one, and any dynamic attributes.
44 45 46 |
# File 'lib/easy/api/result.rb', line 44 def to_xml(={}) convert_to_hash.to_xml() end |