Hash :
2e8a3d5b
Author :
Date :
2016-02-18T09:27:48
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
defmodule ExOvh.Ovh.OvhApi.Request do
@moduledoc :false
alias ExOvh.Ovh.OvhApi.Auth
alias ExOvh.Ovh.OvhApi.Cache
alias ExOvh.Ovh.Defaults
############################
# Public
############################
@spec request(client :: atom, query :: ExOvh.Client.query_t, opts :: map)
:: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
def request(client, {method, uri, params} = query, opts) do
Og.context(__ENV__, :debug)
config = config(client)
{method, uri, options} = Auth.prepare_request(client, query)
|> Og.log_return(:debug)
resp = HTTPotion.request(method, uri, options)
if resp.status_code >= 100 and resp.status_code < 300 do
{:ok, %{
body: resp.body |> Poison.decode!(),
headers: resp.headers,
status_code: resp.status_code
}
}
else
{:error, resp}
end
end
############################
# Private
############################
defp config(client), do: Cache.get_config(client)
end