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.



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

def initialize(response)
  @status = response.status
  @body   = JSON.parse(response.to_s) rescue nil
  response.flush
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

#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



14
15
16
17
18
# File 'lib/ecoportal/api/common/response.rb', line 14

def print
  puts "Status: #{@status.code}"
  puts "Body:"
  puts JSON.pretty_generate(@body)
end

#success?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/ecoportal/api/common/response.rb', line 11

def success?
  @status.success?
end