Class: Emarsys::Contact
- Inherits:
-
DataObject
- Object
- DataObject
- Emarsys::Contact
- Defined in:
- lib/emarsys/data_objects/contact.rb
Overview
Methods for the Contact API
Class Method Summary collapse
- .batch_params(params = []) ⇒ Object
-
.contact_history(contacts:, account: nil) ⇒ Hash
Get list of emails send to a contact.
-
.create(key_id:, key_value:, params: {}, account: nil) ⇒ Hash
Create a new contact.
-
.create_batch(key_id:, params: [], account: nil) ⇒ Object
Batch creation of contacts.
-
.delete(key_id:, key_value:, account: nil) ⇒ Hash
Delete a contact.
-
.emarsys_id(key_id:, key_value:, account: nil) ⇒ Hash
Get the internal emarsys id of a contact.
-
.export_registrations(distribution_method:, time_range:, contact_fields:, account: nil) ⇒ Hash
Exports the selected fields of contacts whoch registered in the specified time range.
-
.query(key_id:, key_value:, return_value:, account: nil) ⇒ Hash
Query contacts by custom.
-
.search(key_id:, key_values:, fields: [], account: nil) ⇒ Hash
Get contact data by custom search.
- .transform_key_id(key_id) ⇒ Object
-
.update(key_id:, key_value:, params: {}, create_if_not_exists: false, account: nil) ⇒ Hash
Update a contact.
-
.update_batch(key_id:, params: [], create_if_not_exists: false, account: nil) ⇒ Object
Batch update of contacts.
Methods inherited from DataObject
get, parameterize_params, post, put, #request
Class Method Details
.batch_params(params = []) ⇒ Object
156 157 158 |
# File 'lib/emarsys/data_objects/contact.rb', line 156 def batch_params(params = []) params.map { |p| Emarsys::ParamsConverter.new(p).convert_to_ids } end |
.contact_history(contacts:, account: nil) ⇒ Hash
Get list of emails send to a contact
104 105 106 |
# File 'lib/emarsys/data_objects/contact.rb', line 104 def contact_history(contacts:, account: nil) post account, "contact/getcontacthistory", {'contacts' => contacts} end |
.create(key_id:, key_value:, params: {}, account: nil) ⇒ Hash
Create a new contact. The given params are transformed to emarsys ids.
19 20 21 22 |
# File 'lib/emarsys/data_objects/contact.rb', line 19 def create(key_id:, key_value:, params: {}, account: nil) transformed_key_id = transform_key_id(key_id) post account, "contact", params.merge!({'key_id' => transformed_key_id, transformed_key_id => key_value}) end |
.create_batch(key_id:, params: [], account: nil) ⇒ Object
Batch creation of contacts.
62 63 64 |
# File 'lib/emarsys/data_objects/contact.rb', line 62 def create_batch(key_id:, params: [], account: nil) post account, "contact", {'key_id' => transform_key_id(key_id), 'contacts' => batch_params(params)} end |
.delete(key_id:, key_value:, account: nil) ⇒ Hash
Delete a contact. The given params are transformed to emarsys ids.
92 93 94 95 96 |
# File 'lib/emarsys/data_objects/contact.rb', line 92 def delete(key_id:, key_value:, account: nil) path = "contact/delete" transformed_key_id = transform_key_id(key_id) post account, path, {'key_id' => transformed_key_id, transformed_key_id => key_value} end |
.emarsys_id(key_id:, key_value:, account: nil) ⇒ Hash
Get the internal emarsys id of a contact. The given params are transformed to emarsys ids.
32 33 34 |
# File 'lib/emarsys/data_objects/contact.rb', line 32 def emarsys_id(key_id:, key_value:, account: nil) get account, "contact", {"#{transform_key_id(key_id).to_s}" => key_value} end |
.export_registrations(distribution_method:, time_range:, contact_fields:, account: nil) ⇒ Hash
Exports the selected fields of contacts whoch registered in the specified time range
141 142 143 144 145 146 147 |
# File 'lib/emarsys/data_objects/contact.rb', line 141 def export_registrations(distribution_method:, time_range:, contact_fields:, account: nil) post account, "contact/getregistrations", { distribution_method: distribution_method, time_range: time_range, contact_fields: contact_fields } end |
.query(key_id:, key_value:, return_value:, account: nil) ⇒ Hash
Query contacts by custom
131 132 133 |
# File 'lib/emarsys/data_objects/contact.rb', line 131 def query(key_id:, key_value:, return_value: , account: nil) get account, "contact/query", { key_id => key_value, 'return' => return_value} end |
.search(key_id:, key_values:, fields: [], account: nil) ⇒ Hash
Get contact data by custom search
TODO transform fields to numeric fields
118 119 120 |
# File 'lib/emarsys/data_objects/contact.rb', line 118 def search(key_id:, key_values:, fields: [], account: nil) post account, "contact/getdata", {'keyId' => key_id, 'keyValues' => key_values, 'fields' => fields} end |
.transform_key_id(key_id) ⇒ Object
150 151 152 153 |
# File 'lib/emarsys/data_objects/contact.rb', line 150 def transform_key_id(key_id) matching_attributes = Emarsys::FieldMapping.attributes.find{|elem| elem[:identifier] == key_id.to_s} matching_attributes.nil? ? key_id : matching_attributes[:id] end |
.update(key_id:, key_value:, params: {}, create_if_not_exists: false, account: nil) ⇒ Hash
Update a contact. The given params are transformed to emarsys ids.
46 47 48 49 50 |
# File 'lib/emarsys/data_objects/contact.rb', line 46 def update(key_id:, key_value:, params: {}, create_if_not_exists: false, account: nil) path = "contact#{create_if_not_exists ? '/?create_if_not_exists=1' : ''}" transformed_key_id = transform_key_id(key_id) put account, path, params.merge!({'key_id' => transformed_key_id, transformed_key_id => key_value}) end |
.update_batch(key_id:, params: [], create_if_not_exists: false, account: nil) ⇒ Object
Batch update of contacts.
79 80 81 82 |
# File 'lib/emarsys/data_objects/contact.rb', line 79 def update_batch(key_id:, params: [], create_if_not_exists: false, account: nil) path = "contact#{create_if_not_exists ? '/?create_if_not_exists=1' : ''}" put account, path, {'key_id' => transform_key_id(key_id), 'contacts' => batch_params(params)} end |