Class: PrivateCaptcha::VerifyOutput
- Inherits:
-
Object
- Object
- PrivateCaptcha::VerifyOutput
- 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
-
#attempt ⇒ Object
readonly
Returns the value of attribute attempt.
-
#code ⇒ Object
Returns the value of attribute code.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#success ⇒ Object
Returns the value of attribute success.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
Class Method Summary collapse
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(success: false, code: VERIFY_NO_ERROR, origin: nil, timestamp: nil, trace_id: nil, attempt: 0) ⇒ VerifyOutput
constructor
A new instance of VerifyOutput.
- #ok? ⇒ Boolean
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 = @trace_id = trace_id @attempt = attempt end |
Instance Attribute Details
#attempt ⇒ Object (readonly)
Returns the value of attribute attempt.
38 39 40 |
# File 'lib/private_captcha/verify_output.rb', line 38 def attempt @attempt end |
#code ⇒ Object
Returns the value of attribute code.
37 38 39 |
# File 'lib/private_captcha/verify_output.rb', line 37 def code @code end |
#origin ⇒ Object
Returns the value of attribute origin.
37 38 39 |
# File 'lib/private_captcha/verify_output.rb', line 37 def origin @origin end |
#success ⇒ Object
Returns the value of attribute success.
37 38 39 |
# File 'lib/private_captcha/verify_output.rb', line 37 def success @success end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
37 38 39 |
# File 'lib/private_captcha/verify_output.rb', line 37 def end |
#trace_id ⇒ Object (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_message ⇒ Object
53 54 55 |
# File 'lib/private_captcha/verify_output.rb', line 53 def ERROR_MESSAGES.fetch(@code, 'error') end |
#ok? ⇒ Boolean
49 50 51 |
# File 'lib/private_captcha/verify_output.rb', line 49 def ok? @success == true && @code == VERIFY_NO_ERROR end |