Class: NewGoogleRecaptcha::Validator
- Inherits:
-
Object
- Object
- NewGoogleRecaptcha::Validator
- Defined in:
- lib/new_google_recaptcha/validator.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#minimum_score ⇒ Object
readonly
Returns the value of attribute minimum_score.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(token:, action:, minimum_score:) ⇒ Validator
constructor
A new instance of Validator.
Constructor Details
#initialize(token:, action:, minimum_score:) ⇒ Validator
Returns a new instance of Validator.
8 9 10 11 12 |
# File 'lib/new_google_recaptcha/validator.rb', line 8 def initialize(token:, action:, minimum_score:) @token = token @action = action @minimum_score = minimum_score end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
6 7 8 |
# File 'lib/new_google_recaptcha/validator.rb', line 6 def action @action end |
#minimum_score ⇒ Object (readonly)
Returns the value of attribute minimum_score.
6 7 8 |
# File 'lib/new_google_recaptcha/validator.rb', line 6 def minimum_score @minimum_score end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
5 6 7 |
# File 'lib/new_google_recaptcha/validator.rb', line 5 def score @score end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/new_google_recaptcha/validator.rb', line 6 def token @token end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/new_google_recaptcha/validator.rb', line 14 def call uri = NewGoogleRecaptcha.compose_uri(token) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme == 'https' result = JSON.parse(http.request(Net::HTTP::Get.new(uri)).body) @score = result['score'].to_f conditions = [] conditions << !!result['success'] conditions << (result['score'].to_f >= minimum_score) conditions << (result['action'].to_s == action.to_s) conditions.none?(&:!) end |