Class: Recaptcha::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/recaptcha/configuration.rb

Overview

This class enables detailed configuration of the recaptcha services.

By calling

Recaptcha.configuration # => instance of Recaptcha::Configuration

or

Recaptcha.configure do |config|
  config # => instance of Recaptcha::Configuration
end

you are able to perform configuration updates.

Your are able to customize all attributes listed below. All values have sensitive default and will very likely not need to be changed.

Please note that the site and secret key for the reCAPTCHA API Access have no useful default value. The keys may be set via the Shell enviroment or using this configuration. Settings within this configuration always take precedence.

Setting the keys with this Configuration

Recaptcha.configure do |config|
  config.site_key  = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
  config.secret_key = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
end

Constant Summary collapse

DEFAULTS =
{
  'server_url' => 'https://www.recaptcha.net/recaptcha/api.js',
  'verify_url' => 'https://www.recaptcha.net/recaptcha/api/siteverify'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

:nodoc:


41
42
43
44
45
46
47
48
49
50
# File 'lib/recaptcha/configuration.rb', line 41

def initialize #:nodoc:
  @default_env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || (Rails.env if defined? Rails.env)
  @skip_verify_env = %w[test cucumber]
  @handle_timeouts_gracefully = true

  @secret_key = ENV['RECAPTCHA_SECRET_KEY']
  @site_key = ENV['RECAPTCHA_SITE_KEY']
  @verify_url = nil
  @api_server_url = nil
end

Instance Attribute Details

#api_server_urlObject


60
61
62
# File 'lib/recaptcha/configuration.rb', line 60

def api_server_url
  @api_server_url || DEFAULTS.fetch('server_url')
end

#default_envObject

Returns the value of attribute default_env


38
39
40
# File 'lib/recaptcha/configuration.rb', line 38

def default_env
  @default_env
end

#handle_timeouts_gracefullyObject

Returns the value of attribute handle_timeouts_gracefully


38
39
40
# File 'lib/recaptcha/configuration.rb', line 38

def handle_timeouts_gracefully
  @handle_timeouts_gracefully
end

#hostnameObject

Returns the value of attribute hostname


38
39
40
# File 'lib/recaptcha/configuration.rb', line 38

def hostname
  @hostname
end

#proxyObject

Returns the value of attribute proxy


38
39
40
# File 'lib/recaptcha/configuration.rb', line 38

def proxy
  @proxy
end

#secret_keyObject

Returns the value of attribute secret_key


38
39
40
# File 'lib/recaptcha/configuration.rb', line 38

def secret_key
  @secret_key
end

#site_keyObject

Returns the value of attribute site_key


38
39
40
# File 'lib/recaptcha/configuration.rb', line 38

def site_key
  @site_key
end

#skip_verify_envObject

Returns the value of attribute skip_verify_env


38
39
40
# File 'lib/recaptcha/configuration.rb', line 38

def skip_verify_env
  @skip_verify_env
end

#verify_urlObject


64
65
66
# File 'lib/recaptcha/configuration.rb', line 64

def verify_url
  @verify_url || DEFAULTS.fetch('verify_url')
end

Instance Method Details

#secret_key!Object


52
53
54
# File 'lib/recaptcha/configuration.rb', line 52

def secret_key!
  secret_key || raise(RecaptchaError, "No secret key specified.")
end

#site_key!Object


56
57
58
# File 'lib/recaptcha/configuration.rb', line 56

def site_key!
  site_key || raise(RecaptchaError, "No site key specified.")
end