Class: SimpleRecaptcha::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_recaptcha/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#challengeObject

Returns the value of attribute challenge.



4
5
6
# File 'lib/simple_recaptcha/client.rb', line 4

def challenge
  @challenge
end

#ipObject

Returns the value of attribute ip.



4
5
6
# File 'lib/simple_recaptcha/client.rb', line 4

def ip
  @ip
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/simple_recaptcha/client.rb', line 6

def message
  @message
end

#private_keyObject



8
9
10
# File 'lib/simple_recaptcha/client.rb', line 8

def private_key
  @private_key ||= SimpleRecaptcha.private_key
end

#responseObject

Returns the value of attribute response.



4
5
6
# File 'lib/simple_recaptcha/client.rb', line 4

def response
  @response
end

Instance Method Details

#attributes=(attributes) ⇒ Object



23
24
25
# File 'lib/simple_recaptcha/client.rb', line 23

def attributes=(attributes)
  attributes.each { |key, value| send("#{key}=", value) }
end

#parse_responseObject



31
32
33
34
# File 'lib/simple_recaptcha/client.rb', line 31

def parse_response
  @verified, @message = request.body.split("\n")
  @verified = @verified == "true" ? true : false
end

#requestObject



27
28
29
# File 'lib/simple_recaptcha/client.rb', line 27

def request
  Net::HTTP.post_form(URI.parse(SimpleRecaptcha::VERIFY_URL), params)
end

#valid?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/simple_recaptcha/client.rb', line 36

def valid?
  ["privatekey", "remoteip", "challenge", "response"].none? { |p| params[p].nil? }
end

#verifiedObject Also known as: verified?



12
13
14
# File 'lib/simple_recaptcha/client.rb', line 12

def verified
  !!@verified
end

#verify(attributes = {}) ⇒ Object



17
18
19
20
21
# File 'lib/simple_recaptcha/client.rb', line 17

def verify(attributes = {})
  self.attributes = attributes
  parse_response if valid?
  verified?
end