Tayori.Subscribers (Tayori v0.1.0)

Copy Markdown View Source

Readers who get the news by email, from the public page: the :subscriptions feature.

Every address is confirmed first: subscribe/2 sends a link, and confirm/1 takes its token. Each email has a link to unsubscribe (unsubscribe/1), which deletes the address. An entry is sent once, when it is published, if the admin chose to email it and it is for everyone (Tayori.Entry's :email): a subscriber is an address, not a reader of the app, so an entry for some readers is never emailed.

With the :emails config, the entries to email wait, and one email of them goes out on a schedule: emails: [every: {:weekly, :monday}], or :monthly, or {:days, n}, at the :at time of day (UTC). It lists their titles and summaries with links to the public page; a period of one entry sends that entry, as it would alone. A period with none sends nothing. Each entry is sent once, in the first email after it is published (emailed_at).

The emails go through the app's own Swoosh mailer (:mailer, :email_from and :page_url of Tayori.Config).

Summary

Functions

Confirms the address of a token. Returns the subscriber, or :error.

The confirmed subscribers and those waiting, for the admin.

Subscribes an address, in a language: sends it a link to confirm. An address already confirmed gets nothing, and an address waiting for its confirmation gets the link again. The answer is the same in every case, so that the page tells no one who subscribed.

Deletes the subscriber of a token. :ok whether or not there was one.

Types

t()

@type t() :: %Tayori.Subscribers{
  __meta__: term(),
  confirmed_at: DateTime.t() | nil,
  email: String.t() | nil,
  id: Ecto.UUID.t() | nil,
  inserted_at: term(),
  locale: String.t() | nil,
  token: String.t() | nil,
  updated_at: term()
}

Functions

confirm(token)

@spec confirm(String.t()) :: {:ok, t()} | :error

Confirms the address of a token. Returns the subscriber, or :error.

counts()

@spec counts() :: %{confirmed: non_neg_integer(), waiting: non_neg_integer()}

The confirmed subscribers and those waiting, for the admin.

subscribe(email, locale \\ nil)

@spec subscribe(String.t(), String.t() | nil) :: :ok | {:error, Ecto.Changeset.t()}

Subscribes an address, in a language: sends it a link to confirm. An address already confirmed gets nothing, and an address waiting for its confirmation gets the link again. The answer is the same in every case, so that the page tells no one who subscribed.

unsubscribe(token)

@spec unsubscribe(String.t()) :: :ok

Deletes the subscriber of a token. :ok whether or not there was one.