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, body: nil, headers: {}, method: :get, userpwd: nil, **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, body: nil, headers: {}, method: :get, userpwd: nil, **params) ⇒ Request
Public: Constructor.
url - The String url. body - The String body (default: nil). headers - The Hash headers (default: {}). method - The Symbol request method (default: :get). userpwd - The String with credentials for Basic Authentication (default: nil). params - The Hash query params (default: {}).
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/chartmogul/v1/request.rb', line 18 def initialize(url, body: nil, headers: {}, method: :get, userpwd: nil, **params) @url = url @userpwd = userpwd @params = params if body body = MultiJson.dump(body) headers.merge!('Content-Type' => 'application/json') end @response = Typhoeus::Request.new(url, body: body, connecttimeout: 5, headers: headers, method: method, params: params, timeout: 10, userpwd: userpwd, ).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.
68 69 70 |
# File 'lib/chartmogul/v1/request.rb', line 68 def body @body ||= Hashie::Mash.new(MultiJson.load response.body || '') end |
#code ⇒ Object
Public: Get response code.
Returns Integer code of response.
54 55 56 |
# File 'lib/chartmogul/v1/request.rb', line 54 def code response.code end |
#next_page ⇒ Object
Public: Get next page.
Returns the instance of Chartmogul::V1::Request.
42 43 44 |
# File 'lib/chartmogul/v1/request.rb', line 42 def next_page Request.new url, params.merge(page: params[:page] + 1, userpwd: userpwd) end |
#ok? ⇒ Boolean
Returns true at successful request , false otherwise.
47 48 49 |
# File 'lib/chartmogul/v1/request.rb', line 47 def ok? [200, 201].include? code end |
#return_code ⇒ Object
Public: Get return code.
Returns Integer return code.
61 62 63 |
# File 'lib/chartmogul/v1/request.rb', line 61 def return_code response.return_code end |