trustcaptcha 2.0.0.pre.beta.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0676f4d7f6a64cf1dd91ed6a4a885a473693114b93ca71849ec45d2443905de8
4
+ data.tar.gz: 770e00c90e15ff986cff933633b8e9b1084a7697daaeefdc5da5fbe732b2cead
5
+ SHA512:
6
+ metadata.gz: 5d434c2851df9a62a9e265b31537077e6bbe80291922633aa90e40a49285e1848219205e56f696c44fc797b8228dc2d59083c9e7c4419176b78945dddab5d05b
7
+ data.tar.gz: 1c07d37c1048627a6ded2963be0cb65ddba9c5fde7afc34b64f1229c49c1ad8baf74ce30a66a3c8e4a94fa8f1fc6695ed2609d596273fa26960bcf01c13ed0a7
@@ -0,0 +1,49 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require_relative 'model/verification_token'
5
+ require_relative 'model/verification_result'
6
+
7
+ class CaptchaManager
8
+
9
+ class SecretKeyInvalidException < StandardError; end
10
+ class VerificationTokenInvalidException < StandardError; end
11
+ class VerificationNotFoundException < StandardError; end
12
+ class VerificationNotFinishedException < StandardError; end
13
+
14
+ def self.get_verification_result(secret_key, base64_verification_token)
15
+ verification_token = get_verification_token(base64_verification_token)
16
+ fetch_verification_result(verification_token, secret_key)
17
+ end
18
+
19
+ private
20
+
21
+ def self.get_verification_token(base64_verification_token)
22
+ VerificationToken.from_base64(base64_verification_token)
23
+ rescue StandardError => e
24
+ raise VerificationTokenInvalidException, "Invalid verification token: #{e.message}"
25
+ end
26
+
27
+ def self.fetch_verification_result(verification_token, access_token)
28
+ url = URI("#{verification_token.api_endpoint}/verifications/#{verification_token.verification_id}/assessments")
29
+ headers = {
30
+ "tc-authorization" => access_token,
31
+ "tc-library-language" => "ruby",
32
+ "tc-library-version" => "2.0"
33
+ }
34
+ response = Net::HTTP.get_response(url, headers)
35
+
36
+ case response.code.to_i
37
+ when 403
38
+ raise SecretKeyInvalidException, "Secret key is invalid"
39
+ when 404
40
+ raise VerificationNotFoundException, "Verification not found"
41
+ when 423
42
+ raise VerificationNotFinishedException, "Verification not finished"
43
+ else
44
+ raise "Failed to retrieve verification result: HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess)
45
+ end
46
+
47
+ VerificationResult.from_json(response.body)
48
+ end
49
+ end
@@ -0,0 +1,48 @@
1
+ require 'json'
2
+
3
+ class VerificationResult
4
+ attr_reader :captcha_id, :verification_id, :score, :reason, :mode, :origin, :ip_address,
5
+ :device_family, :operating_system, :browser, :creation_timestamp,
6
+ :release_timestamp, :retrieval_timestamp, :verification_passed
7
+
8
+ def initialize(data)
9
+ @captcha_id = data['captchaId']
10
+ @verification_id = data['verificationId']
11
+ @score = data['score']
12
+ @reason = data['reason']
13
+ @mode = data['mode']
14
+ @origin = data['origin']
15
+ @ip_address = data['ipAddress']
16
+ @device_family = data['deviceFamily']
17
+ @operating_system = data['operatingSystem']
18
+ @browser = data['browser']
19
+ @creation_timestamp = data['creationTimestamp']
20
+ @release_timestamp = data['releaseTimestamp']
21
+ @retrieval_timestamp = data['retrievalTimestamp']
22
+ @verification_passed = data['verificationPassed']
23
+ end
24
+
25
+ def self.from_json(json_data)
26
+ data = JSON.parse(json_data)
27
+ new(data)
28
+ end
29
+
30
+ def to_json(*_args)
31
+ {
32
+ captchaId: @captcha_id,
33
+ verificationId: @verification_id,
34
+ score: @score,
35
+ reason: @reason,
36
+ mode: @mode,
37
+ origin: @origin,
38
+ ipAddress: @ip_address,
39
+ deviceFamily: @device_family,
40
+ operatingSystem: @operating_system,
41
+ browser: @browser,
42
+ creationTimestamp: @creation_timestamp,
43
+ releaseTimestamp: @release_timestamp,
44
+ retrievalTimestamp: @retrieval_timestamp,
45
+ verificationPassed: @verification_passed
46
+ }.to_json
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ require 'json'
2
+ require 'securerandom'
3
+ require 'base64'
4
+
5
+ class VerificationToken
6
+ attr_reader :api_endpoint, :verification_id
7
+
8
+ def initialize(api_endpoint, verification_id)
9
+ @api_endpoint = api_endpoint
10
+ @verification_id = verification_id
11
+ end
12
+
13
+ def self.from_base64(base64_string)
14
+ json_string = Base64.decode64(base64_string)
15
+ data = JSON.parse(json_string)
16
+ new(data['apiEndpoint'], data['verificationId'])
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trustcaptcha
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0.pre.beta.0
5
+ platform: ruby
6
+ authors:
7
+ - TrustComponent
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: TrustCaptcha – Privacy-first CAPTCHA solution for Ruby. GDPR-compliant,
42
+ bot protection made in Europe.
43
+ email:
44
+ - mail@trustcomponent.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - lib/trustcaptcha/captcha_manager.rb
50
+ - lib/trustcaptcha/model/verification_result.rb
51
+ - lib/trustcaptcha/model/verification_token.rb
52
+ homepage: https://www.trustcomponent.com/en/products/captcha/integrations/ruby-captcha
53
+ licenses:
54
+ - Apache-2.0
55
+ metadata:
56
+ allowed_push_host: https://rubygems.org
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">"
69
+ - !ruby/object:Gem::Version
70
+ version: 1.3.1
71
+ requirements: []
72
+ rubygems_version: 3.3.7
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: TrustCaptcha - CAPTCHA for Ruby
76
+ test_files: []