7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/friendly_captcha/controller_helpers.rb', line 7
def verify_friendly_captcha(options = {})
response_token = friendly_captcha_response_token(options)
return { success: false, error: "No captcha response provided" } if response_token.empty?
result = FriendlyCaptcha::HttpCall.new.call(
url: options[:endpoint] || FriendlyCaptcha.config.verification_endpoint,
body: {
response: response_token,
sitekey: options[:sitekey] || FriendlyCaptcha.config.site_key
},
headers: {
'X-API-Key' => options[:api_key] || FriendlyCaptcha.config.api_key,
'Content-Type' => 'application/json'
}
)
case result
when FriendlyCaptcha::HttpCall::Success
status_code, response_body = result.value!
parse_verification_response(status_code, response_body)
when FriendlyCaptcha::HttpCall::Failure
handle_verification_failure(result.failure)
end
end
|