Class: Ecoportal::API::Common::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/ecoportal/api/common/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/ecoportal/api/common/response.rb', line 5

def body
  @body
end

#src_bodyObject (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

#statusObject (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



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

Returns:

  • (Boolean)


19
20
21
# File 'lib/ecoportal/api/common/response.rb', line 19

def success?
  @status.success?
end