recaptcha_check 0.0.2 → 0.0.3

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 +4 -4
  2. data/lib/recaptcha_check.rb +23 -25
  3. metadata +1 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 328c16d9addceb09c54f856d5908a6d32965cb30bd4afdb4041e9dd9e597cebc
4
- data.tar.gz: 72073cffa851cdcf8632d3002851d9e8382df6a8df9bb04e8cb190c4751ddcb8
3
+ metadata.gz: d5aa064a9eac3bab96394c495866efae18a3d4f208ec6ea7d1348f169ad77dfa
4
+ data.tar.gz: cc5df9e982a043753e04caf2c5948f9a89498c2c578565bdd7fe7600b734a975
5
5
  SHA512:
6
- metadata.gz: 7fa072911b1f0f5cbca763d7344472ab57b8ab28219463caee821d7185ed5d58c3d844bd9f21b0f91c9d9d15e79a7bde8e8591b88eb941a8972ecc8efcc0309c
7
- data.tar.gz: cff20f8da1bfa7b324e0ce544adffc11db6bd44a443b85eb6cfef6cc38a0c56dc8d9246fd131de8eed8a28e31e9135cc9857fb072555ddf25ad88ce9cd1f051a
6
+ metadata.gz: 4beecbb25ddaa0116e7abd209789a1288f6f2b303ba2b8544340ad606355f8aa8b976fbadcdef1edf8c3d0de9caa93613bed261730cc8ffb1c7094f86d17322d
7
+ data.tar.gz: 301c5d4f178c9488b0e89d3e262fd66c015bfa5ab15878853562fd4dc4a46150928e7696ce6f3b2ab326b70594a6576dff55b29ed497c1bcf5935af2dc1ee8e4
@@ -1,43 +1,41 @@
1
- class RecaptchaCheck
1
+ class RecaptchaCheck
2
+ def self.verify(params, ip = nil)
3
+ new(params['g-recaptcha-response'], ip).verify
4
+ end
5
+
6
+ def self.register(recaptcha_secret_key)
7
+ ENV[RECAPTCHACHECK_SECRET_KEY] = recaptcha_secret_key
8
+ end
9
+
10
+ private
11
+
12
+ RECAPTCHACHECK_SECRET_KEY = 'RECAPTCHACHECK_SECRET_KEY'.freeze
13
+
2
14
  def initialize(response, ip)
3
15
  @response = response
4
16
  @ip = ip
5
17
  end
6
-
7
- def self.verify(response, ip = nil)
8
- new(response, ip).verify
9
- end
10
-
18
+
11
19
  def verify
12
20
  require 'httparty'
13
- recaptcha_response = HTTParty.get(recaptcha_url(@response, secret, @ip))
14
- response_success?(recaptcha_response)
21
+ recaptcha_response = HTTParty.get(recaptcha_url(@response, self.secret, @ip))
22
+ self.response_success?(recaptcha_response)
15
23
  end
16
-
17
- private
18
24
 
19
- RECAPTCHA_PRIVATE_KEY = 'RECAPTCHA_PRIVATE_KEY'.freeze
20
-
21
25
  def recaptcha_url(response, secret, ip)
22
26
  "https://www.google.com/recaptcha/api/siteverify?secret=#{secret}&response=#{response}&remoteip=#{ip}"
23
27
  end
24
28
 
29
+ def response_success?(response)
30
+ response.fetch('success')
31
+ end
32
+
25
33
  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
+ raise "Use RecaptchaCheck#register to set the reCAPTCHA secret key." if not self.secret_defined?
35
+ ENV[RECAPTCHACHECK_SECRET_KEY]
34
36
  end
35
37
 
36
38
  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')
39
+ not ENV[RECAPTCHACHECK_SECRET_KEY].nil?
42
40
  end
43
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recaptcha_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Stauffer
@@ -10,26 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2023-02-19 00:00:00.000000000 Z
12
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
13
  - !ruby/object:Gem::Dependency
34
14
  name: httparty
35
15
  requirement: !ruby/object:Gem::Requirement