recaptcha_check 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/recaptcha_check.rb +43 -0
  3. metadata +85 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7c1908f1409d94b626d2decec8ba87f94132dc67e9444d6c40e5259eb0b47b7a
4
+ data.tar.gz: 3b8a50098b23f0b74c36916a9a2ce40ba17a590883ecfc3100f6e4b3cde5ed09
5
+ SHA512:
6
+ metadata.gz: '086396aa3289756fb0da75cf13f574a680e43df1e782d2f8fdf2c26375f404c02f638bf7540a3132b6f37bab1e292472570f92ab806d8a4e949ceedde2bddb7b'
7
+ data.tar.gz: 390abacf178bed17adfcbfe25b7b1aec67139fb3a4bc5bb3f3bad4d57034c6f22453cb9bbcc97c191620df6a44a655293e741bc8d9c7a71f5954563dc6f6f2ec
@@ -0,0 +1,43 @@
1
+ class RecaptchaCheck
2
+ def initialize(response, ip)
3
+ @response = response
4
+ @ip = ip
5
+ end
6
+
7
+ def self.verify(response, ip = nil)
8
+ new(response, ip).verify
9
+ end
10
+
11
+ def verify
12
+ require 'httparty'
13
+ recaptcha_response = HTTParty.get(recaptcha_url(@response, secret, @ip))
14
+ response_success?(recaptcha_response)
15
+ end
16
+
17
+ private
18
+
19
+ RECAPTCHA_PRIVATE_KEY = 'RECAPTCHA_PRIVATE_KEY'.freeze
20
+
21
+ def recaptcha_url(response, secret, ip)
22
+ "https://www.google.com/recaptcha/api/siteverify?secret=#{secret}&response=#{response}&remoteip=#{ip}"
23
+ end
24
+
25
+ def secret
26
+ if not self.secret_defined?
27
+ require 'envl'
28
+ Envl.auto_load
29
+
30
+ puts "#{RECAPTCHA_PRIVATE_KEY} is not defined in ENV." if not self.secret_defined?
31
+ end
32
+
33
+ ENV[RECAPTCHA_PRIVATE_KEY]
34
+ end
35
+
36
+ def secret_defined?
37
+ not ENV[RECAPTCHA_PRIVATE_KEY].nil? or not ENV[RECAPTCHA_PRIVATE_KEY].empty?
38
+ end
39
+
40
+ def response_success?(response)
41
+ response.fetch('success')
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: recaptcha_check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Scott Stauffer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: envl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.8
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.0.8
33
+ - !ruby/object:Gem::Dependency
34
+ name: httparty
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.20'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.20.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.20'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.20.0
53
+ description: A simple interface for verifying Google reCAPTCHA responses in Ruby web
54
+ apps.
55
+ email: scott@fuseraft.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - lib/recaptcha_check.rb
61
+ homepage: https://rubygems.org/gems/recaptcha_check
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ source_code_uri: https://github.com/scstauf/recaptcha_check
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.7.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.1.6
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: A simple interface for verifying Google reCAPTCHA responses.
85
+ test_files: []