Hash :
8c0d1730
Author :
Date :
2016-02-11T00:54:30
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 44 45
defmodule ExOvh.Hubic.OpenstackApi.Auth do
alias ExOvh.Hubic.OpenstackApi.Cache
@methods [:get, :post, :put, :delete]
@timeout 10_000
############################
# Public
############################
@spec prepare_request(query :: ExOvh.Client.raw_query_t)
:: ExOvh.Client.query_t
def prepare_request({method, uri, params} = query), do: prepare_request(ExOvh, query)
@spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t)
:: ExOvh.Client.query_t
def prepare_request(client, query)
def prepare_request(client, {method, uri, params} = query) when method in [:get, :delete] do
uri = Cache.get_endpoint(client) <> uri
if params !== :nil and params !== "", do: uri = uri <> "?" <> URI.encode_query(params)
options = %{ headers: headers(client), timeout: @timeout }
{method, uri, options}
end
def prepare_request(client, {method, uri, params} = query) when method in [:post, :put] do
uri = Cache.get_endpoint(client) <> uri
if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
options = %{ body: params, headers: headers(client), timeout: @timeout }
{method, uri, options}
end
############################
# Private
############################
defp headers(client), do: %{ "X-Auth-Token": Cache.get_credentials_token(client) }
end