Skip to content

Instantly share code, notes, and snippets.

@deadkarma
Last active May 2, 2016 17:51
Show Gist options
  • Save deadkarma/0c4033b9bb3bed530707ca3e94f9d5c8 to your computer and use it in GitHub Desktop.
Save deadkarma/0c4033b9bb3bed530707ca3e94f9d5c8 to your computer and use it in GitHub Desktop.
Elixir module for briteverify
defmodule BriteVerify do
@briteverify_api "https://bpi.briteverify.com/emails.json"
def verify(email) do
parent = self()
{:ok, _pid} = Task.start fn ->
send parent, verify_task(email)
end
receive do
result -> result
after
10000 -> :timeout
end
end
def verify_task(email) do
email
|> build_url
|> HTTPoison.get!(%{}, timeout: 20000, recv_timeout: 12000)
|> Map.fetch!(:body)
|> Poison.decode!
|> Map.fetch!("status")
end
def build_url(email) do
@briteverify_api <> "?" <> URI.encode_query(%{address: email, apikey: apikey})
end
def apikey do
Application.get_env(:your_app, :briteverify)[:api_key]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment