Class: Klarna::Response
- Inherits:
-
Object
- Object
- Klarna::Response
- Defined in:
- lib/klarna/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#http_response ⇒ Object
readonly
Returns the value of attribute http_response.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #error? ⇒ Boolean
- #error_code ⇒ Object
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
- #method_missing(m, *args, &block) ⇒ Object
- #respond_to?(m, *args, &block) ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 |
# File 'lib/klarna/response.rb', line 5 def initialize(http_response) @http_response = http_response @code = http_response.code.to_i @body = parse_body @headers = http_response.to_hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
24 25 26 27 |
# File 'lib/klarna/response.rb', line 24 def method_missing(m, *args, &block) return @body[m.to_s] if has_body_field(m) super end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/klarna/response.rb', line 3 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/klarna/response.rb', line 3 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/klarna/response.rb', line 3 def headers @headers end |
#http_response ⇒ Object (readonly)
Returns the value of attribute http_response.
3 4 5 |
# File 'lib/klarna/response.rb', line 3 def http_response @http_response end |
Instance Method Details
#[](index) ⇒ Object
20 21 22 |
# File 'lib/klarna/response.rb', line 20 def [](index) http_response.send("[]", index) end |
#error? ⇒ Boolean
16 17 18 |
# File 'lib/klarna/response.rb', line 16 def error? @code >= 300 end |
#error_code ⇒ Object
34 35 36 37 |
# File 'lib/klarna/response.rb', line 34 def error_code return @body["error_code"] if has_body_field("error_code") @code.to_s end |
#respond_to?(m, *args, &block) ⇒ Boolean
29 30 31 32 |
# File 'lib/klarna/response.rb', line 29 def respond_to?(m, *args, &block) return true if has_body_field(m) super end |
#success? ⇒ Boolean
12 13 14 |
# File 'lib/klarna/response.rb', line 12 def success? @code < 300 end |