Class: Emarsys::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/emarsys/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(, http_verb, path, params = {})
  self.path = path
  self.http_verb = http_verb
  self.params = params
  self. = 
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



5
6
7
# File 'lib/emarsys/request.rb', line 5

def 
  @account
end

#http_verbObject

Returns the value of attribute http_verb.



5
6
7
# File 'lib/emarsys/request.rb', line 5

def http_verb
  @http_verb
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/emarsys/request.rb', line 5

def params
  @params
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/emarsys/request.rb', line 5

def path
  @path
end

Instance Method Details

#clientObject



35
36
37
# File 'lib/emarsys/request.rb', line 35

def client
  Emarsys::Client.new()
end

#converted_paramsObject



43
44
45
# File 'lib/emarsys/request.rb', line 43

def converted_params
  Emarsys::ParamsConverter.new(params).convert_to_ids
end

#emarsys_uriObject



39
40
41
# File 'lib/emarsys/request.rb', line 39

def emarsys_uri
  [client.endpoint, @path].join('/')
end

#send_requestObject



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