Class: CemAcpt::Goss::Api::ActionResponse
- Inherits:
-
Object
- Object
- CemAcpt::Goss::Api::ActionResponse
- Defined in:
- lib/cem_acpt/goss/api/action_response.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
- #error ⇒ Object
- #error? ⇒ Boolean
-
#initialize(host, action, status, body) ⇒ ActionResponse
constructor
A new instance of ActionResponse.
- #inspect ⇒ Object
- #results ⇒ Object
- #results? ⇒ Boolean
- #status ⇒ Object (also: #http_status)
- #success? ⇒ Boolean
- #summary ⇒ Object
- #summary? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(host, action, status, body) ⇒ ActionResponse
Returns a new instance of ActionResponse.
9 10 11 12 13 14 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 9 def initialize(host, action, status, body) @host = host @action = action @status = status @body = body end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
7 8 9 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 7 def action @action end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 7 def body @body end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 7 def host @host end |
Instance Method Details
#error ⇒ Object
42 43 44 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 42 def error results.find(&:error) || StandardError.new('Unknown error') end |
#error? ⇒ Boolean
46 47 48 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 46 def error? !success? end |
#inspect ⇒ Object
20 21 22 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 20 def inspect to_s end |
#results ⇒ Object
50 51 52 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 50 def results @results ||= @body['results'].map { |r| ActionResponseResult.new(r) } end |
#results? ⇒ Boolean
54 55 56 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 54 def results? !results.nil? && !results.empty? end |
#status ⇒ Object Also known as: http_status
33 34 35 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 33 def status @status.to_i end |
#success? ⇒ Boolean
38 39 40 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 38 def success? status == 200 end |
#summary ⇒ Object
58 59 60 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 58 def summary @summary ||= ActionResponseSummary.new(@body['summary']) end |
#summary? ⇒ Boolean
62 63 64 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 62 def summary? !summary.nil? && !summary.empty? end |
#to_h ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 24 def to_h { host: host, action: action, status: @status, body: @body, } end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 16 def to_s "#<#{self.class.name}:0x#{object_id.to_s(16)}>" end |