adapting for adapters in openstex
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
diff --git a/config/config.exs b/config/config.exs
index 3c44b08..a8c4e27 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -1,6 +1,5 @@
use Mix.Config
-
config :logger,
backends: [:console],
level: :debug,
diff --git a/lib/ex_ovh/client.ex b/lib/ex_ovh/client.ex
index 49ad73e..745ba1e 100644
--- a/lib/ex_ovh/client.ex
+++ b/lib/ex_ovh/client.ex
@@ -1,5 +1,6 @@
defmodule ExOvh.Client do
@moduledoc Module.concat(__MODULE__, Docs).moduledoc()
+ alias ExOvh.{HttpQuery, Query, Response}
defmacro __using__(opts) do
quote bind_quoted: [opts: opts] do
@@ -7,21 +8,29 @@ defmodule ExOvh.Client do
alias ExOvh.{Defaults, HttpQuery, Query, Request, Response, ResponseError}
@behaviour ExOvh.Client
+ # public callback functions
- # public functions
-
- @doc :false
+ @doc "Starts the client supervision tree"
def start_link(sup_opts \\ []) do
- ExOvh.Supervisor.start_link(__MODULE__, sup_opts)
+ client = unquote(opts) |> Keyword.fetch!(:client)
+ ExOvh.Supervisor.start_link(client, sup_opts)
end
@doc "Gets all the application configuration settings"
@spec config() :: Keyword.t
def config() do
otp_app = unquote(opts) |> Keyword.fetch!(:otp_app)
+ client = unquote(opts) |> Keyword.fetch!(:client)
case otp_app do
:ex_ovh -> Application.get_all_env(otp_app)
- _ -> Application.get_env(otp_app, __MODULE__)
+ _ ->
+ case Application.get_env(otp_app, client) do
+ :nil ->
+ temp_client = Module.split(client) |> List.delete_at(-1) |> Enum.join()
+ temp_client = Module.concat(Elixir, temp_client)
+ Application.get_env(otp_app, temp_client)
+ config -> config
+ end
end
end
@@ -46,7 +55,7 @@ defmodule ExOvh.Client do
def httpoison_config() do
default_opts = [connect_timeout: 30000, receive_timeout: (60000 * 30)]
httpoison = Keyword.get(config(), :httpoison, default_opts)
- config()
+ httpoison
|> Keyword.put(:timeout, httpoison[:connect_timeout])
|> Keyword.put(:recv_timeout, httpoison[:receive_timeout])
|> Keyword.delete(:connect_timeout)
@@ -77,25 +86,48 @@ defmodule ExOvh.Client do
end
end
+# defoverridable [
+# ovh_config: 0,
+# httpoison_config: 0,
+# start_link: 0, start_link: 1,
+# request: 1, request: 2,
+# request!: 1, request!: 2,
+# prepare_request: 1, prepare_request: 2
+# ]
+
defoverridable [
- start_link: 0,
ovh_config: 0,
httpoison_config: 0,
+ start_link: 1,
request: 2,
request!: 2,
prepare_request: 2
]
+
end
end
- @callback start_link() :: {:ok, pid} | {:error, atom}
+# @callback start_link() :: {:ok, pid} | {:error, atom}
+# @callback start_link(sup_opts :: list) :: {:ok, pid} | {:error, atom}
+# @callback ovh_config() :: Keyword.t
+# @callback httpoison_config() :: Keyword.t
+# @callback prepare_request(query :: Query.t) :: Query.t | no_return
+# @callback prepare_request(query :: Query.t, httpoison_opts :: Keyword.t) :: Query.t | no_return
+# @callback request(query :: Query.t | HttpQuery.t) :: {:ok, Response.t} | {:error, Response.t}
+# @callback request(query :: Query.t | HttpQuery.t, httpoison_opts :: Keyword.t) :: {:ok, Response.t} | {:error, Response.t}
+# @callback request!(query :: Query.t | HttpQuery.t) :: {:ok, Response.t} | no_return
+# @callback request!(query :: Query.t | HttpQuery.t, httpoison_opts :: Keyword.t) :: {:ok, Response.t} | no_return
+
+
+ @callback start_link(sup_opts :: list) :: {:ok, pid} | {:error, atom}
@callback ovh_config() :: Keyword.t
@callback httpoison_config() :: Keyword.t
- @callback prepare_request(query :: map, httpoison_opts :: Keyword.t) :: Query.t | no_return
- @callback request(query :: map, httpoison_opts :: Keyword.t) :: {:ok, Response.t} | {:error, Response.t}
- @callback request!(query :: map, httpoison_opts :: Keyword.t) :: {:ok, Response.t} | no_return
+ @callback prepare_request(query :: Query.t, httpoison_opts :: Keyword.t) :: Query.t | no_return
+ @callback request(query :: Query.t | HttpQuery.t, httpoison_opts :: Keyword.t) :: {:ok, Response.t} | {:error, Response.t}
+ @callback request!(query :: Query.t | HttpQuery.t, httpoison_opts :: Keyword.t) :: {:ok, Response.t} | no_return
+
end
\ No newline at end of file