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
  @body   = [].tap do |body_data|
    response.body.each do |chunk|
      body_data << chunk
    end
  end.join("")
  @body   = JSON.parse(@body.to_s) rescue nil
  response
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status.



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

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