class Base::Endpoints::MailingLists

This endpoint contains methods for managing mailing lists.

Public Class Methods

new(access_token:, url:) click to toggle source

Initializes this endpoint.

Calls superclass method Base::Endpoint::new
# File lib/base/endpoints/mailing_lists.rb, line 8
def initialize(access_token:, url:)
  @path = 'mailing_lists'
  super
end

Public Instance Methods

get(id) click to toggle source

Returns the metadata of the mailing list with the given ID.

# 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) click to toggle source

Lists the mailing lists of a project

# 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:) click to toggle source

Sends an email with the given parameters.

If there is no sending domain set up all emails will use the `proxy@base-api.io` 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.

# 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:) click to toggle source

Subscribes an email to the mailing list with the given id.

# 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:) click to toggle source

Unsubscribes an email from the mailing list with the given id.

# 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:) click to toggle source

Returns the unsubscribe url for the given email of list the given id.

# 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