Class: Recaptcha::Configuration
- Inherits:
-
Object
- Object
- Recaptcha::Configuration
- 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 =
{ 'free_server_url' => 'https://www.recaptcha.net/recaptcha/api.js', 'enterprise_server_url' => 'https://www.recaptcha.net/recaptcha/enterprise.js', 'free_verify_url' => 'https://www.recaptcha.net/recaptcha/api/siteverify', 'enterprise_verify_url' => 'https://recaptchaenterprise.googleapis.com/v1/projects' }.freeze
Instance Attribute Summary collapse
- #api_server_url ⇒ Object
-
#default_env ⇒ Object
Returns the value of attribute default_env.
-
#enterprise ⇒ Object
Returns the value of attribute enterprise.
-
#enterprise_api_key ⇒ Object
Returns the value of attribute enterprise_api_key.
-
#enterprise_project_id ⇒ Object
Returns the value of attribute enterprise_project_id.
-
#handle_timeouts_gracefully ⇒ Object
Returns the value of attribute handle_timeouts_gracefully.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#response_limit ⇒ Object
Returns the value of attribute response_limit.
-
#response_minimum ⇒ Object
Returns the value of attribute response_minimum.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#site_key ⇒ Object
Returns the value of attribute site_key.
-
#skip_verify_env ⇒ Object
Returns the value of attribute skip_verify_env.
- #verify_url ⇒ Object
Instance Method Summary collapse
- #enterprise_api_key! ⇒ Object
- #enterprise_project_id! ⇒ Object
-
#initialize ⇒ Configuration
constructor
:nodoc:.
- #secret_key! ⇒ Object
- #site_key! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
:nodoc:
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/recaptcha/configuration.rb', line 46 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'] @enterprise = ENV['RECAPTCHA_ENTERPRISE'] == 'true' @enterprise_api_key = ENV['RECAPTCHA_ENTERPRISE_API_KEY'] @enterprise_project_id = ENV['RECAPTCHA_ENTERPRISE_PROJECT_ID'] @verify_url = nil @api_server_url = nil @response_limit = 4000 @response_minimum = 100 end |
Instance Attribute Details
#api_server_url ⇒ Object
81 82 83 |
# File 'lib/recaptcha/configuration.rb', line 81 def api_server_url @api_server_url || (enterprise ? DEFAULTS.fetch('enterprise_server_url') : DEFAULTS.fetch('free_server_url')) end |
#default_env ⇒ Object
Returns the value of attribute default_env.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def default_env @default_env end |
#enterprise ⇒ Object
Returns the value of attribute enterprise.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def enterprise @enterprise end |
#enterprise_api_key ⇒ Object
Returns the value of attribute enterprise_api_key.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def enterprise_api_key @enterprise_api_key end |
#enterprise_project_id ⇒ Object
Returns the value of attribute enterprise_project_id.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def enterprise_project_id @enterprise_project_id end |
#handle_timeouts_gracefully ⇒ Object
Returns the value of attribute handle_timeouts_gracefully.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def handle_timeouts_gracefully @handle_timeouts_gracefully end |
#hostname ⇒ Object
Returns the value of attribute hostname.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def hostname @hostname end |
#proxy ⇒ Object
Returns the value of attribute proxy.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def proxy @proxy end |
#response_limit ⇒ Object
Returns the value of attribute response_limit.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def response_limit @response_limit end |
#response_minimum ⇒ Object
Returns the value of attribute response_minimum.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def response_minimum @response_minimum end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def secret_key @secret_key end |
#site_key ⇒ Object
Returns the value of attribute site_key.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def site_key @site_key end |
#skip_verify_env ⇒ Object
Returns the value of attribute skip_verify_env.
40 41 42 |
# File 'lib/recaptcha/configuration.rb', line 40 def skip_verify_env @skip_verify_env end |
Instance Method Details
#enterprise_api_key! ⇒ Object
73 74 75 |
# File 'lib/recaptcha/configuration.rb', line 73 def enterprise_api_key! enterprise_api_key || raise(RecaptchaError, "No Enterprise API key specified.") end |
#enterprise_project_id! ⇒ Object
77 78 79 |
# File 'lib/recaptcha/configuration.rb', line 77 def enterprise_project_id! enterprise_project_id || raise(RecaptchaError, "No Enterprise project ID specified.") end |
#secret_key! ⇒ Object
65 66 67 |
# File 'lib/recaptcha/configuration.rb', line 65 def secret_key! secret_key || raise(RecaptchaError, "No secret key specified.") end |
#site_key! ⇒ Object
69 70 71 |
# File 'lib/recaptcha/configuration.rb', line 69 def site_key! site_key || raise(RecaptchaError, "No site key specified.") end |