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 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
35 36 37 |
# File 'lib/emarsys/request.rb', line 35 def client Emarsys::Client.new(account) end |
#converted_params ⇒ Object
43 44 45 |
# File 'lib/emarsys/request.rb', line 43 def converted_params Emarsys::ParamsConverter.new(params).convert_to_ids end |
#emarsys_uri ⇒ Object
39 40 41 |
# File 'lib/emarsys/request.rb', line 39 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 |
# File 'lib/emarsys/request.rb', line 14 def send_request case http_verb.to_sym when :post RestClient.post(emarsys_uri, converted_params.to_json, :content_type => :json, :x_wsse => client.x_wsse_string) do |response, request, result, &block| Emarsys::Response.new(response) end when :put RestClient.put emarsys_uri, converted_params.to_json, :content_type => :json, :x_wsse => client.x_wsse_string do |response, request, result, &block| Emarsys::Response.new(response) end when :delete RestClient.delete(emarsys_uri, :content_type => :json, :x_wsse => client.x_wsse_string) do |response, request, result, &block| Emarsys::Response.new(response) end else RestClient.get(emarsys_uri, :content_type => :json, :x_wsse => client.x_wsse_string) do |response, request, result, &block| Emarsys::Response.new(response) end end end |