Lob. Util
(lob_elixir v1.6.0)
View Source
Module responsible for transforming arguments for requests.
Summary
Functions
Transforms a map to a tuple recognized by HTTPoison/hackney for use as a multipart request body.
Transforms a map to a list of tuples recognized by HTTPoison/hackeny for use as request headers.
Transforms a map of request params to a URL encoded query string.
Functions
Transforms a map to a tuple recognized by HTTPoison/hackney for use as a multipart request body.
Example
iex> {:multipart, parts} = Lob.Util.build_body(%{description: "body", to: %{name: "Larry", species: "Lobster"}, front: %{local_path: "a/b/c"}}) iex> Enum.member?(parts, {"description", "body"}) true iex> Enum.member?(parts, {"to[name]", "Larry"}) true iex> Enum.member?(parts, {"to[species]", "Lobster"}) true iex> Enum.member?(parts, {:file, "a/b/c", {"form-data", [name: "front", filename: "a/b/c"]}, []}) true
Transforms a map to a list of tuples recognized by HTTPoison/hackeny for use as request headers.
Example
iex> Lob.Util.build_headers(%{"Idempotency-Key" => "abc123", "Lob-Version" => "2017-11-08"}) [{"Idempotency-Key", "abc123"}, {"Lob-Version", "2017-11-08"}]
Transforms a map of request params to a URL encoded query string.
Example
iex> Lob.Util.build_query_string(%{count: 1, include: ["total_count"], metadata: %{name: "Larry"}}) "count=1&include%5B%5D=total_count&metadata%5Bname%5D=Larry"