diff options
author | Mentor Ágil <mentoragil@gmail.com> | 2015-05-12 22:11:49 -0300 |
---|---|---|
committer | Mentor Ágil <mentoragil@gmail.com> | 2015-05-12 22:11:49 -0300 |
commit | 765438c4c2c300f84364b978a0b199a0e69c4e80 (patch) | |
tree | 8641ea4d3910a28fa8c702ee057251ce2d751abe /lib/httpclient.ex | |
download | mailchimp-765438c4c2c300f84364b978a0b199a0e69c4e80.tar.gz mailchimp-765438c4c2c300f84364b978a0b199a0e69c4e80.tar.xz |
first commit
Diffstat (limited to 'lib/httpclient.ex')
-rw-r--r-- | lib/httpclient.ex | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/httpclient.ex b/lib/httpclient.ex new file mode 100644 index 0000000..b5d0f1e --- /dev/null +++ b/lib/httpclient.ex @@ -0,0 +1,20 @@ +defmodule Mailchimp.HTTPClient do + + def get(url, header) do + case HTTPoison.get(url, header) do + {:ok, %HTTPoison.Response{status_code: 200, body: body}} -> + process_response_body body + {:ok, %HTTPoison.Response{status_code: 404}} -> + "Not found :(" + {:error, %HTTPoison.Error{reason: reason}} -> + reason + end + end + + def process_response_body(body) do + body + |> Poison.decode! + |> Enum.map(fn({k, v}) -> {String.to_atom(k), v} end) + end + +end |