Sha256: b248fb2cac81d268a509d0814b7733301644333ceb574c70f7d9e7bbffe1fa51

Contents?: true

Size: 879 Bytes

Versions: 13

Compression:

Stored size: 879 Bytes

Contents

require 'httparty'

module Locomotive
  module Steam

    # This service supports Google Recaptcha or any API compatible with Google
    class RecaptchaService

      GOOGLE_API_URL = 'https://www.google.com/recaptcha/api/siteverify'.freeze

      def initialize(site, request)
        attributes = site.metafields.values.reduce({}, :merge).with_indifferent_access

        @api      = attributes[:recaptcha_api_url] || GOOGLE_API_URL
        @secret   = attributes[:recaptcha_secret]
        @ip       = request.ip
      end

      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

    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/services/recaptcha_service.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/services/recaptcha_service.rb