Class: Emarsys::Email

Inherits:
DataObject show all
Defined in:
lib/emarsys/data_objects/email.rb

Overview

Methods for the Email API

Class Method Summary collapse

Methods inherited from DataObject

delete, get, parameterize_params, post, put, #request

Class Method Details

.collection(account: nil, **params) ⇒ Hash

List email campaigns

Examples:

Emarsys::Email.collection
Emarsys::Email.collection(:status => 3)
Emarsys::Email.collection(:contactlist => 5)

Parameters:

  • params (Hash)

    Optional filter for the emails

Options Hash (**params):

  • :status (String)

    filter by status

  • :contactlist (String)

    filter by contactlist

Returns:

  • (Hash)

    List of emails



20
21
22
# File 'lib/emarsys/data_objects/email.rb', line 20

def collection(account: nil, **params)
  get , 'email', params
end

.create(account: nil, **params) ⇒ Hash

Create a new email campaign

Examples:

Emarsys::Email.create(
  name: 'Test', language: 'de', fromemail: '[email protected]', fromname: 'John Doe',
  subject: 'Test Subject', :email_category: 3, segment: 1121, contactlist: 0,
  html_source: '<h1>Test</h1>', text_source: 'Test'
)

Parameters:

  • params (Hash)

    Email information to create

Options Hash (**params):

  • :name (String)

    Name of the email campagin

  • :language (String)

    Language Code

  • :fromemail (String)

    sets the from-header email

  • :fromname (String)

    sets the from-header name

  • :subject (String)

    Subject of the email

  • :email_category (Integer)

    associated Email-Category-Id

  • :segment (Integer)

    associated Segment-id

  • :contactlist (Integer)

    associated Contactlist-id

  • :html_source (String)
  • :text_source (String)
  • :unsubscribe (Integer) — default: optional
  • :browse (Integer) — default: optional

Returns:

  • (Hash)

    internal id of the campaign



56
57
58
# File 'lib/emarsys/data_objects/email.rb', line 56

def create(account: nil, **params)
  post , "email", params
end

.delivery_status(id, account: nil, **params) ⇒ Hash

Returns the delivery status of an email

Examples:

Emarsys::Email.delivery_status(1)

Parameters:

  • id (Integer, String)

    Internal email id

  • params (hash)

    recipient parmeters

Options Hash (**params):

  • 'lastId' (String)
  • 'launchId' (Integer)

Returns:

  • (Hash)

    Result data



128
129
130
# File 'lib/emarsys/data_objects/email.rb', line 128

def delivery_status(id, account: nil, **params)
  post , "email/#{id}/getdeliverystatus", params
end

.email_launches(id, account: nil) ⇒ Object



146
147
148
# File 'lib/emarsys/data_objects/email.rb', line 146

def email_launches(id, account: nil)
  post , "email/getlaunchesofemail", emailId: id
end

.export_responses(distribution_method:, time_range:, contact_fields:, sources:, analysis_fields:, account: nil, **params) ⇒ Hash

Exports the selected fields of all contacts who responded to emails within the specified time range.

Examples:

Emarsys::Email.export_responses(
  'local',
  ['2012-02-09', '2014-08-13'],
  [1, 3],
  ['trackable_links'],
  [5, 8, 13]
)

Parameters:

  • distribution_method (String)

    ftp or local

  • time_range (array)

    Array with two elements (start date, end date)

  • contact_fields (array)

    Array of contact field IDs

  • sources (array)

    Array which defines sources

  • analysis_fields (array)

    Array that defines the contact behaviours to analyse

  • params (Hash)

    a customizable set of options

Options Hash (**params):

  • (hash)

Returns:

  • (Hash)

    Result data



168
169
170
171
172
173
174
175
176
177
# File 'lib/emarsys/data_objects/email.rb', line 168

def export_responses(distribution_method:, time_range:, contact_fields:, sources:, analysis_fields:, account: nil, **params)
  params.merge!(
    :distribution_method => distribution_method,
    :time_range => time_range,
    :contact_fields => Emarsys::ParamsConverter.new(contact_fields).convert_to_ids,
    :sources => sources,
    :analysis_fields => analysis_fields
  )
  post , "email/getresponses", params
end

