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/query_params.ex
defmodule Mercury.QueryParams do
@moduledoc """
Normalizes the keyword lists / maps passed as list-endpoint filters into a
clean keyword list suitable for `Req`'s `:params` option: `nil` values are
dropped (matching the reference SDK's `omitempty` semantics) and atoms are
stringified.
"""
@doc false
@spec build(params :: keyword() | map() | nil) :: keyword()
def build(nil), do: []
def build(params) when is_list(params) or is_map(params) do
params
|> Enum.to_list()
|> Enum.reject(fn {_key, value} -> is_nil(value) end)
|> Enum.map(fn {key, value} -> {key, normalize(value)} end)
end
defp normalize(nil), do: nil
defp normalize(value) when is_list(value), do: Enum.map(value, &normalize/1)
defp normalize(value) when is_atom(value) and value not in [true, false],
do: Atom.to_string(value)
defp normalize(value), do: value
end