aboutsummaryrefslogtreecommitdiff
path: root/lib/exping.ex
diff options
context:
space:
mode:
authorkballou <kballou@devnulllabs.io>2016-07-28 16:44:32 -0600
committerkballou <kballou@devnulllabs.io>2016-07-29 11:36:04 -0600
commit1248eeb88d90f0ece972299d40b7406ef0a17cf5 (patch)
tree813c9c8c899a5752409641e47c4480f5e0308721 /lib/exping.ex
parent2175a2f4d9a416f4a443166a2487c8c12a3df9e2 (diff)
downloadexping-1248eeb88d90f0ece972299d40b7406ef0a17cf5.tar.gz
exping-1248eeb88d90f0ece972299d40b7406ef0a17cf5.tar.xz
Add HTTP "Ping"
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