Class: Locomotive::Steam::RecaptchaService
- Inherits:
-
Object
- Object
- Locomotive::Steam::RecaptchaService
- Defined in:
- lib/locomotive/steam/services/recaptcha_service.rb
Overview
This service supports Google Recaptcha or any API compatible with Google
Constant Summary collapse
- GOOGLE_API_URL =
'https://www.google.com/recaptcha/api/siteverify'.freeze
Instance Method Summary collapse
-
#initialize(site, request) ⇒ RecaptchaService
constructor
A new instance of RecaptchaService.
- #verify(response_code) ⇒ Object
Constructor Details
#initialize(site, request) ⇒ RecaptchaService
Returns a new instance of RecaptchaService.
11 12 13 14 15 16 17 |
# File 'lib/locomotive/steam/services/recaptcha_service.rb', line 11 def initialize(site, request) attributes = site..values.reduce({}, :merge).with_indifferent_access @api = attributes[:recaptcha_api_url] || GOOGLE_API_URL @secret = attributes[:recaptcha_secret] @ip = request.ip end |
Instance Method Details
#verify(response_code) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/locomotive/steam/services/recaptcha_service.rb', line 19 def verify(response_code) # save a HTTP query if there is no code return false if response_code.blank? _response = HTTParty.get(@api, { query: { secret: @secret, response: response_code, remoteip: @ip }}) _response.parsed_response['success'] end |