Current section
Files
Jump to
Current section
Files
lib/schemas/event_metadata.ex
defmodule Polymarket.Schemas.EventMetadata do
@moduledoc """
Internal metadata attached to an `Event` returned by the Gamma API.
"""
use TypedEctoSchema
alias Polymarket.JsonUtil
alias Polymarket.Schemas.Coerce
@primary_key false
@derive Jason.Encoder
typed_embedded_schema do
field(:context_requires_regen, :boolean)
field(:context_description, :string)
field(:context_updated_at, :utc_datetime_usec)
end
@doc "Builds an `EventMetadata` from a decoded (JSON) map, coercing each field."
@spec from_attrs(map()) :: {:ok, t()}
def from_attrs(attrs) do
attrs = JsonUtil.snake_case_keys(attrs)
{:ok,
%__MODULE__{
context_requires_regen: attrs["context_requires_regen"],
context_description: attrs["context_description"],
context_updated_at: Coerce.to_datetime(attrs["context_updated_at"])
}}
end
end