Class: Namira::Response
- Inherits:
-
Object
- Object
- Namira::Response
- Defined in:
- lib/namira/response.rb
Overview
HTTP response
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#redirect_count ⇒ Object
readonly
Returns the value of attribute redirect_count.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#from_json ⇒ Hash, Array
Parse the response body as JSON.
-
#initialize(method, url, redirect_count, backing) ⇒ Response
constructor
Create a new Response.
-
#method_missing(name, *args) ⇒ Object
Proxies methods to the backing object.
-
#ok? ⇒ Bool
If the response status 2xx.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#to_s ⇒ String
Returns the response as a string.
Constructor Details
#initialize(method, url, redirect_count, backing) ⇒ Response
Create a new Namira::Response
19 20 21 22 23 24 |
# File 'lib/namira/response.rb', line 19 def initialize(method, url, redirect_count, backing) @method = method @url = url @redirect_count = redirect_count @backing = backing end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Proxies methods to the backing object
46 47 48 49 50 51 52 |
# File 'lib/namira/response.rb', line 46 def method_missing(name, *args) if @backing.respond_to?(name) @backing.send(name, *args) else super end end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
7 8 9 |
# File 'lib/namira/response.rb', line 7 def method @method end |
#redirect_count ⇒ Object (readonly)
Returns the value of attribute redirect_count.
11 12 13 |
# File 'lib/namira/response.rb', line 11 def redirect_count @redirect_count end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/namira/response.rb', line 9 def url @url end |
Class Method Details
.serialized(raw_response) ⇒ Object
13 14 15 |
# File 'lib/namira/response.rb', line 13 def self.serialized(raw_response) Namira::Async::Serializer.unserialize_response(raw_response) end |
Instance Method Details
#from_json ⇒ Hash, Array
Returns Parse the response body as JSON.
28 29 30 |
# File 'lib/namira/response.rb', line 28 def from_json @from_json ||= JSON.parse(@backing.body) end |
#ok? ⇒ Bool
Returns If the response status 2xx.
40 41 42 |
# File 'lib/namira/response.rb', line 40 def ok? (200...300).cover?(@backing.status) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
54 55 56 |
# File 'lib/namira/response.rb', line 54 def respond_to_missing?(method_name, include_private = false) @backing.respond_to?(method_name) || super end |
#to_s ⇒ String
Returns the response as a string
34 35 36 |
# File 'lib/namira/response.rb', line 34 def to_s @backing.to_s end |