Class: Casica::Response
- Inherits:
-
Object
show all
- Defined in:
- lib/casica/response.rb
Instance Method Summary
collapse
Constructor Details
#initialize(faraday_response) ⇒ Response
Returns a new instance of Response.
3
4
5
|
# File 'lib/casica/response.rb', line 3
def initialize(faraday_response)
@faraday_response = faraday_response
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
7
8
9
10
|
# File 'lib/casica/response.rb', line 7
def method_missing(method, *args, &block)
return @faraday_response.send(method, *args, &block) if @faraday_response.respond_to?(method)
super
end
|
Instance Method Details
#failure? ⇒ Boolean
21
22
23
|
# File 'lib/casica/response.rb', line 21
def failure?
!success?
end
|
#response ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/casica/response.rb', line 25
def response
if success?
@faraday_response.body || true
else
Casica::Error.new(self)
end
end
|
#success? ⇒ Boolean
12
13
14
15
16
17
18
19
|
# File 'lib/casica/response.rb', line 12
def success?
case @faraday_response.status
when 200..299 then true
when 400..499 then false
when 500..599 then false
else false
end
end
|