Current section
8 Versions
Jump to
Current section
8 Versions
Compare versions
4
files changed
+20
additions
-8
deletions
| @@ -17,7 +17,7 @@ by adding `nomad_client` to your list of dependencies in `mix.exs`: | |
| 17 17 | |
| 18 18 | ```elixir |
| 19 19 | def deps do |
| 20 | - [{:nomad_client, "~> 0.11.0"}] |
| 20 | + [{:nomad_client, "~> 0.12.1"}] |
| 21 21 | end |
| 22 22 | ``` |
| 23 23 | |
| @@ -30,9 +30,9 @@ First, you have to initiate the `Tesla.Env.Conn`. | |
| 30 30 | # Use Application defaults |
| 31 31 | conn = NomadClient.Connection.new() |
| 32 32 | # Differente URL, no ACL token |
| 33 | - conn = NomadClient.Connection.new("http://172.17.0.1:4646/v1") |
| 33 | + conn = NomadClient.Connection.new("http://172.17.0.1:4646") |
| 34 34 | # Custom URL with ACL token |
| 35 | - conn = NomadClient.Connection.new("http://172.17.0.1:4646/v1", "00000000-0000-0000-0000-000000000000") |
| 35 | + conn = NomadClient.Connection.new("http://172.17.0.1:4646", "00000000-0000-0000-0000-000000000000") |
| 36 36 | ``` |
| 37 37 | |
| 38 38 | After that, you can use your `conn` to make requests the api requests by using the API Modules. |
| @@ -212,4 +212,4 @@ | |
| 212 212 | {<<"optional">>,true}, |
| 213 213 | {<<"repository">>,<<"hexpm">>}, |
| 214 214 | {<<"requirement">>,<<"~> 1.0">>}]]}. |
| 215 | - {<<"version">>,<<"0.12.0">>}. |
| 215 | + {<<"version">>,<<"0.12.1">>}. |
| @@ -14,14 +14,14 @@ defmodule NomadClient.Connection do | |
| 14 14 | |
| 15 15 | ## Parameters |
| 16 16 | |
| 17 | - - url (String): Nomad URL Endpoint (including /v1) |
| 17 | + - url (String): Nomad URL Endpoint) |
| 18 18 | - token (String): ACL Token |
| 19 19 | |
| 20 20 | # Returns |
| 21 21 | |
| 22 22 | Tesla.Env.client |
| 23 23 | """ |
| 24 | - def new(url \\ "http://localhost:4646/v1", token \\ nil) |
| 24 | + def new(url \\ "http://localhost:4646", token \\ nil) |
| 25 25 | |
| 26 26 | def new(url, nil) do |
| 27 27 | Tesla.client(default_opts(url), default_adapter()) |
| @@ -38,13 +38,19 @@ defmodule NomadClient.Connection do | |
| 38 38 | end |
| 39 39 | |
| 40 40 | defp default_opts(url) do |
| 41 | + base_url = |
| 42 | + url |
| 43 | + |> URI.parse() |
| 44 | + |> maybe_fix_path() |
| 45 | + |> URI.to_string() |
| 46 | + |
| 41 47 | middleware = |
| 42 48 | :tesla |
| 43 49 | |> Application.get_env(__MODULE__, []) |
| 44 50 | |> Keyword.get(:middleware, []) |
| 45 51 | |
| 46 52 | [ |
| 47 | - {Tesla.Middleware.BaseUrl, url || "http://localhost:4646/v1"}, |
| 53 | + {Tesla.Middleware.BaseUrl, base_url}, |
| 48 54 | {Tesla.Middleware.Headers, [{"User-Agent", "Elixir"}]}, |
| 49 55 | {Tesla.Middleware.EncodeJson, [engine: Poison]} |
| 50 56 | | middleware |
| @@ -56,4 +62,10 @@ defmodule NomadClient.Connection do | |
| 56 62 | |> Application.get_env(__MODULE__, []) |
| 57 63 | |> Keyword.get(:adapter, nil) |
| 58 64 | end |
| 65 | + |
| 66 | + defp maybe_fix_path(%{path: path} = uri) when path in [nil, "/", ""] do |
| 67 | + %{uri | path: "/v1"} |
| 68 | + end |
| 69 | + |
| 70 | + defp maybe_fix_path(uri), do: uri |
| 59 71 | end |
| @@ -2,7 +2,7 @@ defmodule NomadClient.Mixfile do | |
| 2 2 | use Mix.Project |
| 3 3 | |
| 4 4 | @source_url "https://github.com/mrmstn/nomad_client" |
| 5 | - @version "0.12.0" |
| 5 | + @version "0.12.1" |
| 6 6 | |
| 7 7 | def project do |
| 8 8 | [ |