Class: Phocoder::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_key, base_url, decode, #decode, #encode, encode

Constructor Details

#initialize(options = {}) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
# File 'lib/phocoder/response.rb', line 6

def initialize(options={})
  options.each do |k, v|
    send("#{k}=", v) if respond_to?("#{k}=")
  end
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/phocoder/response.rb', line 4

def body
  @body
end

#codeObject

Returns the value of attribute code.



4
5
6
# File 'lib/phocoder/response.rb', line 4

def code
  @code
end

#raw_bodyObject

Returns the value of attribute raw_body.



4
5
6
# File 'lib/phocoder/response.rb', line 4

def raw_body
  @raw_body
end

#raw_responseObject

Returns the value of attribute raw_response.



4
5
6
# File 'lib/phocoder/response.rb', line 4

def raw_response
  @raw_response
end

Instance Method Details

#body_without_wrapperObject



24
25
26
27
28
29
30
# File 'lib/phocoder/response.rb', line 24

def body_without_wrapper
  if body.is_a?(Hash) && body['api_response']
    body['api_response']
  else
    body
  end
end

#errorsObject



16
17
18
19
20
21
22
# File 'lib/phocoder/response.rb', line 16

def errors
  if body.is_a?(Hash)
    Array(body['errors']).compact
  else
    []
  end
end

#success?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/phocoder/response.rb', line 12

def success?
  code.to_i > 199 && code.to_i < 300
end