Class: Base::Endpoints::MailingLists
- Inherits:
-
Base::Endpoint
- Object
- Base::Endpoint
- Base::Endpoints::MailingLists
- Defined in:
- lib/base/endpoints/mailing_lists.rb
Overview
This endpoint contains methods for managing mailing lists.
Instance Attribute Summary
Attributes inherited from Base::Endpoint
Instance Method Summary collapse
-
#get(id) ⇒ Object
Returns the metadata of the mailing list with the given ID.
-
#initialize(access_token:, url:) ⇒ MailingLists
constructor
Initializes this endpoint.
-
#list(page: 1, per_page: 10) ⇒ Object
Lists the mailing lists of a project.
-
#send(id:, subject:, from:, html:, text:) ⇒ Object
Sends an email with the given parameters.
-
#subscribe(id:, email:) ⇒ Object
Subscribes an email to the mailing list with the given id.
-
#unsubscribe(id:, email:) ⇒ Object
Unsubscribes an email from the mailing list with the given id.
-
#unsubscribe_url(id:, email:) ⇒ Object
Returns the unsubscribe url for the given email of list the given id.
Methods inherited from Base::Endpoint
Constructor Details
#initialize(access_token:, url:) ⇒ MailingLists
Initializes this endpoint.
8 9 10 11 |
# File 'lib/base/endpoints/mailing_lists.rb', line 8 def initialize(access_token:, url:) @path = 'mailing_lists' super end |
Instance Method Details
#get(id) ⇒ Object
Returns the metadata of the mailing list with the given ID.
73 74 75 76 77 78 79 80 |
# File 'lib/base/endpoints/mailing_lists.rb', line 73 def get(id) request do response = connection.get id parse(response.body) end end |
#list(page: 1, per_page: 10) ⇒ Object
Lists the mailing lists of a project
14 15 16 17 18 19 20 21 |
# File 'lib/base/endpoints/mailing_lists.rb', line 14 def list(page: 1, per_page: 10) request do response = connection.get('', per_page: per_page, page: page) parse(response.body) end end |
#send(id:, subject:, from:, html:, text:) ⇒ Object
Sends an email with the given parameters.
If there is no sending domain set up all emails will use the ‘[email protected]` sender and ignore the given one, also in this case there is a rate limit which is 30 emails in an hour.
If there is a sending domain, the sender must match that domain otherwise it will return an error.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/base/endpoints/mailing_lists.rb', line 31 def send(id:, subject:, from:, html:, text:) request do response = connection.post("#{id}/send", 'from' => from, 'subject' => subject, 'html' => html, 'text' => text) parse(response.body) end end |
#subscribe(id:, email:) ⇒ Object
Subscribes an email to the mailing list with the given id.
45 46 47 48 49 50 51 52 |
# File 'lib/base/endpoints/mailing_lists.rb', line 45 def subscribe(id:, email:) request do response = connection.post("#{id}/subscribe", 'email' => email) parse(response.body) end end |
#unsubscribe(id:, email:) ⇒ Object
Unsubscribes an email from the mailing list with the given id.
55 56 57 58 59 60 61 62 |
# File 'lib/base/endpoints/mailing_lists.rb', line 55 def unsubscribe(id:, email:) request do response = connection.post("#{id}/unsubscribe", 'email' => email) parse(response.body) end end |
#unsubscribe_url(id:, email:) ⇒ Object
Returns the unsubscribe url for the given email of list the given id.
65 66 67 68 69 70 |
# File 'lib/base/endpoints/mailing_lists.rb', line 65 def unsubscribe_url(id:, email:) token = Base64.encode64("#{id}:#{email}") "#{connection.url_prefix}unsubscribe?token=#{token}" end |