recaptcha_check 0.0.2 → 0.0.4

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 +24 -26
  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: 7f226b1a1cb1ab493258ed42ef5149b8c1da924923da063b714492fa22011c69
4
+ data.tar.gz: 164c89ead9687aa401e0d99d3c73695b2e56c09a011b8f9230dc4db0fcdd825c
5
5
  SHA512:
6
- metadata.gz: 7fa072911b1f0f5cbca763d7344472ab57b8ab28219463caee821d7185ed5d58c3d844bd9f21b0f91c9d9d15e79a7bde8e8591b88eb941a8972ecc8efcc0309c
7
- data.tar.gz: cff20f8da1bfa7b324e0ce544adffc11db6bd44a443b85eb6cfef6cc38a0c56dc8d9246fd131de8eed8a28e31e9135cc9857fb072555ddf25ad88ce9cd1f051a
6
+ metadata.gz: 34c254f8976539ed121404cf7ca20b5975b2e3d156c0099ace84eea53b783a978f4b1db5720080b1a0561f12e55041d47f8d330bf2926057f72e75aa75b674b9
7
+ data.tar.gz: a65ad6253f046e8d426d04f2506e4f7d15fee402fe6004de65aa772e28146b57c15e5fa9bb6d1b23f2d0ba7c4d85cef4fdbb118c35742c78c8a59fe2034dc28a
@@ -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_recaptcha
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
-
11
- def verify
18
+
19
+ def verify_recaptcha
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.4
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