ExShopifyApp.AppEvents.Event (ex_shopify_app v1.2.0)

A usage event to report through ExShopifyApp.AppEvents.report/2.

  • :event_handle - must match a usage meter handle from the pricing config.
  • :value - the usage amount (must be > 0 to be billed).
  • :idempotency_key - stable key deduping the event. Billing events are permanently deduped, so the key must be stable per billing period; the caller owns this.
  • :timestamp - the event DateTime. new/2 stamps it with DateTime.utc_now/0 when not given; on a struct built as a literal without one, ExShopifyApp.AppEvents.report/2 stamps it at send time instead.

Summary

Functions

Builds an event from a map of the required fields.

Maps the event to the App Events API request body for the shop identified by shop_gid (e.g. "gid://shopify/Shop/123"), stamping DateTime.utc_now/0 when the event carries no timestamp.

Types

t()

@type t() :: %ExShopifyApp.AppEvents.Event{
  event_handle: String.t(),
  idempotency_key: String.t(),
  timestamp: DateTime.t() | nil,
  value: number()
}

Functions

new(fields, opts \\ [])

@spec new(
  %{event_handle: String.t(), value: number(), idempotency_key: String.t()},
  keyword()
) :: t()

Builds an event from a map of the required fields.

Options

  • :timestamp - the event DateTime; defaults to DateTime.utc_now/0, so the event carries the time it was built rather than the time it is sent.

to_api_input(event, shop_gid)

@spec to_api_input(t(), String.t()) :: %{required(String.t()) => term()}

Maps the event to the App Events API request body for the shop identified by shop_gid (e.g. "gid://shopify/Shop/123"), stamping DateTime.utc_now/0 when the event carries no timestamp.