Class: Emarsys::Request
- Inherits:
-
Object
- Object
- Emarsys::Request
- Defined in:
- lib/emarsys/request.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#http_verb ⇒ Object
Returns the value of attribute http_verb.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #client ⇒ Object
- #converted_params ⇒ Object
- #emarsys_uri ⇒ Object
-
#initialize(account, http_verb, path, params = {}) ⇒ Request
constructor
A new instance of Request.
- #send_request ⇒ Object
Constructor Details
#initialize(account, http_verb, path, params = {}) ⇒ Request
Returns a new instance of Request.
7 8 9 10 11 12 |
# File 'lib/emarsys/request.rb', line 7 def initialize(account, http_verb, path, params = {}) self.path = path self.http_verb = http_verb.to_sym self.params = params self.account = account end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
5 6 7 |
# File 'lib/emarsys/request.rb', line 5 def account @account end |
#http_verb ⇒ Object
Returns the value of attribute http_verb.
5 6 7 |
# File 'lib/emarsys/request.rb', line 5 def http_verb @http_verb end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/emarsys/request.rb', line 5 def params @params end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/emarsys/request.rb', line 5 def path @path end |
Instance Method Details
#client ⇒ Object
38 39 40 |
# File 'lib/emarsys/request.rb', line 38 def client Emarsys::Client.new(account) end |
#converted_params ⇒ Object
46 47 48 |
# File 'lib/emarsys/request.rb', line 46 def converted_params Emarsys::ParamsConverter.new(params).convert_to_ids end |
#emarsys_uri ⇒ Object
42 43 44 |
# File 'lib/emarsys/request.rb', line 42 def emarsys_uri [client.endpoint, @path].join('/') end |
#send_request ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/emarsys/request.rb', line 14 def send_request args = { method: http_verb, url: emarsys_uri, headers: { content_type: :json, x_wsse: client.x_wsse_string } } if client.open_timeout args.merge!(open_timeout: client.open_timeout) end if client.read_timeout args.merge!(read_timeout: client.read_timeout) end if [:post, :put].include?(http_verb) args.merge!(payload: converted_params.to_json) end RestClient::Request.execute(args) do |response, request, result, &block| Emarsys::Response.new(response) end end |