Class: Mailtrap::ContactsImportRequest
- Inherits:
-
Object
- Object
- Mailtrap::ContactsImportRequest
- Defined in:
- lib/mailtrap/contacts_import_request.rb
Overview
A builder class for creating contact import requests Allows you to build a collection of contacts with their associated fields and list memberships
Instance Method Summary collapse
-
#add_to_lists(email:, list_ids:) ⇒ ContactsImportRequest
Adds a contact to the specified lists.
-
#initialize ⇒ ContactsImportRequest
constructor
A new instance of ContactsImportRequest.
-
#remove_from_lists(email:, list_ids:) ⇒ ContactsImportRequest
Removes a contact from the specified lists.
-
#to_a ⇒ Array<Hash>
Array of contact objects ready for import.
-
#upsert(email:, fields: {}) ⇒ ContactsImportRequest
Creates or updates a contact with the provided email and fields.
Constructor Details
#initialize ⇒ ContactsImportRequest
Returns a new instance of ContactsImportRequest.
7 8 9 10 11 |
# File 'lib/mailtrap/contacts_import_request.rb', line 7 def initialize @data = Hash.new do |h, k| h[k] = { email: k, fields: {}, list_ids_included: [], list_ids_excluded: [] } end end |
Instance Method Details
#add_to_lists(email:, list_ids:) ⇒ ContactsImportRequest
Adds a contact to the specified lists
30 31 32 33 34 35 36 |
# File 'lib/mailtrap/contacts_import_request.rb', line 30 def add_to_lists(email:, list_ids:) validate_email!(email) append_list_ids email:, list_ids:, key: :list_ids_included self end |
#remove_from_lists(email:, list_ids:) ⇒ ContactsImportRequest
Removes a contact from the specified lists
42 43 44 45 46 47 48 |
# File 'lib/mailtrap/contacts_import_request.rb', line 42 def remove_from_lists(email:, list_ids:) validate_email!(email) append_list_ids email:, list_ids:, key: :list_ids_excluded self end |
#to_a ⇒ Array<Hash>
Returns Array of contact objects ready for import.
51 52 53 |
# File 'lib/mailtrap/contacts_import_request.rb', line 51 def to_a @data.values end |
#upsert(email:, fields: {}) ⇒ ContactsImportRequest
Creates or updates a contact with the provided email and fields
18 19 20 21 22 23 24 |
# File 'lib/mailtrap/contacts_import_request.rb', line 18 def upsert(email:, fields: {}) validate_email!(email) @data[email][:fields].merge!(fields) self end |