mailgun_ex v0.2.2 MailgunEx.Content View Source

Transform, decode and analyze raw encoded content based on it’s type (e.g. decode a raw JSON string into an Elixir map)

Link to this section Summary

Functions

Decode the response body

Extract the content type of the headers

Link to this section Functions

Decode the response body

Examples

iex> MailgunEx.Content.decode({:ok, "{\"a\": 1}", "application/json"})
{:ok, %{a: 1}}

iex> MailgunEx.Content.decode({500, "", "application/json"})
{500, ""}

iex> MailgunEx.Content.decode({:error, "{\"a\": 1}", "application/json"})
{:error, %{a: 1}}

iex> MailgunEx.Content.decode({:ok, "{goop}", "application/json"})
{:error, "{goop}"}

iex> MailgunEx.Content.decode({:error, "{goop}", "application/json"})
{:error, "{goop}"}

iex> MailgunEx.Content.decode({:error, :nxdomain, "application/dontcare"})
{:error, :nxdomain}

Extract the content type of the headers

Examples

iex> MailgunEx.Content.type({:ok, "<xml />", [{"Server", "GitHub.com"}, {"Content-Type", "application/xml; charset=utf-8"}]})
{:ok, "<xml />", "application/xml"}

iex> MailgunEx.Content.type([])
"application/json"

iex> MailgunEx.Content.type([{"Content-Type", "plain/text"}])
"plain/text"

iex> MailgunEx.Content.type([{"Content-Type", "application/xml; charset=utf-8"}])
"application/xml"

iex> MailgunEx.Content.type([{"Server", "GitHub.com"}, {"Content-Type", "application/xml; charset=utf-8"}])
"application/xml"