|
1 | 1 | require 'mailtrap'
|
2 |
| -account_id = 1_111_111 |
| 2 | + |
3 | 3 | client = Mailtrap::Client.new(api_key: 'your-api-key')
|
| 4 | +contact_list = Mailtrap::ContactListsAPI.new 3229, client |
| 5 | +contacts = Mailtrap::ContactsAPI.new 3229, client |
| 6 | + |
| 7 | +# Set your API credentials as environment variables |
| 8 | +# export MAILTRAP_API_KEY='your-api-key' |
| 9 | +# export MAILTRAP_ACCOUNT_ID=your-account-id |
| 10 | +# |
| 11 | +# contact_list = Mailtrap::ContactListsAPI.new |
| 12 | +# contacts = Mailtrap::ContactsAPI.new |
4 | 13 |
|
5 |
| -contact_list = Mailtrap::ContactListsAPI.new(account_id, client) |
| 14 | +# Create new contact list |
6 | 15 | list = contact_list.create(name: 'Test List')
|
7 | 16 |
|
8 |
| -contacts = Mailtrap::ContactsAPI.new(account_id, client) |
9 |
| -contact = contacts.create(email: '[email protected]', fields: { first_name: 'John Doe' }, list_ids: [list.id]) |
10 |
| -puts "Created Contact: #{contact.id}" |
| 17 | +# Get all contact lists |
| 18 | +contact_list.list |
11 | 19 |
|
12 |
| -contact = contacts.get(contact.id) |
13 |
| -puts "Contact: #{contact.email}" |
| 20 | +# Update contact list |
| 21 | +contact_list.update(list.id, name: 'Test List Updated') |
14 | 22 |
|
15 |
| -contact = contacts.update(contact.id, email: '[email protected]', fields: { first_name: 'Jane Doe' }, list_ids: [2]) |
16 |
| -puts "Updated Contact: #{contact.data.email}" |
| 23 | +# Get contact list |
| 24 | +list = contact_list.get(list.id) |
17 | 25 |
|
18 |
| -contacts.delete(contact.data.id) |
19 |
| -puts 'Contact deleted' |
| 26 | +# Create new contact |
| 27 | +contact = contacts.create(email: '[email protected]', fields: { first_name: 'John Doe' }, list_ids: [list.id]) |
20 | 28 |
|
21 |
| -lists = contact_list.list |
22 |
| -puts "Contact Lists: #{lists}" |
| 29 | +# Get contact |
| 30 | +contact = contacts.get(contact.id) |
23 | 31 |
|
24 |
| -contact_list.update(list.id, name: 'Test List Updated') |
| 32 | +# Update contact using id |
| 33 | +updated_contact = contacts.update(contact.id, email: '[email protected]', fields: { first_name: 'Jane Doe' }, |
| 34 | + list_ids_excluded: [list.id]) |
25 | 35 |
|
26 |
| -list = contact_list.get(list.id) |
27 |
| -puts "Contact List: #{list.name}" |
| 36 | +# Update contact using email |
| 37 | +contacts.update(updated_contact.data.email, email: '[email protected]', fields: { first_name: 'Jane Doe' }, |
| 38 | + list_ids_included: [list.id]) |
| 39 | + |
| 40 | +# Delete contact |
| 41 | +contacts.delete(contact.id) |
28 | 42 |
|
| 43 | +# Delete contact list |
29 | 44 | contact_list.delete(list.id)
|
30 |
| -puts 'Contact List deleted' |
|
0 commit comments