arcaptcha 1.0.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: 6764a496651d834cb7447cd4534d60bdcc5033d094aafdddbe7ca5769608f34f
4
+ data.tar.gz: a0c997736316f473f14243cd491cbfe83ee4ccc8e59546a154b4d5c5bb2b145a
5
+ SHA512:
6
+ metadata.gz: 67ddfee67df696d4eac44e5bec14d37c2fb58d9995000ceac8943e967ba40674623867d4c625c9285dd787377c5424d59aa7c31ea31179aabf41ad0951313d53
7
+ data.tar.gz: eca27dae15c00bdbaba5f4e33bc24422806dea3b2333491753903459b897bc4b8eb4352cd6c1b1368f4a4aa16af378825bf6ef6a99641904271bdf262cf22e72
data/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1.84.0
12
+ with:
13
+ ruby-version: 3.0.2
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in arcaptcha.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
13
+
14
+ gem "faraday"
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ arcaptcha (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.4.4)
11
+ faraday (1.8.0)
12
+ faraday-em_http (~> 1.0)
13
+ faraday-em_synchrony (~> 1.0)
14
+ faraday-excon (~> 1.1)
15
+ faraday-httpclient (~> 1.0.1)
16
+ faraday-net_http (~> 1.0)
17
+ faraday-net_http_persistent (~> 1.1)
18
+ faraday-patron (~> 1.0)
19
+ faraday-rack (~> 1.0)
20
+ multipart-post (>= 1.2, < 3)
21
+ ruby2_keywords (>= 0.0.4)
22
+ faraday-em_http (1.0.0)
23
+ faraday-em_synchrony (1.0.0)
24
+ faraday-excon (1.1.0)
25
+ faraday-httpclient (1.0.1)
26
+ faraday-net_http (1.0.1)
27
+ faraday-net_http_persistent (1.2.0)
28
+ faraday-patron (1.0.0)
29
+ faraday-rack (1.0.0)
30
+ multipart-post (2.1.1)
31
+ parallel (1.21.0)
32
+ parser (3.0.2.0)
33
+ ast (~> 2.4.1)
34
+ rainbow (3.0.0)
35
+ rake (13.0.6)
36
+ regexp_parser (2.1.1)
37
+ rexml (3.2.5)
38
+ rspec (3.10.0)
39
+ rspec-core (~> 3.10.0)
40
+ rspec-expectations (~> 3.10.0)
41
+ rspec-mocks (~> 3.10.0)
42
+ rspec-core (3.10.1)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-expectations (3.10.1)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.10.0)
47
+ rspec-mocks (3.10.2)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.10.0)
50
+ rspec-support (3.10.2)
51
+ rubocop (1.22.3)
52
+ parallel (~> 1.10)
53
+ parser (>= 3.0.0.0)
54
+ rainbow (>= 2.2.2, < 4.0)
55
+ regexp_parser (>= 1.8, < 3.0)
56
+ rexml
57
+ rubocop-ast (>= 1.12.0, < 2.0)
58
+ ruby-progressbar (~> 1.7)
59
+ unicode-display_width (>= 1.4.0, < 3.0)
60
+ rubocop-ast (1.12.0)
61
+ parser (>= 3.0.1.1)
62
+ ruby-progressbar (1.11.0)
63
+ ruby2_keywords (0.0.5)
64
+ unicode-display_width (2.1.0)
65
+
66
+ PLATFORMS
67
+ x86_64-linux
68
+
69
+ DEPENDENCIES
70
+ arcaptcha!
71
+ faraday
72
+ rake (~> 13.0)
73
+ rspec (~> 3.0)
74
+ rubocop (~> 1.7)
75
+
76
+ BUNDLED WITH
77
+ 2.2.22
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Arcptcha
2
+
3
+ Arcaptcha library in Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'arcaptcha'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install arcaptcha
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # Display script tag
25
+ Arcaptcha::Captcha.display_tag # => <script src='https://widget...
26
+
27
+ # Initialize base class
28
+ arcaptcha = Arcaptcha::Captcha.new("your_site_key", "your_secret_key")
29
+
30
+ # Display captcha HTML tag
31
+ arcaptcha.display # => <div class='arcaptcha'...
32
+
33
+ # Verify challenge_id
34
+ arcaptcha.verify("challenge_id") # => true or false
35
+ ```
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`.
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/evokelektrique/arcaptcha-ruby.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/arcaptcha.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/arcaptcha/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "arcaptcha"
7
+ spec.version = Arcaptcha::VERSION
8
+ spec.authors = ["EVOKE"]
9
+ spec.email = ["evoke.lektrique@gmail.com"]
10
+
11
+ spec.summary = "Arcaptcha library in Ruby"
12
+ spec.description = "Display and verify arcaptcha service captcha"
13
+ spec.homepage = "http://github.com/evokelektrique/arcaptcha-ruby"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ spec.metadata["changelog_uri"] = "http://github.com/evokelektrique/arcaptcha-ruby/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "arcaptcha"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arcaptcha
4
+ # Base class for validating and displaying captcha for Arcaptcha.
5
+ class Captcha
6
+ attr_reader :site_key, :secret_key
7
+
8
+ def initialize(site_key, secret_key)
9
+ @site_key = site_key
10
+ @secret_key = secret_key
11
+ end
12
+
13
+ def verify(challenge_id)
14
+ raise ArgumentError, "challenge_id cannot be empty" if challenge_id.nil? || challenge_id.empty?
15
+
16
+ verify_url = "https://api.arcaptcha.ir/arcaptcha/api/verify"
17
+ data = { site_key: @site_key, secret_key: @secret_key, challenge_id: challenge_id }
18
+
19
+ response = Faraday.post(verify_url) do |req|
20
+ req.headers["Content-Type"] = "application/json"
21
+ req.body = data.to_json
22
+ end
23
+
24
+ validate(response.body)
25
+ end
26
+
27
+ # Parse and validate response body
28
+ def validate(body)
29
+ raise ArgumentError, "body cannot be empty" if body.nil? || body.empty?
30
+
31
+ parsed = JSON.parse(body)
32
+
33
+ if parsed.key? "success"
34
+ true
35
+ else
36
+ false
37
+ end
38
+ end
39
+
40
+ # Print captcha HTML tag
41
+ def display
42
+ "<div class='arcaptcha' data-site-key='#{@site_key}'></div>"
43
+ end
44
+
45
+ # Print API script tag
46
+ def self.display_tag
47
+ "<script src='https://widget.arcaptcha.ir/1/api.js' async defer></script>"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arcaptcha
4
+ VERSION = "1.0.0"
5
+ end
data/lib/arcaptcha.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "arcaptcha/version"
4
+ require_relative "arcaptcha/captcha"
5
+ require "faraday"
6
+ require "json"
7
+
8
+ module Arcaptcha
9
+ class Error < StandardError; end
10
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arcaptcha
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - EVOKE
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Display and verify arcaptcha service captcha
14
+ email:
15
+ - evoke.lektrique@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".editorconfig"
21
+ - ".github/workflows/main.yml"
22
+ - ".gitignore"
23
+ - ".rspec"
24
+ - ".rubocop.yml"
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - README.md
28
+ - Rakefile
29
+ - arcaptcha.gemspec
30
+ - bin/console
31
+ - bin/setup
32
+ - lib/arcaptcha.rb
33
+ - lib/arcaptcha/captcha.rb
34
+ - lib/arcaptcha/version.rb
35
+ homepage: http://github.com/evokelektrique/arcaptcha-ruby
36
+ licenses: []
37
+ metadata:
38
+ allowed_push_host: https://rubygems.org
39
+ homepage_uri: http://github.com/evokelektrique/arcaptcha-ruby
40
+ source_code_uri: http://github.com/evokelektrique/arcaptcha-ruby
41
+ changelog_uri: http://github.com/evokelektrique/arcaptcha-ruby/CHANGELOG.md
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.7.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.2.22
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Arcaptcha library in Ruby
61
+ test_files: []