Class: PushBot::Response
- Inherits:
-
Object
- Object
- PushBot::Response
- Defined in:
- lib/push_bot/response.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
Instance Method Summary collapse
-
#body ⇒ Object
The raw response body string.
-
#error? ⇒ Boolean
Did the response complete with an error.
-
#initialize(request) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
-
#json ⇒ Hash, Array
The result of the request as a JSON Object.
-
#success? ⇒ Boolean
Did the request complete successfully or have issues.
Constructor Details
#initialize(request) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 |
# File 'lib/push_bot/response.rb', line 5 def initialize(request) @raw_response = request.run @success = raw_response.success? rescue => e @error = e end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
3 4 5 |
# File 'lib/push_bot/response.rb', line 3 def error @error end |
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
3 4 5 |
# File 'lib/push_bot/response.rb', line 3 def raw_response @raw_response end |
Instance Method Details
#body ⇒ Object
The raw response body string
28 29 30 |
# File 'lib/push_bot/response.rb', line 28 def body raw_response.try(:body) end |
#error? ⇒ Boolean
Did the response complete with an error
23 24 25 |
# File 'lib/push_bot/response.rb', line 23 def error? defined?(@error) && @error end |
#inspect ⇒ Object
13 14 15 |
# File 'lib/push_bot/response.rb', line 13 def inspect "#<#{self.class}:#{object_id} @success=#{success?} @json=#{json}>" end |
#json ⇒ Hash, Array
The result of the request as a JSON Object
35 36 37 |
# File 'lib/push_bot/response.rb', line 35 def json @json ||= body.present? ? JSON.parse(body) : {} end |
#success? ⇒ Boolean
Did the request complete successfully or have issues
18 19 20 |
# File 'lib/push_bot/response.rb', line 18 def success? defined?(@success) && @success end |