Class: Paystack::Response
- Inherits:
-
Object
- Object
- Paystack::Response
- Defined in:
- lib/paystack/response.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#http_status ⇒ Object
readonly
Returns the value of attribute http_status.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/paystack/response.rb', line 10 def initialize(http_response) @http_status = http_response.code.to_i body = http_response.body.to_s parsed = body.empty? ? {} : JSON.parse(body, symbolize_names: true) @status = parsed[:status] @message = parsed[:message] @data = parsed[:data] @meta = parsed[:meta] raise_error! unless success? end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/paystack/response.rb', line 8 def data @data end |
#http_status ⇒ Object (readonly)
Returns the value of attribute http_status.
8 9 10 |
# File 'lib/paystack/response.rb', line 8 def http_status @http_status end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
8 9 10 |
# File 'lib/paystack/response.rb', line 8 def @message end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
8 9 10 |
# File 'lib/paystack/response.rb', line 8 def @meta end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/paystack/response.rb', line 8 def status @status end |
Instance Method Details
#success? ⇒ Boolean
21 22 23 |
# File 'lib/paystack/response.rb', line 21 def success? (200..299).cover?(@http_status) && @status != false end |