Packages

A wrapper around Ngrok providing a secure tunnel to localhost for demoing your Elixir/Phoenix web application or testing webhook integrations.

Current section

8 Versions

Jump to

Compare versions

4 files changed
+26 additions
-12 deletions
  @@ -20,4 +20,4 @@
20 20 {<<"name">>,<<"poison">>},
21 21 {<<"optional">>,false},
22 22 {<<"requirement">>,<<"~> 2.0">>}]]}.
23 - {<<"version">>,<<"0.2.0">>}.
23 + {<<"version">>,<<"0.2.1">>}.
  @@ -9,10 +9,10 @@ defmodule Ngrok.Api do
9 9
10 10 @spec first_tunnel_settings() :: error | successful_parse
11 11 def first_tunnel_settings do
12 - with api_url = Application.get_env(:ex_ngrok, :api_url, "http://localhost:4040/api/tunnels"),
12 + with api_url = Application.get_env(:ex_ngrok, :api_url),
13 13 {:ok, body} <- get(api_url),
14 14 {:ok, parsed} <- parse(body) do
15 - first_tunnel(parsed)
15 + find_tunnel(parsed)
16 16 end
17 17 end
18 18
  @@ -41,14 +41,21 @@ defmodule Ngrok.Api do
41 41 end
42 42 end
43 43
44 - @spec first_tunnel(map) :: error | successful_parse
45 - defp first_tunnel(parsed) do
46 - case List.first(Map.fetch!(parsed, "tunnels")) do
44 + @spec find_tunnel(map) :: error | successful_parse
45 + defp find_tunnel(parsed) do
46 + tunnels = Map.fetch!(parsed, "tunnels")
47 + protocol = Application.get_env(:ex_ngrok, :protocol)
48 + case Enum.find(tunnels, &tunnel_for_protocol(&1, protocol)) do
47 49 nil ->
48 - {:error, "No Ngrok tunnels found"}
50 + {:error, "No Ngrok tunnels found for protocol: #{protocol}"}
49 51
50 52 tunnel ->
51 53 {:ok, tunnel}
52 54 end
53 55 end
56 +
57 + @spec tunnel_for_protocol(map, String.t) :: boolean
58 + defp tunnel_for_protocol(tunnel, protocol) do
59 + Map.fetch!(tunnel, "proto") == protocol
60 + end
54 61 end
  @@ -19,10 +19,10 @@ defmodule Ngrok.Executable do
19 19 @spec ngrok :: String.t
20 20 defp ngrok do
21 21 arguments = [
22 - Application.get_env(:ex_ngrok, :executable, "ngrok"),
23 - Application.get_env(:ex_ngrok, :protocol, "http"),
24 - Application.get_env(:ex_ngrok, :port, "4000"),
25 - Application.get_env(:ex_ngrok, :options, ""),
22 + Application.get_env(:ex_ngrok, :executable),
23 + Application.get_env(:ex_ngrok, :protocol),
24 + Application.get_env(:ex_ngrok, :port),
25 + Application.get_env(:ex_ngrok, :options),
26 26 ]
27 27 Enum.join(arguments, " ")
28 28 end
  @@ -3,7 +3,7 @@ defmodule Ngrok.Mixfile do
3 3
4 4 def project do
5 5 [app: :ex_ngrok,
6 - version: "0.2.0",
6 + version: "0.2.1",
7 7 elixir: "~> 1.3",
8 8 build_embedded: Mix.env == :prod,
9 9 start_permanent: Mix.env == :prod,
  @@ -15,6 +15,13 @@ defmodule Ngrok.Mixfile do
15 15
16 16 def application do
17 17 [applications: [:logger, :httpoison],
18 + env: [
19 + api_url: "http://localhost:4040/api/tunnels",
20 + executable: "ngrok",
21 + protocol: "http",
22 + port: "4000",
23 + options: "",
24 + ],
18 25 mod: {Ngrok, []}]
19 26 end