Hash :
be9913b0
Author :
Date :
2016-02-14T18:39:35
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
defmodule ExOvh.Hubic.Request do
@moduledoc :false
@doc ~S"""
Houses the `request` function which delegates the function call to the appropriate
module & function depending on the `opts` key-values.
Hubic uses it's own custom api and also separate Openstack compliant apis so
and these apis are quite different.
Therefore, the request needs to be routed to the correct `request` function so
that the correct auth credentials are put into the `options_t` in the returned
`ExOvh.Client.query_t` query tuple.
## Examples of what some delegation depending on opts
ExOvh.hubic_request(query, %{} = opts)
calls
ExOvh.Hubic.HubicApi.Request.request(ExOvh, query, opts)
-
ExOvh.hubic_request(query, %{ openstack: :true } = opts)
calls
ExOvh.Hubic.OpenstackApi.Request.request(ExOvh, query, opts)
## Subsequent Request modules
The subsequent request functions process the request by
1. Calling the appropriate `prepare_request` function which has been delegated to.
2. Making the actual request with `HTTPotion`
3. Returning the response as `{:ok, response_t}` or `{:error, response_t}`
"""
alias ExOvh.Hubic.HubicApi.Request, as: Hubic
alias ExOvh.Hubic.OpenstackApi.Request, as: Open
@doc ~S"""
Delegates the function call to the appropriate module & function depending on the `opts` key-values.
Subsequent request functions return `{:ok, response_t}` or `{:error, response_t}`
## Options
{ } = opts
The function call will be delegated to `ExOvh.Hubic.HubicApi.Request` and processed as a hubic api request.
{ openstack: :true } = opts
The function call will be delegated to `ExOvh.Hubic.OpenstackApi.Request`.
`openstack: :true` - boolean - indicates whether the request is an openstack one or not.
"""
@spec request(client :: atom, query :: ExOvh.Client.raw_query_t, opts :: map)
:: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
def request(client, {method, uri, params} = query, %{ openstack: :true } = opts) do
Open.request(client, query, opts)
end
def request(client, {method, uri, params} = query, opts) do
Hubic.request(client, query, opts)
end
end