Class: DPay::HTTP::Response
- Inherits:
-
Object
- Object
- DPay::HTTP::Response
- Defined in:
- lib/dpay/http/response.rb,
sig/dpay/http/response.rbs
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
Returns the value of attribute body.
-
#headers ⇒ Hash[String, String]
readonly
Returns the value of attribute headers.
-
#status ⇒ Integer
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #decode_json ⇒ Object
- #header(name) ⇒ String?
-
#initialize(status, headers, body) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(status, headers, body) ⇒ Response
Returns a new instance of Response.
10 11 12 13 14 15 |
# File 'lib/dpay/http/response.rb', line 10 def initialize(status, headers, body) @status = status @headers = headers.each_with_object({}) { |(name, value), result| result[name.to_s.downcase] = value }.freeze @body = body freeze end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/dpay/http/response.rb', line 8 def body @body end |
#headers ⇒ Hash[String, String] (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/dpay/http/response.rb', line 8 def headers @headers end |
#status ⇒ Integer (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/dpay/http/response.rb', line 8 def status @status end |
Instance Method Details
#decode_json ⇒ Object
21 22 23 24 25 26 |
# File 'lib/dpay/http/response.rb', line 21 def decode_json decoded = JSON.parse(@body.to_s) decoded.is_a?(Hash) || decoded.is_a?(Array) ? decoded : nil rescue JSON::ParserError nil end |
#header(name) ⇒ String?
17 18 19 |
# File 'lib/dpay/http/response.rb', line 17 def header(name) @headers[name.to_s.downcase] end |