Thanks @Jacek,
It worked, just pasting the code below for future reference if someone get stuck here.
def make_request(path, params) do
url = construct_url(path, params)
headers = [
{"Accept-Encoding","gzip, deflate"},{"Content-Type", "application/json"}
]
case HTTPoison.get(url, headers) do
{:ok, %HTTPoison.Response{status_code: 200, headers: resp_headers, body: body}} ->
resp_headers
|> check_if_gzipped
|> unzip_body(body)
|> decode_body
{:ok, %HTTPoison.Response{status_code: status_code }} ->
{:error, status_code}
{:error, error} -> {:error, error}
end
end
def check_if_gzipped(headers) do
Enum.any?(headers, fn (kv) ->
case kv do
{"Content-Encoding", "gzip"} -> true
{"content-encoding", "gzip"} -> true
{"Content-Encoding", "x-gzip"} -> true
_ -> false
end
end)
end
def decode_body(body) do
case Poison.decode(body) do
{:ok, decoded} -> {:ok, decoded}
{:error, error} ->{:error, error}
end
end
def unzip_body(true, body), do: :zlib.gunzip(body)
def unzip_body(false, body), do: body
defp construct_url(path, params) do
path <> params
end






















