Class: Recaptcha::Verify::VerifyResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/recaptcha/verify/verify_response.rb

Overview

Represents a response from the Recaptcha verify API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ VerifyResponse


10
11
12
# File 'lib/recaptcha/verify/verify_response.rb', line 10

def initialize(http_response)
  @http_response = http_response
end

Instance Attribute Details

#http_responseObject (readonly)

Returns the value of attribute http_response


7
8
9
# File 'lib/recaptcha/verify/verify_response.rb', line 7

def http_response
  @http_response
end

Instance Method Details

#actionObject


48
49
50
# File 'lib/recaptcha/verify/verify_response.rb', line 48

def action
  json['action']
end

#challenge_tsObject


52
53
54
# File 'lib/recaptcha/verify/verify_response.rb', line 52

def challenge_ts
  json['challenge_ts']
end

#error_codesObject


60
61
62
# File 'lib/recaptcha/verify/verify_response.rb', line 60

def error_codes
  json['error-codes']
end

#hostnameObject


56
57
58
# File 'lib/recaptcha/verify/verify_response.rb', line 56

def hostname
  json['hostname']
end

#jsonHash

For v2:

{ "success": true|false, "challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ) "hostname": string, // the hostname of the site where the reCAPTCHA was solved "error-codes": [...] // optional }

For v3:

{ "success": true|false, // whether this request was a valid reCAPTCHA token for your site "score": number // the score for this request (0.0 - 1.0) "action": string // the action name for this request (important to verify) "challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ) "hostname": string, // the hostname of the site where the reCAPTCHA was solved "error-codes": [...] // optional }


36
37
38
# File 'lib/recaptcha/verify/verify_response.rb', line 36

def json
  @json ||= JSON.parse(@http_response.body)
end

#scoreObject


44
45
46
# File 'lib/recaptcha/verify/verify_response.rb', line 44

def score
  json['score']
end

#success?Boolean


40
41
42
# File 'lib/recaptcha/verify/verify_response.rb', line 40

def success?
  json['success'].to_s == 'true'
end

#timeout_or_duplicate?Boolean


64
65
66
# File 'lib/recaptcha/verify/verify_response.rb', line 64

def timeout_or_duplicate?
  error_codes&.include? 'timeout-or-duplicate'
end