Class: BeeiqAPI::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/beeiq_api/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



5
6
7
# File 'lib/beeiq_api/response.rb', line 5

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



3
4
5
# File 'lib/beeiq_api/response.rb', line 3

def response
  @response
end

Instance Method Details

#bodyObject



9
10
11
12
13
14
15
# File 'lib/beeiq_api/response.rb', line 9

def body
  if success?
    { success: true }
  else
    format_hash(JSON.parse(response.body, :quirks_mode => true))
  end
end

#codeObject



25
26
27
# File 'lib/beeiq_api/response.rb', line 25

def code
  response.code
end

#headersObject



29
30
31
# File 'lib/beeiq_api/response.rb', line 29

def headers
  response.headers
end

#raw_bodyObject



17
18
19
# File 'lib/beeiq_api/response.rb', line 17

def raw_body
  response.body
end

#success?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/beeiq_api/response.rb', line 21

def success?
  [200, 204].include? response.code
end