Commit 8b1e9e75d0e2b21366889b04d138f2f6017bf35a

Stephen Moloney 2016-02-14T17:38:15

improve query docs

diff --git a/lib/hubic/hubic_api/request.ex b/lib/hubic/hubic_api/request.ex
index 5cfd436..fba7ac6 100644
--- a/lib/hubic/hubic_api/request.ex
+++ b/lib/hubic/hubic_api/request.ex
@@ -6,6 +6,7 @@ defmodule ExOvh.Hubic.HubicApi.Request do
 
   @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, opts, retries \\ 0) do
     {method, uri, options} = Auth.prepare_request(client, query)
     LoggingUtils.log_return({method, uri, options}, :debug)
@@ -32,7 +33,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, opts, 1) # Try request one more time
+          unless retries >= 1, do: request(client, query, opts, 1) # Try request one more time
         else
           {:error, resp}
         end
diff --git a/lib/hubic/openstack_api/cache.ex b/lib/hubic/openstack_api/cache.ex
index d1fa358..94b7344 100644
--- a/lib/hubic/openstack_api/cache.ex
+++ b/lib/hubic/openstack_api/cache.ex
@@ -5,7 +5,7 @@ defmodule ExOvh.Hubic.OpenstackApi.Cache do
   alias ExOvh.Hubic.Request
   @get_credentials_retries 10
   @get_credentials_sleep_interval 150
-  @init_delay 3_000
+  @init_delay 2_000
 
 
   #####################
@@ -62,7 +62,7 @@ defmodule ExOvh.Hubic.OpenstackApi.Cache do
     token = Cache.get_token(client)
     :timer.sleep(@init_delay) # give some time for TokenCache Genserver to initialize
     create_ets_table(client)
-    {:ok, resp} = Request.request(client, {:get, "/account/credentials", ""}, %{})
+    {:ok, resp} = Request.request(client, {:get, "/account/credentials", :nil}, %{})
     |> LoggingUtils.log_return(:debug)
     credentials = Map.put(resp.body, :lock, :false)
     :ets.insert(ets_tablename(client), {:credentials, credentials})
diff --git a/lib/hubic/request.ex b/lib/hubic/request.ex
index 9e0f115..4d1b00b 100644
--- a/lib/hubic/request.ex
+++ b/lib/hubic/request.ex
@@ -30,7 +30,7 @@ defmodule ExOvh.Hubic.Request do
   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: Hub
+  alias ExOvh.Hubic.HubicApi.Request, as: Hubic
   alias ExOvh.Hubic.OpenstackApi.Request, as: Open
 
 
@@ -58,7 +58,7 @@ defmodule ExOvh.Hubic.Request do
   end
 
   def request(client, {method, uri, params} = query, opts) do
-    Hub.request(client, query)
+    Hubic.request(client, query, opts)
   end
 
 
diff --git a/lib/hubic/request_helpers.ex b/lib/hubic/request_helpers.ex
index 9ed8a82..18c4afc 100644
--- a/lib/hubic/request_helpers.ex
+++ b/lib/hubic/request_helpers.ex
@@ -1,4 +1,7 @@
 defmodule ExOvh.Hubic.RequestHelpers do
+  @moduledoc ~S"""
+  Helper functions for making requests to the hubic custom api and hubic openstack api.
+  """
   import ExOvh.Query.Openstack.Swift
   alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
 
@@ -12,11 +15,9 @@ defmodule ExOvh.Hubic.RequestHelpers do
 
   ## Example
 
