Skip to content

Instantly share code, notes, and snippets.

@caalberts
Last active August 11, 2017 03:00
Show Gist options
  • Save caalberts/30c9fd1fd320c68adc2476920a151a07 to your computer and use it in GitHub Desktop.
Save caalberts/30c9fd1fd320c68adc2476920a151a07 to your computer and use it in GitHub Desktop.
Elixir lunch & learn
case HTTPoison.get(url, headers) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
case Poison.decode(body) do
{:ok, decoded} -> {:ok, decoded}
{:error, error} -> {:error, error}
end
{:ok, %HTTPoison.Response{status_code: status_code}} ->
{:error, status_code}
{:error, error} ->
{:error, error}
end
def process_response_body(body) do
body
|> Poison.decode!
|> Map.take(@expected_fields)
|> Enum.map(fn({k, v}) -> {String.to_atom(k), v} end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment