aboutsummaryrefslogtreecommitdiff
path: root/lib/exping.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/exping.ex')
-rw-r--r--lib/exping.ex20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/exping.ex b/lib/exping.ex
index 056bfda..c63c37a 100644
--- a/lib/exping.ex
+++ b/lib/exping.ex
@@ -1,5 +1,25 @@
defmodule ExPing do
+ require Logger
@moduledoc """
Public API for ExPing
"""
+
+ @pings [&ExPing.HTTP.get/1, &ExPing.HTTP.head/1]
+
+ @spec ping(URI.t) :: boolean
+ def ping(address) do
+ :ok = Logger.info("Attempting to ping #{inspect(address)}")
+ @pings
+ |> Enum.map(&spawn_ping(&1, address))
+ |> Enum.all?
+ end
+
+ @spec spawn_ping(fun, URI.t) :: boolean
+ defp spawn_ping(ping, address) do
+ case ping.(address) do
+ {:ok, _} -> true
+ {:error, _} -> false
+ end
+ end
+
end