aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Seay <sam@manuka.co>2016-09-05 20:57:27 +1200
committerSamuel Seay <sam@manuka.co>2016-09-05 20:57:27 +1200
commit29813771b6407683d2ad1c6a11ea0586add5dcd7 (patch)
tree642370dd2d0ca1e8a78d9d8a8bb0ec86d0607e0b
parentc5e266b8d151d74a6e53aa010b2cf6663ef8228c (diff)
downloadrecaptcha-29813771b6407683d2ad1c6a11ea0586add5dcd7.tar.gz
recaptcha-29813771b6407683d2ad1c6a11ea0586add5dcd7.tar.xz
Don't compile application environment config.
-rw-r--r--README.md2
-rw-r--r--lib/recaptcha.ex3
-rw-r--r--lib/recaptcha/http.ex8
-rw-r--r--lib/recaptcha/template.ex4
4 files changed, 7 insertions, 10 deletions
diff --git a/README.md b/README.md
index 68e8cfe..a86f8f4 100644
--- a/README.md
+++ b/README.md
@@ -57,7 +57,7 @@ Use `raw` (if you're using Phoenix.HTML) and `Recaptcha.Template.display/1` meth
```html
<form name="someform" method="post" action="/somewhere">
...
- <%= raw Recaptcha.display %>
+ <%= raw Recaptcha.Template.display %>
...
</form>
```
diff --git a/lib/recaptcha.ex b/lib/recaptcha.ex
index ed7e9b7..9e6be0f 100644
--- a/lib/recaptcha.ex
+++ b/lib/recaptcha.ex
@@ -5,7 +5,6 @@ defmodule Recaptcha do
See the [documentation](https://developers.google.com/recaptcha/docs/verify)
for more details.
"""
- @secret Application.get_env(:recaptcha, :secret)
@http_client Application.get_env(:recaptcha, :http_client, Recaptcha.Http)
@doc """
@@ -47,7 +46,7 @@ defmodule Recaptcha do
defp request_body(response, options) do
body_options = Keyword.take(options, [:remote_ip, :secret])
- application_options = [secret: @secret]
+ application_options = [secret: Application.get_env(:recaptcha, :secret)]
# override application secret with options secret if it exists
application_options
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