EDA.Entitlement (EDA v0.5.0-beta.2)

Copy Markdown View Source

A user's or a guild's access to one of the app's SKUs — what a premium app checks before granting a perk.

Arrives with the ENTITLEMENT_CREATE, _UPDATE and _DELETE events and from EDA.API.Entitlement. Discord's own advice is to grant perks on entitlements, not on subscription status: see active?/1.

An entitlement is not deleted when it expires; ends_at passes instead. Deletion happens on a refund, or when Discord or the app removes it.

Summary

Functions

Whether the entitlement grants access right now: not deleted, already started, not yet ended. A missing start or end date is no bound.

Converts a raw entitlement object into this struct.

Types

t()

@type t() :: %EDA.Entitlement{
  application_id: String.t() | nil,
  consumed: boolean() | nil,
  deleted: boolean(),
  ends_at: DateTime.t() | nil,
  guild_id: String.t() | nil,
  id: String.t() | nil,
  sku_id: String.t() | nil,
  starts_at: DateTime.t() | nil,
  type: type() | integer() | nil,
  user_id: String.t() | nil
}

type()

@type type() ::
  :purchase
  | :premium_subscription
  | :developer_gift
  | :test_mode_purchase
  | :free_purchase
  | :user_gift
  | :premium_purchase
  | :application_subscription

Functions

active?(entitlement, now \\ DateTime.utc_now())

@spec active?(t(), DateTime.t()) :: boolean()

Whether the entitlement grants access right now: not deleted, already started, not yet ended. A missing start or end date is no bound.

iex> EDA.Entitlement.active?(%EDA.Entitlement{deleted: false})
true

iex> EDA.Entitlement.active?(%EDA.Entitlement{ends_at: ~U[2020-01-01 00:00:00Z]})
false

from_raw(raw)

@spec from_raw(map()) :: t()

Converts a raw entitlement object into this struct.