private_captcha 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +23 -138
- data/lib/private_captcha/verify_output.rb +4 -2
- data/lib/private_captcha/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8cfbe57b68cd76d99caf830425f5c0b266807cd9f0b1290e7f973f10b3d6ff58
|
|
4
|
+
data.tar.gz: 9dc9b9cb80b0ed3efeaa15992233688836a07d0a2e26f8640f1801f023db0958
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9cfab92357a7f4a13d2b6f9aa63a2f523f29de75bcd0c2d79b252e49f65ca02cda3881ecadb7a2d5785eb9f85fa7e48df1561c4dad217718e532834ced62d8fc
|
|
7
|
+
data.tar.gz: 3cac0cac74a8e081a3a67e405481306d2ddfe01a8d9790de575fb45ee1ab40fa3bb08d4bcb86f2110bccc5b248c054434323cc371f0d814016352452113047f4
|
data/README.md
CHANGED
|
@@ -5,151 +5,36 @@
|
|
|
5
5
|
|
|
6
6
|
Ruby client for server-side verification of Private Captcha solutions.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Add this line to your application's Gemfile:
|
|
11
|
-
|
|
12
|
-
```ruby
|
|
13
|
-
gem 'private_captcha'
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
And then execute:
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
bundle install
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Or install it yourself as:
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
gem install private_captcha
|
|
26
|
-
```
|
|
8
|
+
<mark>Please check the [official documentation](https://docs.privatecaptcha.com/docs/integrations/ruby/) for the in-depth and up-to-date information.</mark>
|
|
27
9
|
|
|
28
10
|
## Quick Start
|
|
29
11
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
client
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
#
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if result.ok?
|
|
42
|
-
puts 'Captcha verified successfully!'
|
|
43
|
-
else
|
|
44
|
-
puts "Verification failed: #{result.error_message}"
|
|
12
|
+
- Install gem `private_captcha`
|
|
13
|
+
```bash
|
|
14
|
+
gem install private_captcha
|
|
15
|
+
```
|
|
16
|
+
- Instantiate the client and call `verify()` method to check the captcha solution
|
|
17
|
+
```ruby
|
|
18
|
+
require 'private_captcha'
|
|
19
|
+
|
|
20
|
+
# Initialize the client with your API key
|
|
21
|
+
client = PrivateCaptcha::Client.new do |config|
|
|
22
|
+
config.api_key = 'your-api-key-here'
|
|
45
23
|
end
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
end
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Usage
|
|
52
|
-
|
|
53
|
-
### Web Framework Integration
|
|
54
|
-
|
|
55
|
-
#### Sinatra Example
|
|
56
|
-
|
|
57
|
-
```ruby
|
|
58
|
-
require 'sinatra'
|
|
59
|
-
require 'private_captcha'
|
|
60
|
-
|
|
61
|
-
client = PrivateCaptcha::Client.new do |config|
|
|
62
|
-
config.api_key = 'your-api-key'
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
post '/submit' do
|
|
24
|
+
|
|
25
|
+
# Verify a captcha solution
|
|
66
26
|
begin
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
rescue PrivateCaptcha::Error
|
|
73
|
-
status 400
|
|
74
|
-
'Captcha verification failed'
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
#### Rails Example
|
|
80
|
-
|
|
81
|
-
```ruby
|
|
82
|
-
class FormsController < ApplicationController
|
|
83
|
-
def submit
|
|
84
|
-
client = PrivateCaptcha::Client.new do |config|
|
|
85
|
-
config.api_key = 'your-api-key'
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
begin
|
|
89
|
-
client.verify_request(request)
|
|
90
|
-
# Process form data
|
|
91
|
-
render plain: 'Success!'
|
|
92
|
-
rescue PrivateCaptcha::Error
|
|
93
|
-
render plain: 'Captcha failed', status: :bad_request
|
|
27
|
+
result = client.verify('user-solution-from-frontend')
|
|
28
|
+
if result.ok?
|
|
29
|
+
puts 'Captcha verified successfully!'
|
|
30
|
+
else
|
|
31
|
+
puts "Verification failed: #{result.error_message}"
|
|
94
32
|
end
|
|
33
|
+
rescue PrivateCaptcha::Error => e
|
|
34
|
+
puts "Error: #{e.message}"
|
|
95
35
|
end
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
#### Rack Middleware
|
|
100
|
-
|
|
101
|
-
```ruby
|
|
102
|
-
require 'private_captcha'
|
|
103
|
-
|
|
104
|
-
use PrivateCaptcha::Middleware,
|
|
105
|
-
api_key: 'your-api-key',
|
|
106
|
-
failed_status_code: 403
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
## Configuration
|
|
110
|
-
|
|
111
|
-
### Client Options
|
|
112
|
-
|
|
113
|
-
```ruby
|
|
114
|
-
require 'private_captcha'
|
|
115
|
-
|
|
116
|
-
client = PrivateCaptcha::Client.new do |config|
|
|
117
|
-
config.api_key = 'your-api-key'
|
|
118
|
-
config.domain = PrivateCaptcha::Configuration::EU_DOMAIN # replace domain for self-hosting or EU isolation
|
|
119
|
-
config.form_field = 'private-captcha-solution' # custom form field name
|
|
120
|
-
config.max_backoff_seconds = 20 # maximum wait between retries
|
|
121
|
-
config.attempts = 5 # number of retry attempts
|
|
122
|
-
config.logger = Logger.new(STDOUT) # optional logger
|
|
123
|
-
end
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Non-standard backend domains
|
|
127
|
-
|
|
128
|
-
```ruby
|
|
129
|
-
require 'private_captcha'
|
|
130
|
-
|
|
131
|
-
# Use EU domain
|
|
132
|
-
eu_client = PrivateCaptcha::Client.new do |config|
|
|
133
|
-
config.api_key = 'your-api-key'
|
|
134
|
-
config.domain = PrivateCaptcha::Configuration::EU_DOMAIN # api.eu.privatecaptcha.com
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
# Or specify custom domain in case of self-hosting
|
|
138
|
-
custom_client = PrivateCaptcha::Client.new do |config|
|
|
139
|
-
config.api_key = 'your-api-key'
|
|
140
|
-
config.domain = 'your-custom-domain.com'
|
|
141
|
-
end
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### Retry Configuration
|
|
145
|
-
|
|
146
|
-
```ruby
|
|
147
|
-
result = client.verify(
|
|
148
|
-
'solution',
|
|
149
|
-
max_backoff_seconds: 15, # maximum wait between retries
|
|
150
|
-
attempts: 3 # number of retry attempts
|
|
151
|
-
)
|
|
152
|
-
```
|
|
36
|
+
```
|
|
37
|
+
- Integrate using Rack middleware or use with Sinatra or Rails with `client.verify_request()` helper
|
|
153
38
|
|
|
154
39
|
## Requirements
|
|
155
40
|
|
|
@@ -15,7 +15,8 @@ module PrivateCaptcha
|
|
|
15
15
|
MAINTENANCE_MODE_ERROR = 9
|
|
16
16
|
TEST_PROPERTY_ERROR = 10
|
|
17
17
|
INTEGRITY_ERROR = 11
|
|
18
|
-
|
|
18
|
+
ORG_SCOPE_ERROR = 12
|
|
19
|
+
VERIFY_CODES_COUNT = 13
|
|
19
20
|
|
|
20
21
|
ERROR_MESSAGES = {
|
|
21
22
|
VERIFY_NO_ERROR => '',
|
|
@@ -29,7 +30,8 @@ module PrivateCaptcha
|
|
|
29
30
|
VERIFIED_BEFORE_ERROR => 'solution-verified-before',
|
|
30
31
|
MAINTENANCE_MODE_ERROR => 'maintenance-mode',
|
|
31
32
|
TEST_PROPERTY_ERROR => 'property-test',
|
|
32
|
-
INTEGRITY_ERROR => 'integrity-error'
|
|
33
|
+
INTEGRITY_ERROR => 'integrity-error',
|
|
34
|
+
ORG_SCOPE_ERROR => 'org-scope-error'
|
|
33
35
|
}.freeze
|
|
34
36
|
|
|
35
37
|
attr_accessor :success, :code, :origin, :timestamp
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: private_captcha
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Taras Kushnir
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-12-
|
|
11
|
+
date: 2025-12-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|