Class: Workarea::Emarsys::Gateway

Inherits:
Object
  • Object
show all
Defined in:
app/lib/workarea/emarsys/gateway.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secret_key, customer_id, options = {}) ⇒ Gateway

Returns a new instance of Gateway.



6
7
8
9
10
# File 'app/lib/workarea/emarsys/gateway.rb', line 6

def initialize(secret_key, customer_id, options = {})
  @secret_key = secret_key
  @customer_id = customer_id
  @options = options
end

Instance Attribute Details

#customer_idObject (readonly)

Returns the value of attribute customer_id.



4
5
6
# File 'app/lib/workarea/emarsys/gateway.rb', line 4

def customer_id
  @customer_id
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'app/lib/workarea/emarsys/gateway.rb', line 4

def options
  @options
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



4
5
6
# File 'app/lib/workarea/emarsys/gateway.rb', line 4

def secret_key
  @secret_key
end

Instance Method Details

#create_contact(attrs) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/lib/workarea/emarsys/gateway.rb', line 12

def create_contact(attrs)
  base_uri = "/api/v2/internal/#{customer_id}/contact/"
  params = { create_if_not_exists: 1 }
  query_values = "?" + params.to_query

  path = base_uri + query_values

  request_data = sign_request('put', path, attrs.to_json)

  response = connection.put do |req|
    req.url path
    req.params = params
    req.body = attrs.to_json

    request_data[:headers].each do |k, v|
      req.headers[k] = v
    end
  end

  Response.new(response)
end