Class: Gillbus::V2::Responses::Base
- Inherits:
-
Object
- Object
- Gillbus::V2::Responses::Base
- Defined in:
- lib/gillbus/v2/responses/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#http_body ⇒ Object
readonly
Returns the value of attribute http_body.
-
#http_headers ⇒ Object
readonly
Returns the value of attribute http_headers.
-
#http_status ⇒ Object
readonly
Returns the value of attribute http_status.
Instance Method Summary collapse
- #error_code ⇒ Object
- #error_message ⇒ Object
-
#initialize(http_response) ⇒ Base
constructor
A new instance of Base.
- #json_body ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(http_response) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 |
# File 'lib/gillbus/v2/responses/base.rb', line 8 def initialize(http_response) @http_status = http_response.status @http_headers = http_response.headers @http_body = http_response.body end |
Instance Attribute Details
#http_body ⇒ Object (readonly)
Returns the value of attribute http_body.
6 7 8 |
# File 'lib/gillbus/v2/responses/base.rb', line 6 def http_body @http_body end |
#http_headers ⇒ Object (readonly)
Returns the value of attribute http_headers.
5 6 7 |
# File 'lib/gillbus/v2/responses/base.rb', line 5 def http_headers @http_headers end |
#http_status ⇒ Object (readonly)
Returns the value of attribute http_status.
4 5 6 |
# File 'lib/gillbus/v2/responses/base.rb', line 4 def http_status @http_status end |
Instance Method Details
#error_code ⇒ Object
23 24 25 |
# File 'lib/gillbus/v2/responses/base.rb', line 23 def error_code json_body["status"] unless success? end |
#error_message ⇒ Object
27 28 29 |
# File 'lib/gillbus/v2/responses/base.rb', line 27 def json_body["message"] unless success? end |
#json_body ⇒ Object
14 15 16 17 |
# File 'lib/gillbus/v2/responses/base.rb', line 14 def json_body return @json_body if defined?(@json_body) @json_body = JSON.parse(@http_body) rescue {} end |
#success? ⇒ Boolean
19 20 21 |
# File 'lib/gillbus/v2/responses/base.rb', line 19 def success? http_status == 200 end |