Class: Zester::Response
- Inherits:
-
Object
show all
- Defined in:
- lib/zester/response.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(response_body, response_type) ⇒ Response
Returns a new instance of Response.
6
7
8
|
# File 'lib/zester/response.rb', line 6
def initialize(response_body, response_type)
self.body = Hashie::Rash.new(response_body).send(response_type)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/zester/response.rb', line 30
def method_missing(method_name, *args)
if self.body.respond_to?(:response) && self.body.response.respond_to?(method_name)
self.body.response.send(method_name)
else
super
end
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4
5
6
|
# File 'lib/zester/response.rb', line 4
def body
@body
end
|
Instance Method Details
#error_message ⇒ Object
14
15
16
|
# File 'lib/zester/response.rb', line 14
def error_message
self.message.text if self.message && self.message.text
end
|
#message ⇒ Object
26
27
28
|
# File 'lib/zester/response.rb', line 26
def message
self.body.message if self.body.respond_to?(:message)
end
|
#near_limit? ⇒ Boolean
22
23
24
|
# File 'lib/zester/response.rb', line 22
def near_limit?
self.message && self.message.limit_warning && self.message.limit_warning == "true"
end
|
#respond_to?(method_name) ⇒ Boolean
38
39
40
41
42
43
44
|
# File 'lib/zester/response.rb', line 38
def respond_to?(method_name)
if self.body.respond_to?(:response) && self.body.response.respond_to?(method_name)
true
else
super
end
end
|
#response_code ⇒ Object
18
19
20
|
# File 'lib/zester/response.rb', line 18
def response_code
self.message.code.to_i if self.message && self.message.code
end
|
#success? ⇒ Boolean
10
11
12
|
# File 'lib/zester/response.rb', line 10
def success?
!self.response_code.nil? && self.response_code == 0
end
|