bigid_bgcheck 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +96 -0
- data/Rakefile +30 -20
- data/lib/bigid/bgcheck/auth/authenticated_connection.rb +20 -19
- data/lib/bigid/bgcheck/auth/authenticated_resource.rb +2 -0
- data/lib/bigid/bgcheck/auth/authentication.rb +15 -14
- data/lib/bigid/bgcheck/auth/connection.rb +4 -2
- data/lib/bigid/bgcheck/bad_request_error.rb +2 -0
- data/lib/bigid/bgcheck/base_error.rb +5 -5
- data/lib/bigid/bgcheck/doc_type.rb +17 -0
- data/lib/bigid/bgcheck/document_not_supported_error.rb +2 -0
- data/lib/bigid/bgcheck/integration/connection.rb +48 -47
- data/lib/bigid/bgcheck/integration/multipart_flat.rb +6 -4
- data/lib/bigid/bgcheck/integration/request.rb +2 -0
- data/lib/bigid/bgcheck/integration/response.rb +2 -0
- data/lib/bigid/bgcheck/internal_error.rb +4 -2
- data/lib/bigid/bgcheck/invalid_credentials_error.rb +2 -0
- data/lib/bigid/bgcheck/invalid_document_value_error.rb +2 -0
- data/lib/bigid/bgcheck/no_info_error.rb +4 -2
- data/lib/bigid/bgcheck/not_permission_error.rb +2 -0
- data/lib/bigid/bgcheck/request.rb +34 -43
- data/lib/bigid/bgcheck/result.rb +2 -0
- data/lib/bigid/bgcheck/result_code.rb +30 -0
- data/lib/bigid/bgcheck/server_error.rb +2 -0
- data/lib/bigid/bgcheck/version.rb +3 -1
- data/lib/bigid_bgcheck.rb +45 -37
- data/spec/bigid_bgcheck_spec.rb +96 -4
- data/spec/lib/bgcheck/doc_type_spec.rb +28 -0
- data/spec/lib/bgcheck/result_code_spec.rb +78 -0
- data/spec/spec_helper.rb +13 -12
- metadata +132 -18
- data/README.rdoc +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0e56b8286ff8c62b9e3fc0e4b4c147df0737c1bf8af5d32ac6c12fb162ba1cd
|
4
|
+
data.tar.gz: cc0203dfb074f3960d6c96ed832279f8d07e52927fbb3f6880219d502b96403f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7cc45959661c9cb9d62d1237253544af5545454b8de12047d824968cdf7b76c36752b8b12b7ab4d70205c669ba6b749813a3ae40b226b6473fc1afcf60dbce4
|
7
|
+
data.tar.gz: a2f88c24add0312d6e2871432ead1c5eba93d8cca6fe4ebfea966c0ca751a9e320686e4d8b1261a6dc65031de8a0fc17c65e403ead78b9dcac300429f5ec4e40
|
data/CHANGELOG.md
CHANGED
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
BigId Background Check's Library for Ruby
|
2
|
+
==============
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/bigid_bgcheck.svg)](https://badge.fury.io/rb/bigid_bgcheck)
|
5
|
+
[![Build Status](https://travis-ci.com/Quasar-Flash/bigid-bgcheck-ruby.svg?branch=master)](https://travis-ci.com/Quasar-Flash/bigid-bgcheck-ruby)
|
6
|
+
|
7
|
+
Simple, efficient background processing for Ruby.
|
8
|
+
|
9
|
+
Sidekiq uses threads to handle many jobs at the same time in the
|
10
|
+
same process. It does not require Rails but will integrate tightly with
|
11
|
+
Rails to make background processing dead simple.
|
12
|
+
|
13
|
+
Dev Requirements
|
14
|
+
-----------------
|
15
|
+
|
16
|
+
- Ruby: Any version
|
17
|
+
- Bundler
|
18
|
+
|
19
|
+
Global Installation
|
20
|
+
-----------------
|
21
|
+
|
22
|
+
gem install bigid_bgcheck
|
23
|
+
|
24
|
+
Installation for Rails
|
25
|
+
-----------------
|
26
|
+
|
27
|
+
# Add to the Gemfile
|
28
|
+
gem 'bigid_bgcheck', '~> 0.1.0'
|
29
|
+
|
30
|
+
Setting the BigID credentials
|
31
|
+
-----------------
|
32
|
+
|
33
|
+
# Set the env variables
|
34
|
+
ENV['BIGID_USERNAME'] = 'your_username'
|
35
|
+
ENV['BIGID_PASSWORD'] = 'your_password'
|
36
|
+
|
37
|
+
Setting the BigID credentials - Rails Project
|
38
|
+
-----------------
|
39
|
+
|
40
|
+
Create the config/initializers/bigid_bgcheck.rb file and define:
|
41
|
+
|
42
|
+
# Set the env variables
|
43
|
+
Bigid::Bgcheck.configure do |config|
|
44
|
+
config.username = 'your_username'
|
45
|
+
config.password = 'your_password'
|
46
|
+
end
|
47
|
+
|
48
|
+
Applying a background check
|
49
|
+
-----------------
|
50
|
+
|
51
|
+
require 'bigid_bgcheck'
|
52
|
+
|
53
|
+
Bigid::Bgcheck::Request.new.call(
|
54
|
+
document: '000.000.000-00',
|
55
|
+
document_type: 'CPF',
|
56
|
+
group: 'Default'
|
57
|
+
)
|
58
|
+
|
59
|
+
Result Example
|
60
|
+
-----------------
|
61
|
+
|
62
|
+
#<Bigid::Bgcheck::Result:0x0000560fef3c1068
|
63
|
+
@approved=false,
|
64
|
+
@ticket_id="00000000000000000",
|
65
|
+
@code=-1100,
|
66
|
+
@message="Not Approved",
|
67
|
+
@score=0,
|
68
|
+
@limit_score=0.0>
|
69
|
+
|
70
|
+
Problems?
|
71
|
+
-----------------
|
72
|
+
|
73
|
+
**Please do not directly email any committers with questions or problems.** A community is best served when discussions are held in public.
|
74
|
+
|
75
|
+
Searching the [issues](https://github.com/Quasar-Flash/bigid-bgcheck-ruby/issues) for your problem is also a good idea.
|
76
|
+
|
77
|
+
Contributing
|
78
|
+
-----------------
|
79
|
+
|
80
|
+
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet;
|
81
|
+
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it;
|
82
|
+
- Fork the project;
|
83
|
+
- Start a feature/bugfix branch;
|
84
|
+
- Commit and push until you are happy with your contribution;
|
85
|
+
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.;
|
86
|
+
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
87
|
+
|
88
|
+
License
|
89
|
+
-----------------
|
90
|
+
|
91
|
+
Please see [LICENSE](https://github.com/Quasar-Flash/bigid-bgcheck-ruby/blob/master/LICENSE.txt) for licensing details.
|
92
|
+
|
93
|
+
Authors
|
94
|
+
-----------------
|
95
|
+
|
96
|
+
Danilo Carolino, [@danilogco](https://github.com/danilogco) / [@Quasar-Flash](https://github.com/Quasar-Flash)
|
data/Rakefile
CHANGED
@@ -1,38 +1,48 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
begin
|
3
|
-
require
|
5
|
+
require "bundler/setup"
|
4
6
|
rescue LoadError
|
5
|
-
puts
|
7
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
6
8
|
end
|
9
|
+
|
7
10
|
begin
|
8
|
-
require
|
11
|
+
require "rdoc/task"
|
9
12
|
rescue LoadError
|
10
|
-
require
|
11
|
-
require
|
13
|
+
require "rdoc/rdoc"
|
14
|
+
require "rake/rdoctask"
|
15
|
+
|
12
16
|
RDoc::Task = Rake::RDocTask
|
13
17
|
end
|
14
18
|
|
15
19
|
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
-
rdoc.rdoc_dir =
|
17
|
-
rdoc.title =
|
18
|
-
rdoc.options <<
|
19
|
-
rdoc.rdoc_files.include(
|
20
|
-
rdoc.rdoc_files.include(
|
20
|
+
rdoc.rdoc_dir = "rdoc"
|
21
|
+
rdoc.title = "bigid_bgcheck"
|
22
|
+
rdoc.options << "--line-numbers"
|
23
|
+
rdoc.rdoc_files.include("README.rdoc")
|
24
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
21
25
|
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
27
|
Bundler::GemHelper.install_tasks
|
27
28
|
|
29
|
+
begin
|
30
|
+
require "rake/testtask"
|
31
|
+
require "rubocop/rake_task"
|
32
|
+
|
33
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
34
|
+
t.options = ["--display-cop-names"]
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
# no rspec available
|
38
|
+
end
|
28
39
|
|
29
|
-
|
40
|
+
begin
|
41
|
+
require "rspec/core/rake_task"
|
30
42
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
t.pattern = "spec/**/*_spec.rb"
|
35
|
-
t.verbose = true
|
43
|
+
RSpec::Core::RakeTask.new(:spec)
|
44
|
+
rescue LoadError
|
45
|
+
# no rspec available
|
36
46
|
end
|
37
47
|
|
38
|
-
task :
|
48
|
+
task default: %i[rubocop ]
|
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bigid
|
2
4
|
module Bgcheck
|
3
5
|
module Auth
|
4
6
|
class AuthenticatedConnection < Connection
|
5
|
-
COOKIE_CACHE_KEY =
|
7
|
+
COOKIE_CACHE_KEY = "BIG_ID_AUTHENTICATION_COOKIE_CACHE_KEY"
|
6
8
|
|
7
9
|
def initialize(authentication: Bigid::Bgcheck::Auth::Authentication.new,
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
cache: defined?(Rails) ? Rails.cache : nil,
|
11
|
+
request_class: Faraday,
|
12
|
+
base_url: Bigid::Bgcheck::BASE_URL,
|
13
|
+
token_expiration_time_in_seconds: Bigid::Bgcheck::TOKEN_EXPIRATION)
|
12
14
|
super(request_class: request_class, base_url: base_url)
|
13
15
|
@authentication = authentication
|
14
16
|
@cache = cache
|
@@ -20,24 +22,23 @@ module Bigid
|
|
20
22
|
end
|
21
23
|
|
22
24
|
private
|
25
|
+
def auth_token
|
26
|
+
response = @authentication.login
|
27
|
+
extract_token(response.body)
|
28
|
+
end
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def cached_token
|
30
|
-
@cache.fetch(COOKIE_CACHE_KEY, expires_in: @token_expiration_time_in_seconds.seconds) do
|
31
|
-
auth_token
|
30
|
+
def cached_token
|
31
|
+
@cache.fetch(COOKIE_CACHE_KEY, expires_in: @token_expiration_time_in_seconds.seconds) do
|
32
|
+
auth_token
|
33
|
+
end
|
32
34
|
end
|
33
|
-
end
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
def extract_token(value)
|
37
|
+
raise Bigid::Bgcheck::AuthenticationError unless value
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
value_json = JSON.parse(value)
|
40
|
+
"Bearer #{value_json['token']}"
|
41
|
+
end
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
@@ -1,19 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bigid
|
2
4
|
module Bgcheck
|
3
5
|
module Auth
|
4
6
|
class Authentication
|
5
7
|
def initialize(connection: Connection.new,
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
username: Bigid::Bgcheck.configuration.username,
|
9
|
+
password: Bigid::Bgcheck.configuration.password,
|
10
|
+
token_expiration_time_in_seconds: Bigid::Bgcheck::AUTH_ENDPOINT)
|
9
11
|
@connection = connection
|
10
12
|
@token_expiration_time_in_seconds = Bigid::Bgcheck::TOKEN_EXPIRATION
|
11
|
-
@username = username
|
12
|
-
@password = password
|
13
|
+
@username = username
|
14
|
+
@password = password
|
13
15
|
end
|
14
16
|
|
15
17
|
def login
|
16
|
-
res = @connection.post(url:
|
18
|
+
res = @connection.post(url: "Generate", body: login_body)
|
17
19
|
|
18
20
|
return res if res.status == 200
|
19
21
|
|
@@ -23,14 +25,13 @@ module Bigid
|
|
23
25
|
end
|
24
26
|
|
25
27
|
private
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
28
|
+
def login_body
|
29
|
+
{
|
30
|
+
login: @username,
|
31
|
+
password: @password,
|
32
|
+
expires: @token_expiration_time_in_seconds.to_i
|
33
|
+
}.to_json
|
34
|
+
end
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bigid
|
2
4
|
module Bgcheck
|
3
5
|
module Auth
|
@@ -8,8 +10,8 @@ module Bigid
|
|
8
10
|
|
9
11
|
def default_headers
|
10
12
|
{
|
11
|
-
'Content-Type':
|
12
|
-
'Accept':
|
13
|
+
'Content-Type': "application/json",
|
14
|
+
'Accept': "application/json"
|
13
15
|
}
|
14
16
|
end
|
15
17
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bigid
|
2
4
|
module Bgcheck
|
3
5
|
class BaseError < StandardError
|
@@ -11,12 +13,10 @@ module Bigid
|
|
11
13
|
I18n.t("errors.#{underscore(name)}")
|
12
14
|
end
|
13
15
|
|
14
|
-
protected
|
15
|
-
|
16
16
|
def self.underscore(str)
|
17
|
-
str.gsub(/::/,
|
18
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
19
|
-
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
17
|
+
str.gsub(/::/, ".")
|
18
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
19
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
20
20
|
.tr("-", "_")
|
21
21
|
.downcase
|
22
22
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bigid
|
4
|
+
module Bgcheck
|
5
|
+
class DocType
|
6
|
+
VALUES = %w[CPF CNPJ].freeze
|
7
|
+
|
8
|
+
def self.valid?(document_type)
|
9
|
+
VALUES.include?(document_type.upcase)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.values
|
13
|
+
VALUES
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bigid
|
2
4
|
module Bgcheck
|
3
5
|
module Integration
|
4
6
|
class Connection
|
5
7
|
attr_reader :base_url
|
6
8
|
|
7
|
-
def initialize(request_class: Faraday
|
9
|
+
def initialize(base_url:, request_class: Faraday)
|
8
10
|
@request_class = request_class
|
9
11
|
@base_url = base_url
|
10
12
|
end
|
11
13
|
|
12
|
-
def get(url:
|
14
|
+
def get(url: "", params: {}, headers: {})
|
13
15
|
send_request(
|
14
16
|
method: :get,
|
15
17
|
url: url,
|
@@ -18,7 +20,7 @@ module Bigid
|
|
18
20
|
)
|
19
21
|
end
|
20
22
|
|
21
|
-
def post(url:
|
23
|
+
def post(url: "", params: {}, headers: {}, body: {}, multipart: false)
|
22
24
|
send_request(
|
23
25
|
method: :post,
|
24
26
|
url: url,
|
@@ -29,7 +31,7 @@ module Bigid
|
|
29
31
|
)
|
30
32
|
end
|
31
33
|
|
32
|
-
def put(url:
|
34
|
+
def put(url: "", params: {}, headers: {}, body: {})
|
33
35
|
send_request(
|
34
36
|
method: :put,
|
35
37
|
url: url,
|
@@ -39,7 +41,7 @@ module Bigid
|
|
39
41
|
)
|
40
42
|
end
|
41
43
|
|
42
|
-
def patch(url:
|
44
|
+
def patch(url: "", params: {}, headers: {}, body: {})
|
43
45
|
send_request(
|
44
46
|
method: :patch,
|
45
47
|
url: url,
|
@@ -49,7 +51,7 @@ module Bigid
|
|
49
51
|
)
|
50
52
|
end
|
51
53
|
|
52
|
-
def delete(url:
|
54
|
+
def delete(url: "", params: {}, headers: {}, body: {})
|
53
55
|
send_request(
|
54
56
|
method: :delete,
|
55
57
|
url: url,
|
@@ -64,55 +66,54 @@ module Bigid
|
|
64
66
|
end
|
65
67
|
|
66
68
|
private
|
69
|
+
def send_request(method:, url:, params:, headers:, body: nil, multipart: false)
|
70
|
+
connection = multipart ? multipart_connection : @request_class.new(url: @base_url)
|
67
71
|
|
68
|
-
|
69
|
-
connection = multipart ? multipart_connection : @request_class.new(url: @base_url)
|
72
|
+
merged_headers = default_headers.merge(headers)
|
70
73
|
|
71
|
-
|
74
|
+
request = build_request(
|
75
|
+
method, connection.build_url(url).to_s, params, merged_headers, body
|
76
|
+
)
|
72
77
|
|
73
|
-
|
74
|
-
|
75
|
-
|
78
|
+
result =
|
79
|
+
connection.send(method) do |request|
|
80
|
+
request.url(url)
|
81
|
+
request.params = params
|
82
|
+
request.headers = merged_headers
|
83
|
+
request.body = body if body
|
84
|
+
end
|
76
85
|
|
77
|
-
|
78
|
-
|
79
|
-
request.url(url)
|
80
|
-
request.params = params
|
81
|
-
request.headers = merged_headers
|
82
|
-
request.body = body if body
|
83
|
-
end
|
84
|
-
|
85
|
-
build_response(request, result.status, result.headers, result.body)
|
86
|
-
end
|
86
|
+
build_response(request, result.status, result.headers, result.body)
|
87
|
+
end
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
89
|
+
def multipart_connection
|
90
|
+
@request_class.new(url: @base_url) do |conn|
|
91
|
+
conn.use Bigid::Bgcheck::Integration::MultipartFlat
|
92
|
+
conn.request :url_encoded
|
93
|
+
conn.adapter @request_class.default_adapter
|
94
|
+
end
|
93
95
|
end
|
94
|
-
end
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
97
|
+
def build_request(method, url, params, headers, body)
|
98
|
+
Bigid::Bgcheck::Integration::Request.new(
|
99
|
+
method: method,
|
100
|
+
url: url,
|
101
|
+
params: params,
|
102
|
+
headers: headers,
|
103
|
+
body: body,
|
104
|
+
time: Time.now.utc
|
105
|
+
)
|
106
|
+
end
|
106
107
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
108
|
+
def build_response(request, status, headers, body)
|
109
|
+
Bigid::Bgcheck::Integration::Response.new(
|
110
|
+
request: request,
|
111
|
+
status: status,
|
112
|
+
headers: headers,
|
113
|
+
body: body,
|
114
|
+
time: Time.now.utc
|
115
|
+
)
|
116
|
+
end
|
116
117
|
end
|
117
118
|
end
|
118
119
|
end
|