Module: RainCaptcha

Extended by:
Configuration
Defined in:
lib/rain_captcha.rb,
lib/rain_captcha/version.rb,
lib/rain_captcha/configuration.rb

Defined Under Namespace

Modules: Configuration

Constant Summary collapse

VERSION =
"0.0.1"

Constants included from Configuration

Configuration::RAINCAPTCHA_URL

Instance Attribute Summary

Attributes included from Configuration

#use_ssl

Class Method Summary collapse

Methods included from Configuration

configure, endpoint, extended, protocol, reset

Class Method Details

.url(identifier) ⇒ Object



8
9
10
11
12
13
# File 'lib/rain_captcha.rb', line 8

def url(identifier)
  uri = URI(endpoint)
  params = { key: identifier }
  uri.query = URI.encode_www_form(params)
  uri.to_s
end

.verify(identifier, answer) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/rain_captcha.rb', line 26

def verify(identifier, answer)
  response = Net::HTTP.get_response(verify_uri(identifier, answer))
  if response.is_a? Net::HTTPSuccess
    response.body == "true"
  else
    response.value
  end
end

.verify_uri(identifier, answer) ⇒ Object



19
20
21
22
23
24
# File 'lib/rain_captcha.rb', line 19

def verify_uri(identifier, answer)
  uri = URI("#{endpoint}test/")
  params = { key: identifier, code: answer }
  uri.query = URI.encode_www_form(params)
  uri
end

.verify_url(identifier, answer) ⇒ Object



15
16
17
# File 'lib/rain_captcha.rb', line 15

def verify_url(identifier, answer)
  verify_uri(identifier, answer).to_s
end