class BeeiqAPI::Response

Attributes

response[RW]

Public Class Methods

new(response) click to toggle source
# File lib/beeiq_api/response.rb, line 5
def initialize(response)
  @response = response
end

Public Instance Methods

body() click to toggle source
# 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
code() click to toggle source
# File lib/beeiq_api/response.rb, line 25
def code
  response.code
end
headers() click to toggle source
# File lib/beeiq_api/response.rb, line 29
def headers
  response.headers
end
raw_body() click to toggle source
# File lib/beeiq_api/response.rb, line 17
def raw_body
  response.body
end
success?() click to toggle source
# File lib/beeiq_api/response.rb, line 21
def success?
  [200, 204].include? response.code
end

Private Instance Methods

format_hash(h) click to toggle source
# File lib/beeiq_api/response.rb, line 35
def format_hash(h)
  if h.kind_of? Hash
    Hash[
      h.map do |k, v|
        [k.respond_to?(:to_sym) ? k.to_sym : k, format_hash(v)]
      end
    ]
  else
    h
  end
end