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
-
.contact_history(contact_ids_array) ⇒ Hash
Get list of emails send to a contact.
-
.create(key_id, key_value, params = {}) ⇒ Hash
Create a new contact.
-
.create_batch(key_id, params = []) ⇒ Object
Batch creation of contacts.
-
.emarsys_id(key_id, key_value) ⇒ Hash
Get the interal emarsys id of a contact.
-
.export_registrations(params = {}) ⇒ Hash
Exports the selected fields of contacts whoch registered in the specified time range.
-
.search(key_id, key_values = [], fields = []) ⇒ Hash
Get contact data by custom search.
- .transform_key_id(key_id) ⇒ Object
-
.update(key_id, key_value, params = {}) ⇒ Hash
Update a contact.
-
.update_batch(key_id, params = []) ⇒ Object
Batch update of contacts.
Methods inherited from DataObject
delete, get, parameterize_params, post, put, #request
Class Method Details
.contact_history(contact_ids_array) ⇒ Hash
Get list of emails send to a contact
85 86 87 |
# File 'lib/emarsys/data_objects/contact.rb', line 85 def contact_history(contact_ids_array) post "contact/getcontacthistory", {'contacts' => contact_ids_array} end |
.create(key_id, key_value, params = {}) ⇒ Hash
Create a new contact. The given params are transformed to emarsys ids.
18 19 20 21 |
# File 'lib/emarsys/data_objects/contact.rb', line 18 def create(key_id, key_value, params = {}) transformed_key_id = transform_key_id(key_id) post "contact", params.merge!({'key_id' => transformed_key_id, transformed_key_id => key_value}) end |
.create_batch(key_id, params = []) ⇒ Object
Batch creation of contacts.
TODO params should be parameterized with field mappings
60 61 62 |
# File 'lib/emarsys/data_objects/contact.rb', line 60 def create_batch(key_id, params = []) post "contact", {'key_id' => transform_key_id(key_id), 'contacts' => params} end |
.emarsys_id(key_id, key_value) ⇒ Hash
Get the interal emarsys id of a contact. The given params are transformed to emarsys ids.
31 32 33 |
# File 'lib/emarsys/data_objects/contact.rb', line 31 def emarsys_id(key_id, key_value) get "contact/#{transform_key_id(key_id).to_s}=#{key_value.to_s}", {} end |
.export_registrations(params = {}) ⇒ Hash
Exports the selected fields of contacts whoch registered in the specified time range
109 110 111 |
# File 'lib/emarsys/data_objects/contact.rb', line 109 def export_registrations(params = {}) post "contact/getregistrations", params end |
.search(key_id, key_values = [], fields = []) ⇒ Hash
Get contact data by custom search
TODO transform fields to numeric fields
99 100 101 |
# File 'lib/emarsys/data_objects/contact.rb', line 99 def search(key_id, key_values = [], fields = []) post "contact/getdata", {'keyId' => key_id, 'keyValues' => key_values, 'fields' => fields} end |
.transform_key_id(key_id) ⇒ Object
114 115 116 117 |
# File 'lib/emarsys/data_objects/contact.rb', line 114 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 = {}) ⇒ Hash
Update a contact. The given params are transformed to emarsys ids.
44 45 46 47 |
# File 'lib/emarsys/data_objects/contact.rb', line 44 def update(key_id, key_value, params = {}) transformed_key_id = transform_key_id(key_id) put "contact", params.merge!({'key_id' => transformed_key_id, transformed_key_id => key_value}) end |
.update_batch(key_id, params = []) ⇒ Object
Batch update of contacts.
TODO params should be parameterized with field mappings
75 76 77 |
# File 'lib/emarsys/data_objects/contact.rb', line 75 def update_batch(key_id, params = []) put "contact", {'key_id' => transform_key_id(key_id), 'contacts' => params} end |