improve docs for the Request.request/3 and Auth.prepare_request/3 functions
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
diff --git a/lib/hubic/auth.ex b/lib/hubic/auth.ex
index cfa030d..8053e00 100644
--- a/lib/hubic/auth.ex
+++ b/lib/hubic/auth.ex
@@ -1,35 +1,68 @@
defmodule ExOvh.Hubic.Auth do
@moduledoc ~S"""
- Delegates the prepare_request to the appropriate module and function
- depending on the opts specified.
- `%{ openstack: :true }` ==> delegates the query to the OpenstackApi.Auth Module
- `%{ }` ==> delegates the query to the HubicApi.Auth Module
+ Houses the `prepare_request` function which delegates the function call to the appropriate
+ module & function depending on the `opts` key-values.
+
+ Ovh 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 `prepare_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_prepare_request(query, %{} = opts)
+ calls
+ ExOvh.Hubic.HubicApi.Auth.hubic_prepare_request(ExOvh, query, opts)
+
+ -
+
+ ExOvh.hubic_prepare_request(query, %{ openstack: :true } = opts)
+ calls
+ ExOvh.Hubic.OpenstackApi.Auth.hubic_prepare_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. Getting the appropriate auth credentials and adding them to the headers as needed.
+ 3. Returning `ExOvh.Client.query_t` which is a tuple of the format {method, uri, options} which
+ can then be easily used to make requests using HTTPpotion, `ovh_request` or `hubic_request`.
"""
alias ExOvh.Hubic.OpenstackApi.Auth, as: OpenstackAuth
alias ExOvh.Hubic.HubicApi.Auth, as: HubicAuth
- ############################
- # Public
- ############################
+ @doc ~S"""
+ Delegates the function call to the appropriate module & function depending on the `opts` key-values.
- @spec prepare_request(query :: ExOvh.Client.raw_query_t, opts :: map())
- :: ExOvh.Client.query_t
- def prepare_request({method, uri, params} = query, opts), do: prepare_request(ExOvh, query, opts)
+ Subsequent request functions return `{:ok, response_t}` or `{:error, response_t}`
+ ## Options
+
+ { } = opts
+
+ The function call will be delegated to `ExOvh.Hubic.HubicApi.Auth`.
+
+ { openstack: :true, webstorage: "<service>" } = opts
+
+ The function call will be delegated to `ExOvh.Hubic.HubicApi.Webstorage.Auth`.
+
+ `openstack: :true` - boolean - indicates whether the request is an openstack one or not.
+
+ `webstorage: service` - String.t and is the name the cdn webstorage in your ovh stack which you which to use.
+ """
@spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t, opts :: map())
:: ExOvh.Client.query_t
def prepare_request(client, {method, uri, params} = query, %{openstack: :true} = opts) do
OpenstackAuth.prepare_request(client, query)
end
+
def prepare_request(client, {method, uri, params} = query, opts) do
HubicAuth.prepare_request(client, query)
end
- ############################
- # Private
- ############################
-
-
end
diff --git a/lib/hubic/hubic_api/request.ex b/lib/hubic/hubic_api/request.ex
index d370bdf..5cfd436 100644
--- a/lib/hubic/hubic_api/request.ex
+++ b/lib/hubic/hubic_api/request.ex
@@ -4,9 +4,9 @@ defmodule ExOvh.Hubic.HubicApi.Request do
alias ExOvh.Hubic.HubicApi.Cache, as: TokenCache
- @spec request(client :: atom, query :: ExOvh.Client.raw_query_t, retries :: integer)
+ @spec request(client :: atom, query :: ExOvh.Client.raw_query_t, opts :: map, retries :: integer)
:: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
- def request(client, {method, uri, params} = query, retries \\ 0) do
+ def request(client, {method, uri, params} = query, opts, retries \\ 0) do
{method, uri, options} = Auth.prepare_request(client, query)
LoggingUtils.log_return({method, uri, options}, :debug)
resp = HTTPotion.request(method, uri, options)
@@ -32,7 +32,7 @@ defmodule ExOvh.Hubic.HubicApi.Request do
if Map.has_key?(resp.body, "error") do
if resp.body["error"] === "invalid_token" do
GenServer.call(TokenCache, :stop) # Restart the gen_server to recuperate state
- unless retries >= 1, do: request(query, 1) # Try request one more time
+ unless retries >= 1, do: request(query, opts, 1) # Try request one more time
else
{:error, resp}
end
diff --git a/lib/hubic/openstack_api/request.ex b/lib/hubic/openstack_api/request.ex
index 2b5d590..21af5f4 100644
--- a/lib/hubic/openstack_api/request.ex
+++ b/lib/hubic/openstack_api/request.ex
@@ -4,9 +4,9 @@ defmodule ExOvh.Hubic.OpenstackApi.Request do
alias ExOvh.Hubic.OpenstackApi.Auth
- @spec request(client :: atom, query :: ExOvh.Client.raw_query_t)
+ @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) do
+ def request(client, {method, uri, params} = query, opts) do
LoggingUtils.log_mod_func_line(__ENV__, :debug)
{method, uri, options} = Auth.prepare_request(client, query)
|> LoggingUtils.log_return(:debug)
diff --git a/lib/hubic/request.ex b/lib/hubic/request.ex
index a164262..9e0f115 100644
--- a/lib/hubic/request.ex
+++ b/lib/hubic/request.ex
@@ -1,26 +1,30 @@
defmodule ExOvh.Hubic.Request do
@moduledoc ~S"""
- Contains the `request` function which delegates the request
- to the correct module and functions depending on the parameters in `opts`.
+ 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 a distinct Openstack compliant api so
+ 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 `prepare_request` function so
+ 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.
- This module's request function delegates the query to the correct `prepare_request`
- function by pattern matching on the `opts` map.
+ ## Examples of what some delegation depending on opts
- ## Routing/Delegating depending on opts
+ ExOvh.hubic_request(query, %{} = opts)
+ calls
+ ExOvh.Hubic.HubicApi.Request.request(ExOvh, query, opts)
- `%{ }` -> `ExOvh.Hubic.HubicApi.Request`
+ -
+
+ ExOvh.hubic_request(query, %{ openstack: :true } = opts)
+ calls
+ ExOvh.Hubic.OpenstackApi.Request.request(ExOvh, query, opts)
- `%{ openstack: :true}` -> `ExOvh.Hubic.OpenstackApi.Request`
## Subsequent Request modules
- The subsequent request modules process the request by
+ 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`
@@ -31,7 +35,7 @@ defmodule ExOvh.Hubic.Request do
@doc ~S"""
- Redirects the query to the appropriate function dependeing on the `opts` key-values.
+ 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}`
@@ -39,11 +43,13 @@ defmodule ExOvh.Hubic.Request do
{ } = opts
- The request will be delegated to `ExOvh.Hubic.HubicApi.Request` and processed as a hubic api request.
+ The function call will be delegated to `ExOvh.Hubic.HubicApi.Request` and processed as a hubic api request.
{ openstack: :true } = opts
- The request will be delegated to `ExOvh.Hubic.OpenstackApi.Request` and processed as an openstack api request.
+ 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}
diff --git a/lib/ovh/auth.ex b/lib/ovh/auth.ex
index 7d0709b..abbb8ac 100644
--- a/lib/ovh/auth.ex
+++ b/lib/ovh/auth.ex
@@ -1,35 +1,68 @@
defmodule ExOvh.Ovh.Auth do
@moduledoc ~s"""
- Delegates the prepare_request to the appropriate module and function
- depending on the opts specified.
- `%{ openstack: :true }` ==> delegates the query to the OpenstackApi.Auth Module
- `%{ }` ==> delegates the query to the HubicApi.Auth Module
+ Houses the `prepare_request` function which delegates the function call to the appropriate
+ module & function depending on the `opts` key-values.
+
+ Ovh 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 `prepare_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.ovh_prepare_request(query, %{} = opts)
+ calls
+ ExOvh.Ovh.OvhApi.Auth.ovh_prepare_request(ExOvh, query, opts)
+
+ -
+
+ ExOvh.ovh_prepare_request(query, %{ openstack: :true, webstorage: "service_name" } = opts)
+ calls
+ ExOvh.Ovh.OpenstackApi.Webstorage.Auth.ovh_prepare_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. Getting the appropriate auth credentials and adding them to the headers as needed.
+ 3. Returning `ExOvh.Client.query_t` which is a tuple of the format {method, uri, options} which
+ can then be easily used to make requests using HTTPpotion, `ovh_request` or `hubic_request`.
"""
alias ExOvh.Ovh.Openstack.Auth, as: OpenstackAuth
alias ExOvh.Ovh.OvhApi.Auth, as: OvhAuth
- ############################
- # Public
- ############################
+ @doc ~S"""
+ Delegates the function call to the appropriate module & function depending on the `opts` key-values.
- @spec prepare_request(query :: ExOvh.Client.raw_query_t, opts :: map())
- :: ExOvh.Client.query_t
- def prepare_request({method, uri, params} = query, opts), do: prepare_request(ExOvh, query, opts)
+ Subsequent request functions return `{:ok, response_t}` or `{:error, response_t}`
+ ## Options
+
+ { } = opts
+
+ The function call will be delegated to `ExOvh.Ovh.OvhApi.Auth`.
+
+ { openstack: :true, webstorage: "<service>" } = opts
+
+ The function call will be delegated to `ExOvh.Ovh.OpenstackApi.Webstorage.Auth`.
+
+ `openstack: :true` - boolean - indicates whether the request is an openstack one or not.
+
+ `webstorage: service` - String.t and is the name the cdn webstorage in your ovh stack which you which to use.
+ """
@spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t, opts :: map())
:: ExOvh.Client.query_t
def prepare_request(client, {method, uri, params} = query, %{openstack: :true} = opts) do
OpenstackAuth.prepare_request(client, query)
end
+
def prepare_request(client, {method, uri, params} = query, opts) do
OvhAuth.prepare_request(client, query)
end
- ############################
- # Private
- ############################
-
-
end
diff --git a/lib/ovh/openstack_api/webstorage/request.ex b/lib/ovh/openstack_api/webstorage/request.ex
index 57233f9..01d9a6f 100644
--- a/lib/ovh/openstack_api/webstorage/request.ex
+++ b/lib/ovh/openstack_api/webstorage/request.ex
@@ -5,7 +5,7 @@ defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Request do
@spec request(client :: atom, query :: ExOvh.Client.query_t, service :: String.t)
:: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
- def request(client, {method, uri, params} = query, service) do
+ def request(client, {method, uri, params} = query, %{ webstorage: service } = opts) do
LoggingUtils.log_mod_func_line(__ENV__, :debug)
{method, uri, options} = Auth.prepare_request(client, query, service)
diff --git a/lib/ovh/ovh_api/request.ex b/lib/ovh/ovh_api/request.ex
index e3addfa..09b3b57 100644
--- a/lib/ovh/ovh_api/request.ex
+++ b/lib/ovh/ovh_api/request.ex
@@ -9,9 +9,9 @@ defmodule ExOvh.Ovh.OvhApi.Request do
############################
- @spec request(client :: atom, query :: ExOvh.Client.query_t)
+ @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) do
+ def request(client, {method, uri, params} = query, opts) do
LoggingUtils.log_mod_func_line(__ENV__, :debug)
config = config(client)
diff --git a/lib/ovh/request.ex b/lib/ovh/request.ex
index acf9ce0..8a541b8 100644
--- a/lib/ovh/request.ex
+++ b/lib/ovh/request.ex
@@ -1,26 +1,30 @@
defmodule ExOvh.Ovh.Request do
@moduledoc ~S"""
- Contains the `request` function which delegates the request
- to the correct module and functions depending on the parameters in `opts`.
+ Houses the `request` function which delegates the function call to the appropriate
+ module & function depending on the `opts` key-values.
Ovh 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 `prepare_request` function so
+ 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.
- This module's request function delegates the query to the correct `prepare_request`
- function by pattern matching on the `opts` map.
+ ## Examples of what some delegation depending on opts
- ## Routing/Delegating depending on opts
+ ExOvh.ovh_request(query, %{} = opts)
+ calls
+ ExOvh.Ovh.OvhApi.Request.request(ExOvh, query, opts)
- `%{ }` -> `ExOvh.Ovh.OvhApi.Request`
+ -
+
+ ExOvh.ovh_request(query, %{ openstack: :true, webstorage: "service_name" } = opts)
+ calls
+ ExOvh.Ovh.OpenstackApi.Webstorage.Request.request(ExOvh, query, opts)
- `%{ openstack: :true, webstorage: "service_name" }` -> `ExOvh.Ovh.OpenstackApi.Webstorage.Request`
## Subsequent Request modules
- The subsequent request modules process the request by
+ 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`
@@ -31,7 +35,7 @@ defmodule ExOvh.Ovh.Request do
@doc ~S"""
- Redirects the query to the appropriate function dependeing on the `opts` key-values.
+ 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}`
@@ -39,18 +43,20 @@ defmodule ExOvh.Ovh.Request do
{ } = opts
- The request will be delegated to `ExOvh.Ovh.OvhApi.Request` and processed as a hubic api request.
+ The function call will be delegated to `ExOvh.Ovh.OvhApi.Request` and processed as a hubic api request.
{ openstack: :true, webstorage: service } = opts
- The request will be delegated to `ExOvh.Ovh.OpenstackApi.Webstorage.Request`
- and processed as an openstack api request with the service value. The `service` value is a String.t
- and is the name the cdn webstorage in your ovh stack which you which to use.
+ The function call will be delegated to `ExOvh.Ovh.OpenstackApi.Webstorage.Request`.
+
+ `openstack: :true` - boolean - indicates whether the request is an openstack one or not.
+
+ `webstorage: service` - String.t and is the name the cdn webstorage in your ovh stack which you which to use.
"""
@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, webstorage: service } = opts) do
- Webstorage.request(client, query, service)
+ Webstorage.request(client, query, opts)
end
def request(client, {method, uri, params} = query, opts) do