.launch(id, account: nil, **params) ⇒ Hash

Launches an email

Examples:

Emarsys::Email.launch(1)

Parameters:

  • id (Integer, String)

    Internal email id

  • params (hash)

    Optional launch parmeters

Options Hash (**params):

  • :schedule (Datetime)

    launch time

  • :timezone (String)

Returns:

  • (Hash)

    Result data



69
70
71
# File 'lib/emarsys/data_objects/email.rb', line 69

def launch(id, account: nil, **params)
  post , "email/#{id}/launch", params
end

.preview(id, version: 'html', account: nil) ⇒ Hash

Preview an email

Examples:

Emarsys::Email.preview(1)

Parameters:

  • id (Integer, String)

    Internal email id

  • version (String) (defaults to: 'html')

    ‘html’ or ‘text’ version

Returns:

  • (Hash)

    Result data



80
81
82
# File 'lib/emarsys/data_objects/email.rb', line 80

def preview(id, version: 'html', account: nil)
  post , "email/#{id}/preview", {:version => version}
end

.resource(id, account: nil) ⇒ Hash

Get Email attirbutes of a specific email

Examples:

Emarsys::Email.resource(1)

Parameters:

  • id (Integer, String)

    The internal id of an email

Returns:

  • (Hash)

    Attributes hash



30
31
32
# File 'lib/emarsys/data_objects/email.rb', line 30

def resource(id, account: nil)
  get , "email/#{id}", {}
end

.response_summary(id, launch_id: nil, start_date: nil, end_date: nil, account: nil) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/emarsys/data_objects/email.rb', line 85

def response_summary(id, launch_id: nil, start_date: nil, end_date: nil, account: nil)
  params = {}

  if !launch_id.nil?
    params.merge!(launch_id: launch_id) 
  end

  if !start_date.nil? 
    params.merge!(start_date: start_date)
  end

  if !end_date.nil?
    params.merge!(end_date: end_date)
  end

  get , "email/#{id}/responsesummary", params
end

.responses(type:, start_date: nil, end_date: nil, campaign_id: nil, account: nil) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
# File 'lib/emarsys/data_objects/email.rb', line 180

def responses(type:, start_date: nil, end_date: nil, campaign_id: nil, account: nil)
  params = { type: type }
  if !campaign_id.nil?
    params.merge!(campaign_id: campaign_id)
  elsif !start_date.nil? && !end_date.nil?
    params.merge!(start_date: start_date, end_date: end_date)
  else
    raise "Either campaign_id OR start_date/end_date must be provided"
  end
  post , "email/responses", params
end

.responses_result(query_id, account: nil) ⇒ Object



193
194
195
# File 'lib/emarsys/data_objects/email.rb', line 193

def responses_result(query_id, account: nil)
  get , "email/#{query_id}/responses", {}
end

.send_test_mail(id, account: nil, **params) ⇒ Hash

Instruct emarsys to send a test mail

Only one of the three parameters must be sent.

Examples:

Emarsys::Email.send_test_mail(1, {:recipientlist => '[email protected];[email protected]'})

Parameters:

  • id (Integer, String)

    Internal email id

  • params (hash)

    recipient parmeters

Options Hash (**params):

  • :recipientlist (String)

    email_addresses separated by ‘;’

  • :segment_id (Integer)

    custom segement id

  • :contactlist_id (Integer)

    custom contactlist id

Returns:

  • (Hash)

    Result data



115
116
117
# File 'lib/emarsys/data_objects/email.rb', line 115

def send_test_mail(id, account: nil, **params)
  post , "email/#{id}/sendtestmail", params
end

.unsubscribe(account: nil, **params) ⇒ Hash

Tracking email campaign unsubscribes

Examples:

Emarsys::Email.unsubscribe({contact_uid: '1', email_id: '1', launch_list_id: '1'})

Parameters:

  • params (hash)

    unsubscribe parameters

Options Hash (**params):

  • 'contact_uid' (String)
  • 'email_id' (String)
  • 'launch_list_id' (String)

Returns:

  • (Hash)

    Result data



141
142
143
# File 'lib/emarsys/data_objects/email.rb', line 141

def unsubscribe(account: nil, **params)
  post , "email/unsubscribe", params
end