Class: Fakturoid::Response
- Inherits:
-
Object
- Object
- Fakturoid::Response
- Defined in:
- lib/fakturoid/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#caller ⇒ Object
readonly
Returns the value of attribute caller.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(faraday_response, caller, request_method) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #json? ⇒ Boolean
- #status_code ⇒ Object
Constructor Details
#initialize(faraday_response, caller, request_method) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fakturoid/response.rb', line 5 def initialize(faraday_response, caller, request_method) @response = faraday_response @caller = caller @env = faraday_response.env @request_method = request_method.to_sym if !(env.body.nil? || env.body.empty? || (json? && env.body =~ /\A\s+\z/)) @body = json? ? MultiJson.load(env.body) : env.body end handle_response end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
62 63 64 65 66 67 68 |
# File 'lib/fakturoid/response.rb', line 62 def method_missing(method, *args, &block) if body_has_key?(method) body[method.to_s] else super end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/fakturoid/response.rb', line 3 def body @body end |
#caller ⇒ Object (readonly)
Returns the value of attribute caller.
3 4 5 |
# File 'lib/fakturoid/response.rb', line 3 def caller @caller end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
3 4 5 |
# File 'lib/fakturoid/response.rb', line 3 def env @env end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
3 4 5 |
# File 'lib/fakturoid/response.rb', line 3 def request_method @request_method end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/fakturoid/response.rb', line 3 def response @response end |
Instance Method Details
#headers ⇒ Object
25 26 27 |
# File 'lib/fakturoid/response.rb', line 25 def headers env.response_headers end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/fakturoid/response.rb', line 29 def inspect "#<#{self.class.name}:#{object_id} @body=\"#{body}\" @status_code=\"#{status_code}\">" end |
#json? ⇒ Boolean
21 22 23 |
# File 'lib/fakturoid/response.rb', line 21 def json? env.request_headers['Content-Type'] == 'application/json' end |
#status_code ⇒ Object
17 18 19 |
# File 'lib/fakturoid/response.rb', line 17 def status_code env['status'] end |