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.
-
#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.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fakturoid/response.rb', line 7 def initialize(faraday_response, caller, request_method) @response = faraday_response @caller = caller @request_method = request_method.to_sym env = response.env 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)
52 53 54 55 56 57 58 |
# File 'lib/fakturoid/response.rb', line 52 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.
5 6 7 |
# File 'lib/fakturoid/response.rb', line 5 def body @body end |
#caller ⇒ Object (readonly)
Returns the value of attribute caller.
5 6 7 |
# File 'lib/fakturoid/response.rb', line 5 def caller @caller end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
5 6 7 |
# File 'lib/fakturoid/response.rb', line 5 def request_method @request_method end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/fakturoid/response.rb', line 5 def response @response end |
Instance Method Details
#headers ⇒ Object
29 30 31 |
# File 'lib/fakturoid/response.rb', line 29 def headers response.env.response_headers.transform_keys(&:downcase) end |
#inspect ⇒ Object
33 34 35 |
# File 'lib/fakturoid/response.rb', line 33 def inspect "#<#{self.class.name}:#{object_id} @body=\"#{body}\" @status_code=\"#{status_code}\">" end |
#json? ⇒ Boolean
25 26 27 |
# File 'lib/fakturoid/response.rb', line 25 def json? headers["content-type"] =~ %r{\Aapplication/json} end |
#status_code ⇒ Object
21 22 23 |
# File 'lib/fakturoid/response.rb', line 21 def status_code response.env["status"] end |