Class: Workarea::Listrak::EmailApi::Contacts

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/listrak/email_api/contacts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Contacts

Returns a new instance of Contacts.



6
7
8
# File 'app/services/workarea/listrak/email_api/contacts.rb', line 6

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'app/services/workarea/listrak/email_api/contacts.rb', line 4

def client
  @client
end

Instance Method Details

#get(list_id, contactIdentifier, options = {}) ⇒ Workarea::Listrak::Models::Contact

Parameters:

  • list_id (String)

    Identifier used to locate the list.

  • contactIdentifier (String)

    dentifier used to locate the contact. You may specify either an email address or a Listrak email key.

  • options (Hash) (defaults to: {})

    extra options when getting the contact

Options Hash (options):

  • segmentationFieldIds (String)

    Comma-separated list of segmentation field IDs to retrieve. Up to 30 fields may be included.

Returns:



36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/workarea/listrak/email_api/contacts.rb', line 36

def get(list_id, contactIdentifier, options = {})
  params = validate_query_params(options, get_params)
  path = [
    "/email/v1/List/#{list_id}/Contact/#{contactIdentifier}",
    params
  ].compact.join '?'
  request = Net::HTTP::Get.new(path)
  response = client.request request
  body = JSON.parse response.body
  Listrak::Models::Contact.new(body["data"])
end

#upsert(list_id, contact, options = {}) ⇒ Object

Parameters:

  • list_id (String)

    the list to add this contact to

  • contact (Workarea::Listrak::Models::ContactForm)

    to create or update

  • options (Hash) (defaults to: {})

    extra options when upserting the contact

Options Hash (options):

  • eventIds (String)

    Comma-separated list of event identifiers that should be raised after the contact is created or updated.

  • overrideUnsubscribe (Boolean)

    Whether a contact in an unsubscribed state should be forced to a subscribed state. The default value is false

  • subscribedByContact (Boolean)

    Whether the subscribe was initiated by the contact. The default value is false.

  • sendDoubleOptIn (Boolean)

    Whether a double opt-in email should be sent if a new contact is being created. The default value is false.

  • updateType (String)

    If updating an existing contact, the type of update that will be performed on any submitted segmentation fields. Allowed values are Update, Append, and Overwrite. The default value is Update.

  • newEmailAddress (String)

    If updating an existing contact, the contact’s email address will be changed to this value. Provide the original email address in the emailAddress body field to select the existing contact.



19
20
21
22
23
24
25
26
27
28
# File 'app/services/workarea/listrak/email_api/contacts.rb', line 19

def upsert(list_id, contact, options = {})
  params = validate_query_params(options, upsert_params)
  path = ["/email/v1/List/#{list_id}/Contact", params].compact.join '?'
  request = Net::HTTP::Post.new(path).tap do |post|
    post.body = contact.to_json
  end
  response = client.request request
  body = JSON.parse(response.body)
  body["data"]
end