Class: Tappay::Response
- Inherits:
-
Object
- Object
- Tappay::Response
- Defined in:
- lib/tappay/client.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.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(net_http_response) ⇒ Response
constructor
A new instance of Response.
- #parsed_response ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(net_http_response) ⇒ Response
64 65 66 67 68 69 |
# File 'lib/tappay/client.rb', line 64 def initialize(net_http_response) @response = net_http_response @code = net_http_response.code.to_i @body = net_http_response.body @headers = net_http_response.to_hash end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
62 63 64 |
# File 'lib/tappay/client.rb', line 62 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
62 63 64 |
# File 'lib/tappay/client.rb', line 62 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
62 63 64 |
# File 'lib/tappay/client.rb', line 62 def headers @headers end |
Instance Method Details
#[](key) ⇒ Object
81 82 83 |
# File 'lib/tappay/client.rb', line 81 def [](key) parsed_response[key] end |
#parsed_response ⇒ Object
71 72 73 74 75 |
# File 'lib/tappay/client.rb', line 71 def parsed_response @parsed_response ||= JSON.parse(@body) rescue JSON::ParserError @body end |
#success? ⇒ Boolean
77 78 79 |
# File 'lib/tappay/client.rb', line 77 def success? @code >= 200 && @code < 300 end |