Class: PrivateCaptcha::VerifyOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/private_captcha/verify_output.rb

Overview

VerifyOutput represents the result of a captcha verification

Constant Summary collapse

VERIFY_NO_ERROR =
0
VERIFY_ERROR_OTHER =
1
DUPLICATE_SOLUTIONS_ERROR =
2
INVALID_SOLUTION_ERROR =
3
PARSE_RESPONSE_ERROR =
4
PUZZLE_EXPIRED_ERROR =
5
INVALID_PROPERTY_ERROR =
6
WRONG_OWNER_ERROR =
7
VERIFIED_BEFORE_ERROR =
8
MAINTENANCE_MODE_ERROR =
9
TEST_PROPERTY_ERROR =
10
INTEGRITY_ERROR =
11
ORG_SCOPE_ERROR =
12
VERIFY_CODES_COUNT =
13
ERROR_MESSAGES =
{
  VERIFY_NO_ERROR => '',
  VERIFY_ERROR_OTHER => 'error-other',
  DUPLICATE_SOLUTIONS_ERROR => 'solution-duplicates',
  INVALID_SOLUTION_ERROR => 'solution-invalid',
  PARSE_RESPONSE_ERROR => 'solution-bad-format',
  PUZZLE_EXPIRED_ERROR => 'puzzle-expired',
  INVALID_PROPERTY_ERROR => 'property-invalid',
  WRONG_OWNER_ERROR => 'property-owner-mismatch',
  VERIFIED_BEFORE_ERROR => 'solution-verified-before',
  MAINTENANCE_MODE_ERROR => 'maintenance-mode',
  TEST_PROPERTY_ERROR => 'property-test',
  INTEGRITY_ERROR => 'integrity-error',
  ORG_SCOPE_ERROR => 'org-scope-error'
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success: false, code: VERIFY_NO_ERROR, origin: nil, timestamp: nil, trace_id: nil, attempt: 0) ⇒ VerifyOutput

Returns a new instance of VerifyOutput.



40
41
42
43
44
45
46
47
# File 'lib/private_captcha/verify_output.rb', line 40

def initialize(success: false, code: VERIFY_NO_ERROR, origin: nil, timestamp: nil, trace_id: nil, attempt: 0)
  @success = success
  @code = code
  @origin = origin
  @timestamp = timestamp
  @trace_id = trace_id
  @attempt = attempt
end

Instance Attribute Details

#attemptObject (readonly)

Returns the value of attribute attempt.



38
39
40
# File 'lib/private_captcha/verify_output.rb', line 38

def attempt
  @attempt
end

#codeObject

Returns the value of attribute code.



37
38
39
# File 'lib/private_captcha/verify_output.rb', line 37

def code
  @code
end

#originObject

Returns the value of attribute origin.



37
38
39
# File 'lib/private_captcha/verify_output.rb', line 37

def origin
  @origin
end

#successObject

Returns the value of attribute success.



37
38
39
# File 'lib/private_captcha/verify_output.rb', line 37

def success
  @success
end

#timestampObject

Returns the value of attribute timestamp.



37
38
39
# File 'lib/private_captcha/verify_output.rb', line 37

def timestamp
  @timestamp
end

#trace_idObject (readonly)

Returns the value of attribute trace_id.



38
39
40
# File 'lib/private_captcha/verify_output.rb', line 38

def trace_id
  @trace_id
end

Class Method Details

.from_json(json_data, trace_id: nil, attempt: 0) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/private_captcha/verify_output.rb', line 57

def self.from_json(json_data, trace_id: nil, attempt: 0)
  new(
    success: json_data['success'],
    code: json_data['code'] || VERIFY_NO_ERROR,
    origin: json_data['origin'],
    timestamp: json_data['timestamp'],
    trace_id: trace_id,
    attempt: attempt
  )
end

Instance Method Details

#error_messageObject



53
54
55
# File 'lib/private_captcha/verify_output.rb', line 53

def error_message
  ERROR_MESSAGES.fetch(@code, 'error')
end

#ok?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/private_captcha/verify_output.rb', line 49

def ok?
  @success == true && @code == VERIFY_NO_ERROR
end