-      ```elixir
       alias ExOvh.Hubic.RequestHelpers
       client = ExOvh # Enter your client here
       RequestHelpers.containers(client)
-      ```
   """
   @spec containers(client :: atom)
                    :: {:ok, [String.t]} | {:error, ExOvh.Client.response_t}
@@ -42,13 +43,18 @@ defmodule ExOvh.Hubic.RequestHelpers do
 
   ## Example
 
-      ```elixir
       alias ExOvh.Hubic.RequestHelpers
       client = ExOvh
       container = "new_container"
       RequestHelpers.get_objects(client, container, :name)
+
+
+  ## Example
+
+      alias ExOvh.Hubic.RequestHelpers
+      client = ExOvh
+      container = "new_container"
       RequestHelpers.get_objects(client, container, :hash)
-      ```
   """
   @spec get_objects(client :: atom, container :: String.t, filter :: atom)
                    :: {:ok, [String.t]} | {:error, ExOvh.Client.response_t}
diff --git a/lib/mix/tasks/hubic.ex b/lib/mix/tasks/hubic.ex
index e59e9e7..8755faa 100644
--- a/lib/mix/tasks/hubic.ex
+++ b/lib/mix/tasks/hubic.ex
@@ -171,7 +171,7 @@ defmodule Mix.Tasks.Hubic do
 
   #- Adds the refresh_token to the opts_map
   @spec get_refresh_token(opts_map :: map) :: map
-  def get_refresh_token(opts_map) do
+  defp get_refresh_token(opts_map) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
     auth_credentials = opts_map.client_id <> ":" <> opts_map.client_secret
     auth_credentials_base64 = Base.encode64(auth_credentials)
diff --git a/lib/mix/tasks/ovh.ex b/lib/mix/tasks/ovh.ex
index d03848c..05f68b0 100644
--- a/lib/mix/tasks/ovh.ex
+++ b/lib/mix/tasks/ovh.ex
@@ -221,7 +221,7 @@ defmodule Mix.Tasks.Ovh do
   defp get_application_key(body), do: Map.get(extract(body), "key")
   defp get_application_name(body), do: Map.get(extract(body), "name")
   defp get_application_description(body), do: Map.get(extract(body), "description")
