Class: Hubspot::HttpResponse
- Defined in:
- lib/hubspot/http_response.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Attributes inherited from Object
Class Method Summary collapse
Instance Method Summary collapse
- #constructor ⇒ Object
-
#initialize(response) ⇒ HttpResponse
constructor
A new instance of HttpResponse.
Methods inherited from Object
#call, #errors, #failure?, #success?
Constructor Details
#initialize(response) ⇒ HttpResponse
Returns a new instance of HttpResponse.
7 8 9 |
# File 'lib/hubspot/http_response.rb', line 7 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/hubspot/http_response.rb', line 5 def response @response end |
Class Method Details
.call(response) ⇒ Object
11 12 13 |
# File 'lib/hubspot/http_response.rb', line 11 def self.call(response) new(response).constructor end |
Instance Method Details
#constructor ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hubspot/http_response.rb', line 15 def constructor case response when Net::HTTPSuccess body = JSON.parse response.body if response.body && response.body.length >= 2 { 'body': body, 'status': response.code } when Net::HTTPUnauthorized { 'error' => "#{response.}: username and password set and correct?", 'status' => response.code } when Net::HTTPServerError # errors.add(error: response.message, :status, response.code) { 'error' => "#{response.}: try again later?", 'status' => response.code } else # errors.add(error: response.message, :status, response.code) { 'error' => response., 'status' => response.code } end end |