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.to_sym
  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



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

def client
  Emarsys::Client.new()
end

#converted_paramsObject



46
47
48
# File 'lib/emarsys/request.rb', line 46

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

#emarsys_uriObject



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

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
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