Class: BrandCaptcha
- Inherits:
-
Object
- Object
- BrandCaptcha
- Defined in:
- lib/brand_captcha.rb
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- API_HOST =
'api.pontamedia.net'
- VERIFY_PATH =
'/verify.php'
- CHALLENGE_PATH =
'/challenge.php'
- Error =
Class.new(StandardError)
Class Method Summary collapse
- .check_answer(remote_ip, challenge, response, extra_params = {}) ⇒ Object
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .widget(error = nil) ⇒ Object
Class Method Details
.check_answer(remote_ip, challenge, response, extra_params = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/brand_captcha.rb', line 29 def self.check_answer remote_ip, challenge, response, extra_params={} raise Error.new('To use BrandCaptcha you must get an API key') if configuration.private_key.to_s.empty? raise Error.new('For security reasons, you must pass the remote ip to BrandCaptcha') if remote_ip.to_s.empty? return false if challenge.to_s.empty? or response.to_s.empty? params = { privatekey: configuration.private_key, remoteip: remote_ip, challenge: challenge, response: response }.merge extra_params uri = URI('http://' + API_HOST + VERIFY_PATH) res = Net::HTTP.post_form(uri, params) res.body =~ /true/ end |
.configuration ⇒ Object
12 13 14 |
# File 'lib/brand_captcha.rb', line 12 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
16 17 18 19 |
# File 'lib/brand_captcha.rb', line 16 def self.configure self.configuration yield(configuration) end |
.widget(error = nil) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/brand_captcha.rb', line 21 def self. error=nil raise Error.new('To use BrandCaptcha you must get an API Key') if configuration.public_key.to_s.empty? url = '//' + API_HOST + CHALLENGE_PATH error_part = error ? "&error=#{error}" : "" "<script type='text/javascript' src='#{url}?k=#{configuration.public_key}#{error_part}'></script>"; end |