Class: Touchpass::Rp::Response
- Inherits:
-
Object
- Object
- Touchpass::Rp::Response
- Defined in:
- lib/touchpass/rp/response.rb
Instance Attribute Summary collapse
-
#http_status_code ⇒ Object
Returns the value of attribute http_status_code.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(http_party_response = nil) ⇒ Response
constructor
A new instance of Response.
- #to_h ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(http_party_response = nil) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 12 |
# File 'lib/touchpass/rp/response.rb', line 7 def initialize(http_party_response = nil) if http_party_response @http_status_code = http_party_response.code @response = http_party_response.parsed_response end end |
Instance Attribute Details
#http_status_code ⇒ Object
Returns the value of attribute http_status_code.
5 6 7 |
# File 'lib/touchpass/rp/response.rb', line 5 def http_status_code @http_status_code end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/touchpass/rp/response.rb', line 5 def response @response end |
Instance Method Details
#[](key) ⇒ Object
24 25 26 |
# File 'lib/touchpass/rp/response.rb', line 24 def [](key) @response.kind_of?(Hash) ? @response[key] : nil end |
#to_h ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/touchpass/rp/response.rb', line 14 def to_h if @response.kind_of?(Hash) @response.merge(:http_status_code => @http_status_code) elsif @http_status_code != 200 { :error => @response, :http_status_code => @http_status_code } else { :text => @response, :http_status_code => @http_status_code } end end |
#to_json(options = {}) ⇒ Object
28 29 30 |
# File 'lib/touchpass/rp/response.rb', line 28 def to_json( = {}) to_h.to_json() end |