Last active
August 11, 2017 03:00
-
-
Save caalberts/30c9fd1fd320c68adc2476920a151a07 to your computer and use it in GitHub Desktop.
Elixir lunch & learn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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