diff options
author | Samuel Seay <sam@manuka.co> | 2016-09-05 20:20:54 +1200 |
---|---|---|
committer | Samuel Seay <sam@manuka.co> | 2016-09-05 20:20:54 +1200 |
commit | a3a1fa993d09f23619a6605bce7d3e0824ba096c (patch) | |
tree | e160e65c649f084b2ad7ac70af6cd8ea89415ece /lib/recaptcha/http.ex | |
parent | ba60e34e37848b4b7ee49f26789664c095baeb6d (diff) | |
download | recaptcha-a3a1fa993d09f23619a6605bce7d3e0824ba096c.tar.gz recaptcha-a3a1fa993d09f23619a6605bce7d3e0824ba096c.tar.xz |
Add strict credo checks to build, fix line length issues.
Diffstat (limited to 'lib/recaptcha/http.ex')
-rw-r--r-- | lib/recaptcha/http.ex | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/recaptcha/http.ex b/lib/recaptcha/http.ex index 01c088a..0182a7c 100644 --- a/lib/recaptcha/http.ex +++ b/lib/recaptcha/http.ex @@ -2,14 +2,18 @@ defmodule Recaptcha.Http do @moduledoc """ Responsible for managing HTTP requests to the reCAPTCHA API """ - @headers [{"Content-type", "application/x-www-form-urlencoded"}, {"Accept", "application/json"}] + @headers [ + {"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. - See the [documentation](https://developers.google.com/recaptcha/docs/verify#api-response) for more details on the API response. + See the [docs](https://developers.google.com/recaptcha/docs/verify#api-response) + for more details on the API response. ## Options @@ -17,12 +21,22 @@ defmodule Recaptcha.Http do ## Example - {:ok, %{ "success" => success, "challenge_ts" => ts, "hostname" => host, "error-codes" => errors}} = Recaptcha.Http.request_verification(%{ secret: "secret", response: "response", remote_ip: "remote_ip"}) + {:ok, %{ + "success" => success, + "challenge_ts" => ts, + "hostname" => host, + "error-codes" => errors + }} = Recaptcha.Http.request_verification(%{ + secret: "secret", + response: "response", + remote_ip: "remote_ip" + }) """ @spec request_verification(map, [timeout: integer]) :: {:ok, map} | {:error, [atom]} def request_verification(body, options \\ []) do + timeout = options[:timeout] || @timeout result = - with {:ok, response} <- HTTPoison.post(@url, body, @headers, timeout: options[:timeout] || @timeout), + with {:ok, response} <- HTTPoison.post(@url, body, @headers, timeout: timeout), {:ok, data} <- Poison.decode(response.body) do {:ok, data} end |