Class: Namira::Response
- Inherits:
-
Object
- Object
- Namira::Response
- Defined in:
- lib/namira/response.rb
Overview
HTTP response
Instance Method Summary collapse
-
#from_json ⇒ Hash, Array
Parse the response body as JSON.
-
#initialize(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(backing) ⇒ Response
Create a new Namira::Response
7 8 9 |
# File 'lib/namira/response.rb', line 7 def initialize(backing) @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
31 32 33 34 35 36 37 |
# File 'lib/namira/response.rb', line 31 def method_missing(name, *args) if @backing.respond_to?(name) @backing.send(name, *args) else super end end |
Instance Method Details
#from_json ⇒ Hash, Array
Returns Parse the response body as JSON.
13 14 15 |
# File 'lib/namira/response.rb', line 13 def from_json @json ||= JSON.parse(@backing.body) end |
#ok? ⇒ Bool
Returns If the response status 2xx.
25 26 27 |
# File 'lib/namira/response.rb', line 25 def ok? (200...300).cover?(@backing.status) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
39 40 41 |
# File 'lib/namira/response.rb', line 39 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
19 20 21 |
# File 'lib/namira/response.rb', line 19 def to_s @backing.to_s end |