Class: Broadcast::Resources::Subscribers
- Defined in:
- lib/broadcast/resources/subscribers.rb
Instance Method Summary collapse
- #activate(email) ⇒ Object
- #add_tags(email, tags) ⇒ Object
-
#create(**attrs) ⇒ Object
Create or upsert a subscriber.
- #deactivate(email) ⇒ Object
- #find(email:) ⇒ Object
-
#list(**params) ⇒ Object
List subscribers (250 per page, with
paginationmetadata; passpage:). - #redact(email) ⇒ Object
- #remove_tags(email, tags) ⇒ Object
- #resubscribe(email) ⇒ Object
- #unsubscribe(email) ⇒ Object
- #update(email, **attrs) ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from Broadcast::Resources::Base
Instance Method Details
#activate(email) ⇒ Object
76 77 78 |
# File 'lib/broadcast/resources/subscribers.rb', line 76 def activate(email) post('/api/v1/subscribers/activate.json', { email: email }) end |
#add_tags(email, tags) ⇒ Object
64 65 66 |
# File 'lib/broadcast/resources/subscribers.rb', line 64 def (email, ) post('/api/v1/subscribers/add_tag.json', { email: email, tags: }) end |
#create(**attrs) ⇒ Object
Create or upsert a subscriber.
Subscriber attributes (wrapped under subscriber: on the wire):
email:, first_name:, last_name:, is_active:, source:,
subscribed_at:, ip_address:, tags: [...], custom_data: {...}
Top-level options (NOT wrapped under subscriber:):
double_opt_in: true | { reply_to:, confirmation_template_id:, include_unsubscribe_link: }
When set, the subscriber is created in unconfirmed state
and a confirmation email is queued.
confirmation_template_id: custom confirmation template (used with double_opt_in: true)
Admin tokens only:
confirmed_at: backdate the confirmation timestamp on create.
Intended for migrating an already-confirmed list off
another provider. Ignored (with a warning) on update,
and ignored entirely for channel-scoped tokens.
Note unsubscribed_at is never settable here — use unsubscribe(email).
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/broadcast/resources/subscribers.rb', line 49 def create(**attrs) double_opt_in = attrs.delete(:double_opt_in) confirmation_template_id = attrs.delete(:confirmation_template_id) payload = { subscriber: attrs } payload[:double_opt_in] = double_opt_in unless double_opt_in.nil? payload[:confirmation_template_id] = confirmation_template_id unless confirmation_template_id.nil? post('/api/v1/subscribers.json', payload) end |
#deactivate(email) ⇒ Object
72 73 74 |
# File 'lib/broadcast/resources/subscribers.rb', line 72 def deactivate(email) post('/api/v1/subscribers/deactivate.json', { email: email }) end |
#find(email:) ⇒ Object
26 27 28 |
# File 'lib/broadcast/resources/subscribers.rb', line 26 def find(email:) get('/api/v1/subscribers/find.json', { email: email }) end |
#list(**params) ⇒ Object
List subscribers (250 per page, with pagination metadata; pass page:).
Filters, all optional and combinable:
is_active: true | false
source: exact match on the source string
created_after: ISO-8601 timestamp
created_before: ISO-8601 timestamp
tags: array — AND logic, subscriber must have all of them
email: partial (case-insensitive) match, not exact
confirmation_status: 'confirmed' | 'unconfirmed'
custom_data: hash — JSONB containment, e.g. { plan: 'pro' }
An unparseable created_after/created_before is ignored by the server
rather than rejected; it comes back as a parameter_ignored warning on
the response, so a bad timestamp silently widens the result set unless
you check result.warnings.
22 23 24 |
# File 'lib/broadcast/resources/subscribers.rb', line 22 def list(**params) get('/api/v1/subscribers.json', params) end |
#redact(email) ⇒ Object
88 89 90 |
# File 'lib/broadcast/resources/subscribers.rb', line 88 def redact(email) post('/api/v1/subscribers/redact.json', { email: email }) end |
#remove_tags(email, tags) ⇒ Object
68 69 70 |
# File 'lib/broadcast/resources/subscribers.rb', line 68 def (email, ) @client.request(:delete, '/api/v1/subscribers/remove_tag.json', { email: email, tags: }) end |
#resubscribe(email) ⇒ Object
84 85 86 |
# File 'lib/broadcast/resources/subscribers.rb', line 84 def resubscribe(email) post('/api/v1/subscribers/resubscribe.json', { email: email }) end |
#unsubscribe(email) ⇒ Object
80 81 82 |
# File 'lib/broadcast/resources/subscribers.rb', line 80 def unsubscribe(email) post('/api/v1/subscribers/unsubscribe.json', { email: email }) end |
#update(email, **attrs) ⇒ Object
60 61 62 |
# File 'lib/broadcast/resources/subscribers.rb', line 60 def update(email, **attrs) patch('/api/v1/subscribers.json', { email: email, subscriber: attrs }) end |