Class: Chartmogul::V1::Request
- Inherits:
-
Object
- Object
- Chartmogul::V1::Request
- Defined in:
- lib/chartmogul/v1/request.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#userpwd ⇒ Object
readonly
Returns the value of attribute userpwd.
Instance Method Summary collapse
-
#body ⇒ Object
Public: Get body.
-
#code ⇒ Object
Public: Get response code.
-
#initialize(url, userpwd: nil, method: :get, **params) ⇒ Request
constructor
Public: Constructor.
-
#next_page ⇒ Object
Public: Get next page.
-
#ok? ⇒ Boolean
Returns true at successful request , false otherwise.
-
#return_code ⇒ Object
Public: Get return code.
Constructor Details
#initialize(url, userpwd: nil, method: :get, **params) ⇒ Request
Public: Constructor.
url - The String url. userpwd - The String with credentials for Basic Authentication. method - The Symbol request method (default: :get). params - The Hash query params.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/chartmogul/v1/request.rb', line 16 def initialize(url, userpwd: nil, method: :get, **params) @url = url @userpwd = userpwd @params = params @response = Typhoeus::Request.new(url, userpwd: userpwd, method: method, params: params, connecttimeout: 5, timeout: 10 ).run end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/chartmogul/v1/request.rb', line 8 def params @params end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/chartmogul/v1/request.rb', line 8 def response @response end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/chartmogul/v1/request.rb', line 8 def url @url end |
#userpwd ⇒ Object (readonly)
Returns the value of attribute userpwd.
8 9 10 |
# File 'lib/chartmogul/v1/request.rb', line 8 def userpwd @userpwd end |
Instance Method Details
#body ⇒ Object
Public: Get body.
Returns the instance of Hashie::Mash.
58 59 60 |
# File 'lib/chartmogul/v1/request.rb', line 58 def body @body ||= Hashie::Mash.new(MultiJson.load response.body || '') end |
#code ⇒ Object
Public: Get response code.
Returns Integer code of response.
44 45 46 |
# File 'lib/chartmogul/v1/request.rb', line 44 def code response.code end |
#next_page ⇒ Object
Public: Get next page.
Returns the instance of Chartmogul::V1::Request.
32 33 34 |
# File 'lib/chartmogul/v1/request.rb', line 32 def next_page Request.new url, params.merge(page: params[:page] + 1, userpwd: userpwd) end |
#ok? ⇒ Boolean
Returns true at successful request , false otherwise.
37 38 39 |
# File 'lib/chartmogul/v1/request.rb', line 37 def ok? [200, 201].include? code end |
#return_code ⇒ Object
Public: Get return code.
Returns Integer return code.
51 52 53 |
# File 'lib/chartmogul/v1/request.rb', line 51 def return_code response.return_code end |