Class: Ecoportal::API::Common::Response
- Inherits:
-
Object
- Object
- Ecoportal::API::Common::Response
- Defined in:
- lib/ecoportal/api/common/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#src_body ⇒ Object
readonly
Returns the value of attribute src_body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #print_pretty ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ecoportal/api/common/response.rb', line 8 def initialize(response) @status = response.status @src_body = [].tap do |body_data| response.body.each do |chunk| body_data << chunk end end.join.to_s @body = JSON.parse(@src_body) rescue nil # rubocop:disable Style/RescueModifier end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/ecoportal/api/common/response.rb', line 5 def body @body end |
#src_body ⇒ Object (readonly)
Returns the value of attribute src_body.
6 7 8 |
# File 'lib/ecoportal/api/common/response.rb', line 6 def src_body @src_body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/ecoportal/api/common/response.rb', line 5 def status @status end |
Instance Method Details
#print_pretty ⇒ Object
23 24 25 26 27 |
# File 'lib/ecoportal/api/common/response.rb', line 23 def print_pretty puts "Status: #{@status.code}" puts "Body:" puts JSON.pretty_generate(@body) end |
#success? ⇒ Boolean
19 20 21 |
# File 'lib/ecoportal/api/common/response.rb', line 19 def success? @status.success? end |