Packages
mercury_client
1.0.0
A complete, production-grade Elixir client for the Mercury Banking API (accounts, transactions, recipients, invoices, payments, treasury, webhooks, and more), with typed errors, retry with backoff, and lazy auto-paginating streams.
Current section
Files
Jump to
Current section
Files
lib/mercury/types.ex
defmodule Mercury.Types do
@moduledoc false
# Shared conversion helpers used by every resource's `from_json/1`.
@doc false
@spec datetime(value :: String.t() | nil) :: DateTime.t() | nil
def datetime(nil), do: nil
def datetime(value) when is_binary(value) do
case DateTime.from_iso8601(value) do
{:ok, datetime, _utc_offset} -> datetime
{:error, _reason} -> nil
end
end
def datetime(_other), do: nil
@doc false
@spec list_of(list :: list() | nil, from_json :: (map() -> struct())) :: [struct()]
def list_of(nil, _from_json), do: []
def list_of(list, from_json) when is_list(list), do: Enum.map(list, from_json)
end