Class: Wegift::Response
- Inherits:
-
Object
- Object
- Wegift::Response
- Includes:
- Initializable
- Defined in:
- lib/wegift/models/response.rb
Direct Known Subclasses
Constant Summary collapse
- STATUS =
{ success: 'SUCCESS', error: 'ERROR' }.freeze
Instance Attribute Summary collapse
-
#error_code ⇒ Object
global shared body.
-
#error_details ⇒ Object
global shared body.
-
#error_string ⇒ Object
global shared body.
-
#payload ⇒ Object
global shared body.
-
#status ⇒ Object
global shared body.
Instance Method Summary collapse
Methods included from Initializable
Instance Attribute Details
#error_code ⇒ Object
global shared body
18 19 20 |
# File 'lib/wegift/models/response.rb', line 18 def error_code @error_code end |
#error_details ⇒ Object
global shared body
18 19 20 |
# File 'lib/wegift/models/response.rb', line 18 def error_details @error_details end |
#error_string ⇒ Object
global shared body
18 19 20 |
# File 'lib/wegift/models/response.rb', line 18 def error_string @error_string end |
#payload ⇒ Object
global shared body
18 19 20 |
# File 'lib/wegift/models/response.rb', line 18 def payload @payload end |
#status ⇒ Object
global shared body
18 19 20 |
# File 'lib/wegift/models/response.rb', line 18 def status @status end |
Instance Method Details
#is_successful? ⇒ Boolean
20 21 22 |
# File 'lib/wegift/models/response.rb', line 20 def is_successful? @status&.eql?(STATUS[:success]) end |
#parse(response = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wegift/models/response.rb', line 24 def parse(response = {}) # TODO: JSON responses, when requested? # let's fix that with a simpel catch all if response.success? && response['content-type'].eql?('application/json') @payload = JSON.parse(response.body) # TODO: @payload['status'] is only returned for orders! (products etc are plain objects) @status = @payload['status'] || STATUS[:success] @error_code = @payload['error_code'] @error_string = @payload['error_string'] @error_details = @payload['error_details'] else @payload = {} @status = STATUS[:error] @error_code = response.status @error_string = response.reason_phrase @error_details = response.reason_phrase end end |