Shared helpers for converting snake_case attrs to API-format maps.
Used internally by all API modules to convert attrs (keyword list or map, e.g.
name: "my-zone" or %{name: "my-zone"}) into the PascalCase maps the bunny.net
API expects (e.g. %{"Name" => "my-zone"}). Unknown keys raise ArgumentError
with the valid set listed.
Summary
Functions
Like map_keys!/2 but only includes keys present in the mapping, ignoring extras.
Useful for query param conversion where unknown keys should be silently dropped.
Converts attrs (keyword list or map) to a map using the given key mapping.
Puts a key-value pair into a keyword list only if the value is not nil.
Puts a key-value pair into a map only if the value is not nil.
Types
Functions
Like map_keys!/2 but only includes keys present in the mapping, ignoring extras.
Useful for query param conversion where unknown keys should be silently dropped.
Converts attrs (keyword list or map) to a map using the given key mapping.
Raises ArgumentError with a clear message if an unknown key is passed.
Examples
iex> Bunnyx.Params.map_keys!([name: "test"], %{name: "Name"})
%{"Name" => "test"}
iex> Bunnyx.Params.map_keys!(%{name: "test"}, %{name: "Name"})
%{"Name" => "test"}
iex> Bunnyx.Params.map_keys!([bad: "x"], %{name: "Name"})
** (ArgumentError) unknown key :bad. Valid keys: [:name]
Puts a key-value pair into a keyword list only if the value is not nil.
Puts a key-value pair into a map only if the value is not nil.