aboutsummaryrefslogtreecommitdiff
path: root/lib/recaptcha
diff options
context:
space:
mode:
Diffstat (limited to 'lib/recaptcha')
-rw-r--r--lib/recaptcha/http.ex8
-rw-r--r--lib/recaptcha/template.ex4
2 files changed, 5 insertions, 7 deletions
diff --git a/lib/recaptcha/http.ex b/lib/recaptcha/http.ex
index 0182a7c..6d81b76 100644
--- a/lib/recaptcha/http.ex
+++ b/lib/recaptcha/http.ex
@@ -6,8 +6,6 @@ defmodule Recaptcha.Http do
{"Content-type", "application/x-www-form-urlencoded"},
{"Accept", "application/json"}
]
- @url Application.get_env(:recaptcha, :verify_url)
- @timeout Application.get_env(:recaptcha, :timeout, 5000)
@doc """
Sends an HTTP request to the reCAPTCHA version 2.0 API.
@@ -34,9 +32,11 @@ defmodule Recaptcha.Http do
"""
@spec request_verification(map, [timeout: integer]) :: {:ok, map} | {:error, [atom]}
def request_verification(body, options \\ []) do
- timeout = options[:timeout] || @timeout
+ timeout = options[:timeout] || Application.get_env(:recaptcha, :timeout, 5000)
+ url = Application.get_env(:recaptcha, :verify_url)
+
result =
- with {:ok, response} <- HTTPoison.post(@url, body, @headers, timeout: timeout),
+ with {:ok, response} <- HTTPoison.post(url, body, @headers, timeout: timeout),
{:ok, data} <- Poison.decode(response.body) do
{:ok, data}
end
diff --git a/lib/recaptcha/template.ex b/lib/recaptcha/template.ex
index 28db29c..008a63d 100644
--- a/lib/recaptcha/template.ex
+++ b/lib/recaptcha/template.ex
@@ -11,15 +11,13 @@ defmodule Recaptcha.Template do
EEx.function_from_file :defp, :render_template, "lib/template.html.eex", [:assigns]
- @public_key Application.get_env(:recaptcha, :public_key)
-
@doc """
Returns a string with reCAPTCHA code
To convert the string to html code, use Phoenix.HTML.Raw/1 method
"""
def display(options \\ []) do
- public_key = options[:public_key] || @public_key
+ public_key = options[:public_key] || Application.get_env(:recaptcha, :public_key)
render_template(public_key: public_key, options: options)
end
end