Class: Runa::Response
- Inherits:
-
Object
- Object
- Runa::Response
- Includes:
- Initializable
- Defined in:
- lib/runa/models/response.rb
Direct Known Subclasses
Constant Summary collapse
- STATUS =
{ completed: 'COMPLETED', success: 'SUCCESS', processing: 'PROCESSING', failed: 'FAILED', 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/runa/models/response.rb', line 18 def error_code @error_code end |
#error_details ⇒ Object
global shared body
18 19 20 |
# File 'lib/runa/models/response.rb', line 18 def error_details @error_details end |
#error_string ⇒ Object
global shared body
18 19 20 |
# File 'lib/runa/models/response.rb', line 18 def error_string @error_string end |
#payload ⇒ Object
global shared body
18 19 20 |
# File 'lib/runa/models/response.rb', line 18 def payload @payload end |
#status ⇒ Object
global shared body
18 19 20 |
# File 'lib/runa/models/response.rb', line 18 def status @status end |
Instance Method Details
#is_successful? ⇒ Boolean
20 21 22 |
# File 'lib/runa/models/response.rb', line 20 def is_successful? @status&.eql?(STATUS[:completed]) || @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 |
# File 'lib/runa/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) @status = STATUS[:completed] @error_code = @payload['type'] @error_string = @payload['message'] @error_details = @payload['help'] else @payload = JSON.parse(response.body) unless !response['content-type'].eql?('application/json') @status = STATUS[:failed] @error_code = response.status @error_string = response.reason_phrase @error_details = response.reason_phrase end end |