-  def extract(body) do
+  defp extract(body) do
     Floki.find(body, "pre")
     |> Enum.map(fn({"pre", [], [val]}) -> val end)
     |> Enum.map(fn(ext) ->
diff --git a/lib/ovh/request.ex b/lib/ovh/request.ex
index 8a541b8..4a6e8d4 100644
--- a/lib/ovh/request.ex
+++ b/lib/ovh/request.ex
@@ -60,7 +60,7 @@ defmodule ExOvh.Ovh.Request do
   end
 
   def request(client, {method, uri, params} = query, opts) do
-    Ovh.request(client, query)
+    Ovh.request(client, query, opts)
   end
 
 
diff --git a/lib/query/hubic/query.ex b/lib/query/hubic/query.ex
index 2a35b2e..4ecb55f 100644
--- a/lib/query/hubic/query.ex
+++ b/lib/query/hubic/query.ex
@@ -1,15 +1,13 @@
 defmodule ExOvh.Query.Hubic do
   @moduledoc ~S"""
-    Helps to build queries for the hubic api.
+  Helper functions for building queries for the hubic api.
 
-    The raw query can be passed into a client request.
+  The raw query can be passed into a client request.
 
     ## Example
 
-      ```elixir
       import ExOvh.Query.Hubic, only: [scope: 0]
       scope = ExOvh.hubic_request(scope())
-      ```
   """
 
 
@@ -17,6 +15,7 @@ defmodule ExOvh.Query.Hubic do
   # General Hubic Requests
   #########################
 
+
   @doc ~S"""
   GET /scope/scope, Get the possible scopes for hubiC API
 
diff --git a/lib/query/openstack/swift/query.ex b/lib/query/openstack/swift/query.ex
index 1f535f7..c99b7f7 100644
--- a/lib/query/openstack/swift/query.ex
+++ b/lib/query/openstack/swift/query.ex
@@ -1,16 +1,15 @@
 defmodule ExOvh.Query.Openstack.Swift do
   @moduledoc ~S"""
-  Helps to build queries for the openstack swift api.
+  Helper functions for to building queries for the openstack compatible swift apis.
+
   The raw query can be passed into a client request.
 
     ## Example
 
-      ```elixir
       import ExOvh.Query.Openstack.Swift, only: [scope: 0]
       account = ExOvh.Hubic.OpenstackApi.Cache.get_account()
       client = ExOvh
       scope = ExOvh.hubic_request(account_info(client), %{ openstack: : true })
-      ```
   """
   alias ExOvh.Hubic.OpenstackApi.Cache, as: HubicOpenstackCache
 
diff --git a/lib/query/ovh/webstorage/query.ex b/lib/query/ovh/webstorage/query.ex
index c3fd0fb..3a22bc8 100644
--- a/lib/query/ovh/webstorage/query.ex
+++ b/lib/query/ovh/webstorage/query.ex
@@ -1,13 +1,14 @@
 defmodule ExOvh.Query.Ovh.Webstorage do
   @moduledoc ~S"""
-  Helps to build queries for the openstack swift api.
+  Helper functions for to building queries to the `/cdn/webstorage` part of the custom ovh api.
+
   The raw query can be passed into a client request.
 
     ## Example
 
-      ```elixir
       import ExOvh.Query.Ovh.Webstorage
-      ```
+      query = get_all_webstorage()
+      ExOvh.ovh_request(query, %{})
   """
   alias ExOvh.Ovh.OvhApi.Cache, as: OvhApiCache
 
@@ -18,10 +19,8 @@ defmodule ExOvh.Query.Ovh.Webstorage do
 
   ### Example usage
 
-      ```elixir
       import ExOvh.Query.Ovh.Webstorage
       ExOvh.ovh_request(get_all_webstorage(), %{})
-      ```
   """
   @spec get_all_webstorage() :: ExOvh.Client.raw_query_t
   def get_all_webstorage(), do: {:get, "/cdn/webstorage", :nil}
@@ -33,7 +32,6 @@ defmodule ExOvh.Query.Ovh.Webstorage do
 
   ### Example usage
 
-      ```elixir
       import ExOvh.Query.Ovh.Webstorage
       service_name = "cdnwebstorage-????"
       resp = ExOvh.ovh_request(get_webstorage_service(service_name), %{})
@@ -42,7 +40,6 @@ defmodule ExOvh.Query.Ovh.Webstorage do
         "storageLimit => storage_limit,
         "server" => server
        } = resp.body
-      ```
   """
   @spec get_webstorage_service(service_name :: String.t)
                                :: ExOvh.Client.raw_query_t
@@ -55,11 +52,9 @@ defmodule ExOvh.Query.Ovh.Webstorage do
 
   ### Example usage
 
-      ```elixir
       import ExOvh.Query.Ovh.Webstorage
       service_name = "cdnwebstorage-????"
       resp = ExOvh.ovh_request(get_webstorage_service_info(service_name), %{})
-      ```
   """
   @spec get_webstorage_service_info(service_name :: String.t)
                                :: ExOvh.Client.raw_query_t
@@ -75,11 +70,9 @@ defmodule ExOvh.Query.Ovh.Webstorage do
 
   ### Example usage
 
-      ```elixir
       import ExOvh.Query.Ovh.Webstorage
       # service_name = "cdnwebstorage-????"
       resp = ExOvh.ovh_request(get_webstorage_service_stats(service_name, "month", "backend"), %{})
-      ```
   """
   @spec get_webstorage_service_stats(service_name :: String.t, period :: String.t, type :: String.t)
                                :: ExOvh.Client.raw_query_t
@@ -94,11 +87,9 @@ defmodule ExOvh.Query.Ovh.Webstorage do
 
   ### Example usage
 
-      ```elixir
       import ExOvh.Query.Ovh.Webstorage
       # service_name = "cdnwebstorage-????"
       resp = ExOvh.ovh_request(get_webstorage_credentials(service_name), %{})
-      ```
   """
   @spec get_webstorage_credentials(service_name :: String.t)
                                :: ExOvh.Client.raw_query_t