Last active
May 2, 2016 17:51
-
-
Save deadkarma/0c4033b9bb3bed530707ca3e94f9d5c8 to your computer and use it in GitHub Desktop.
Elixir module for briteverify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
|> 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