Class: SimpleRecaptcha::Client
- Inherits:
-
Object
- Object
- SimpleRecaptcha::Client
- Defined in:
- lib/simple_recaptcha/client.rb
Instance Attribute Summary collapse
-
#challenge ⇒ Object
Returns the value of attribute challenge.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
- #private_key ⇒ Object
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #attributes=(attributes) ⇒ Object
- #parse_response ⇒ Object
- #request ⇒ Object
- #valid? ⇒ Boolean
- #verified ⇒ Object (also: #verified?)
- #verify(attributes = {}) ⇒ Object
Instance Attribute Details
#challenge ⇒ Object
Returns the value of attribute challenge.
4 5 6 |
# File 'lib/simple_recaptcha/client.rb', line 4 def challenge @challenge end |
#ip ⇒ Object
Returns the value of attribute ip.
4 5 6 |
# File 'lib/simple_recaptcha/client.rb', line 4 def ip @ip end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/simple_recaptcha/client.rb', line 6 def @message end |
#private_key ⇒ Object
8 9 10 |
# File 'lib/simple_recaptcha/client.rb', line 8 def private_key @private_key ||= SimpleRecaptcha.private_key end |
#response ⇒ Object
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_response ⇒ Object
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 |
#request ⇒ Object
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
36 37 38 |
# File 'lib/simple_recaptcha/client.rb', line 36 def valid? ["privatekey", "remoteip", "challenge", "response"].none? { |p| params[p].nil? } end |
#verified ⇒ Object 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 |