Class: Axene::Mailer::Resources::Contacts
- Inherits:
-
Object
- Object
- Axene::Mailer::Resources::Contacts
- Defined in:
- lib/axene/mailer/resources/contacts.rb
Overview
The contacts resource: manage subscriber lists, their contacts, CSV imports, and templated bulk sends. Accessed as client.contacts.
Instance Method Summary collapse
-
#add_contact(list_id, email:, name: nil, metadata: nil) ⇒ Hash
Add a single contact to a list.
-
#bulk_send(list_id, sender_address_id:, subject:, html: nil, text: nil, tags: nil) ⇒ Hash
Send a templated email to every contact in a list.
-
#create_list(name:, description: nil, icon_seed: nil) ⇒ Hash
Create a subscriber list.
-
#delete_list(id) ⇒ nil
Delete a list and all of its contacts.
-
#get_list(id, page: 0, limit: 50) ⇒ Hash
Get a list with a page of its contacts (zero-based
page). -
#initialize(transport) ⇒ Contacts
constructor
A new instance of Contacts.
-
#list_lists ⇒ Array<Hash>
List all subscriber lists in the active workspace.
-
#remove_contact(list_id, contact_id) ⇒ nil
Remove a contact from a list.
-
#update_list(id, name: nil, description: nil, icon_seed: nil) ⇒ Hash
Update a list’s name, description, or icon (partial).
-
#upload_csv(list_id, file, filename: "contacts.csv") ⇒ Hash
Import contacts from a CSV file (header row required).
Constructor Details
#initialize(transport) ⇒ Contacts
Returns a new instance of Contacts.
10 11 12 |
# File 'lib/axene/mailer/resources/contacts.rb', line 10 def initialize(transport) @transport = transport end |
Instance Method Details
#add_contact(list_id, email:, name: nil, metadata: nil) ⇒ Hash
Add a single contact to a list.
69 70 71 72 |
# File 'lib/axene/mailer/resources/contacts.rb', line 69 def add_contact(list_id, email:, name: nil, metadata: nil) @transport.request(:post, "/v1/contacts/#{Util.escape(list_id)}/contacts", body: Util.prune(email: email, name: name, metadata: )) end |
#bulk_send(list_id, sender_address_id:, subject:, html: nil, text: nil, tags: nil) ⇒ Hash
Send a templated email to every contact in a list. The contact_list_id is injected automatically from list_id. Subject/html/text may use {email}, {name}, and {metadata_key} placeholders.
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/axene/mailer/resources/contacts.rb', line 108 def bulk_send(list_id, sender_address_id:, subject:, html: nil, text: nil, tags: nil) body = Util.prune( contact_list_id: list_id, sender_address_id: sender_address_id, subject: subject, html: html, text: text, tags: ) @transport.request(:post, "/v1/contacts/#{Util.escape(list_id)}/send", body: body) end |
#create_list(name:, description: nil, icon_seed: nil) ⇒ Hash
Create a subscriber list.
27 28 29 30 |
# File 'lib/axene/mailer/resources/contacts.rb', line 27 def create_list(name:, description: nil, icon_seed: nil) @transport.request(:post, "/v1/contacts/", body: Util.prune(name: name, description: description, icon_seed: icon_seed)) end |
#delete_list(id) ⇒ nil
Delete a list and all of its contacts.
58 59 60 |
# File 'lib/axene/mailer/resources/contacts.rb', line 58 def delete_list(id) @transport.request(:delete, "/v1/contacts/#{Util.escape(id)}") end |
#get_list(id, page: 0, limit: 50) ⇒ Hash
Get a list with a page of its contacts (zero-based page).
38 39 40 |
# File 'lib/axene/mailer/resources/contacts.rb', line 38 def get_list(id, page: 0, limit: 50) @transport.request(:get, "/v1/contacts/#{Util.escape(id)}", query: { page: page, limit: limit }) end |
#list_lists ⇒ Array<Hash>
List all subscriber lists in the active workspace.
17 18 19 |
# File 'lib/axene/mailer/resources/contacts.rb', line 17 def list_lists @transport.request(:get, "/v1/contacts/") end |
#remove_contact(list_id, contact_id) ⇒ nil
Remove a contact from a list.
79 80 81 |
# File 'lib/axene/mailer/resources/contacts.rb', line 79 def remove_contact(list_id, contact_id) @transport.request(:delete, "/v1/contacts/#{Util.escape(list_id)}/contacts/#{Util.escape(contact_id)}") end |
#update_list(id, name: nil, description: nil, icon_seed: nil) ⇒ Hash
Update a list’s name, description, or icon (partial).
49 50 51 52 |
# File 'lib/axene/mailer/resources/contacts.rb', line 49 def update_list(id, name: nil, description: nil, icon_seed: nil) @transport.request(:patch, "/v1/contacts/#{Util.escape(id)}", body: Util.prune(name: name, description: description, icon_seed: icon_seed)) end |
#upload_csv(list_id, file, filename: "contacts.csv") ⇒ Hash
Import contacts from a CSV file (header row required). The email column is auto-detected; other columns become contact metadata.
file may be raw bytes (a String) or a path to a readable file.
92 93 94 95 |
# File 'lib/axene/mailer/resources/contacts.rb', line 92 def upload_csv(list_id, file, filename: "contacts.csv") bytes = read_file(file) @transport.upload("/v1/contacts/#{Util.escape(list_id)}/upload", bytes, filename) end |