bigid_bgcheck 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +8 -9
- data/lib/bigid/bgcheck/request.rb +2 -2
- data/lib/bigid/bgcheck/version.rb +1 -1
- data/lib/bigid_bgcheck.rb +5 -24
- metadata +21 -10
- data/lib/bigid/bgcheck/auth/authenticated_connection.rb +0 -45
- data/lib/bigid/bgcheck/auth/authenticated_resource.rb +0 -13
- data/lib/bigid/bgcheck/auth/authentication.rb +0 -38
- data/lib/bigid/bgcheck/auth/connection.rb +0 -20
- data/lib/bigid/bgcheck/integration/connection.rb +0 -120
- data/lib/bigid/bgcheck/integration/multipart_flat.rb +0 -28
- data/lib/bigid/bgcheck/integration/request.rb +0 -20
- data/lib/bigid/bgcheck/integration/response.rb +0 -27
- data/lib/bigid/bgcheck/not_permission_error.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f078e2eba71cbc4578ee9a4c1ceec003435b4f3331ec52924c9b2a30eb873b5
|
4
|
+
data.tar.gz: bada7c2db0bbc0a3cbb2f7470a3f1d9d9a366a9f150cb95313e3f49aadc66f75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53249dd591e3b909a88fb5bdc0b3a70e89b56364c5ba86945cf6620f842e6c5cdf750bb07b75bca4c29ea24106a384e9fab06b43873590f0770504325549ae67
|
7
|
+
data.tar.gz: 6ddbe14002b9525f7b447cbfa4982eea4dd83458b0c6457344711acd7c72cf95ac971e31d8793a007b17d496d5ab5186a27337f13f5fe1fb30361c2cdb1a1c67
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,18 +4,17 @@ BigId Background Check's Library for Ruby
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/bigid_bgcheck.svg)](https://badge.fury.io/rb/bigid_bgcheck)
|
5
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
6
|
|
7
|
-
|
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
|
7
|
+
Requirements
|
14
8
|
-----------------
|
15
9
|
|
16
10
|
- Ruby: Any version
|
17
11
|
- Bundler
|
18
12
|
|
13
|
+
Included Modules
|
14
|
+
-----------------
|
15
|
+
|
16
|
+
- [bigid-auth-ruby](https://github.com/Quasar-Flash/bigid-auth-ruby) - BigID API authentication module
|
17
|
+
|
19
18
|
Global Installation
|
20
19
|
-----------------
|
21
20
|
|
@@ -37,10 +36,10 @@ Setting the BigID credentials
|
|
37
36
|
Setting the BigID credentials - Rails Project
|
38
37
|
-----------------
|
39
38
|
|
40
|
-
Create the config/initializers/
|
39
|
+
Create the config/initializers/bigid.rb file and define:
|
41
40
|
|
42
41
|
# Set the env variables
|
43
|
-
Bigid
|
42
|
+
Bigid.configure do |config|
|
44
43
|
config.username = 'your_username'
|
45
44
|
config.password = 'your_password'
|
46
45
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Bigid
|
4
4
|
module Bgcheck
|
5
|
-
class Request < Bigid::
|
5
|
+
class Request < Bigid::Auth::AuthenticatedResource
|
6
6
|
def call(document:, document_type:, group:)
|
7
7
|
res = @connection.post(url: Bigid::Bgcheck::SRV_ENDPOINT,
|
8
8
|
body: payload(document, document_type, group).to_json)
|
@@ -25,7 +25,7 @@ module Bigid
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def payload(document, document_type, group, parameters = {})
|
28
|
-
login = Bigid
|
28
|
+
login = Bigid.configuration.username
|
29
29
|
document_type = document_type.upcase.strip
|
30
30
|
|
31
31
|
raise Bigid::Bgcheck::DocumentNotSupportedError unless DocType.valid?(document_type)
|
@@ -9,6 +9,6 @@ module Bigid
|
|
9
9
|
# Major - Incremented for incompatible changes with previous release (or big enough new features)
|
10
10
|
# Minor - Incremented for new backwards-compatible features + deprecations
|
11
11
|
# Patch - Incremented for backwards-compatible bug fixes
|
12
|
-
VERSION = "0.1.
|
12
|
+
VERSION = "0.1.2"
|
13
13
|
end
|
14
14
|
end
|
data/lib/bigid_bgcheck.rb
CHANGED
@@ -4,38 +4,27 @@ require "faraday"
|
|
4
4
|
require "i18n"
|
5
5
|
require "json"
|
6
6
|
|
7
|
-
require "
|
8
|
-
|
9
|
-
require "bigid/bgcheck/integration/multipart_flat"
|
10
|
-
require "bigid/bgcheck/integration/response"
|
11
|
-
require "bigid/bgcheck/integration/request"
|
12
|
-
require "bigid/bgcheck/integration/connection"
|
7
|
+
require "bigid_auth"
|
13
8
|
|
14
|
-
require "bigid/bgcheck/
|
15
|
-
require "bigid/bgcheck/auth/authentication"
|
16
|
-
require "bigid/bgcheck/auth/authenticated_resource"
|
17
|
-
require "bigid/bgcheck/auth/authenticated_connection"
|
9
|
+
require "bigid/bgcheck/version"
|
18
10
|
|
19
11
|
require "bigid/bgcheck/base_error"
|
20
12
|
require "bigid/bgcheck/bad_request_error"
|
21
13
|
require "bigid/bgcheck/document_not_supported_error"
|
22
14
|
require "bigid/bgcheck/internal_error"
|
23
15
|
require "bigid/bgcheck/invalid_credentials_error"
|
16
|
+
require "bigid/bgcheck/invalid_document_value_error"
|
24
17
|
require "bigid/bgcheck/no_info_error"
|
25
18
|
require "bigid/bgcheck/server_error"
|
26
19
|
|
27
20
|
require "bigid/bgcheck/doc_type"
|
28
21
|
require "bigid/bgcheck/result"
|
29
22
|
require "bigid/bgcheck/result_code"
|
30
|
-
|
31
23
|
require "bigid/bgcheck/request"
|
32
24
|
|
33
25
|
module Bigid
|
34
26
|
module Bgcheck
|
35
|
-
|
36
|
-
AUTH_ENDPOINT = "https://accesstoken.bigdatacorp.com.br"
|
37
|
-
SRV_ENDPOINT = "backgroundcheck"
|
38
|
-
TOKEN_EXPIRATION = 60_000
|
27
|
+
SRV_ENDPOINT = "backgroundcheck"
|
39
28
|
|
40
29
|
class << self
|
41
30
|
attr_writer :configuration
|
@@ -52,19 +41,11 @@ module Bigid
|
|
52
41
|
end
|
53
42
|
|
54
43
|
class Configuration
|
55
|
-
attr_writer :username, :password
|
56
|
-
|
57
|
-
def username
|
58
|
-
@username ||= ENV["BIGID_USERNAME"]
|
59
|
-
end
|
60
|
-
|
61
|
-
def password
|
62
|
-
@password ||= ENV["BIGID_PASSWORD"]
|
63
|
-
end
|
64
44
|
end
|
65
45
|
|
66
46
|
I18n.load_path << Dir["#{File.expand_path('config/locales')}/*.yml"]
|
67
47
|
I18n.config.available_locales = :en, :'pt-BR'
|
68
48
|
I18n.default_locale = :en
|
49
|
+
I18n.reload!
|
69
50
|
end
|
70
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigid_bgcheck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danilo Carolino
|
@@ -10,6 +10,26 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2021-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bigid_auth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.0
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.1.0
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.1'
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: faraday
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,23 +247,14 @@ files:
|
|
227
247
|
- LICENSE.txt
|
228
248
|
- README.md
|
229
249
|
- Rakefile
|
230
|
-
- lib/bigid/bgcheck/auth/authenticated_connection.rb
|
231
|
-
- lib/bigid/bgcheck/auth/authenticated_resource.rb
|
232
|
-
- lib/bigid/bgcheck/auth/authentication.rb
|
233
|
-
- lib/bigid/bgcheck/auth/connection.rb
|
234
250
|
- lib/bigid/bgcheck/bad_request_error.rb
|
235
251
|
- lib/bigid/bgcheck/base_error.rb
|
236
252
|
- lib/bigid/bgcheck/doc_type.rb
|
237
253
|
- lib/bigid/bgcheck/document_not_supported_error.rb
|
238
|
-
- lib/bigid/bgcheck/integration/connection.rb
|
239
|
-
- lib/bigid/bgcheck/integration/multipart_flat.rb
|
240
|
-
- lib/bigid/bgcheck/integration/request.rb
|
241
|
-
- lib/bigid/bgcheck/integration/response.rb
|
242
254
|
- lib/bigid/bgcheck/internal_error.rb
|
243
255
|
- lib/bigid/bgcheck/invalid_credentials_error.rb
|
244
256
|
- lib/bigid/bgcheck/invalid_document_value_error.rb
|
245
257
|
- lib/bigid/bgcheck/no_info_error.rb
|
246
|
-
- lib/bigid/bgcheck/not_permission_error.rb
|
247
258
|
- lib/bigid/bgcheck/request.rb
|
248
259
|
- lib/bigid/bgcheck/result.rb
|
249
260
|
- lib/bigid/bgcheck/result_code.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bigid
|
4
|
-
module Bgcheck
|
5
|
-
module Auth
|
6
|
-
class AuthenticatedConnection < Connection
|
7
|
-
COOKIE_CACHE_KEY = "BIG_ID_AUTHENTICATION_COOKIE_CACHE_KEY"
|
8
|
-
|
9
|
-
def initialize(authentication: Bigid::Bgcheck::Auth::Authentication.new,
|
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)
|
14
|
-
super(request_class: request_class, base_url: base_url)
|
15
|
-
@authentication = authentication
|
16
|
-
@cache = cache
|
17
|
-
@token_expiration_time_in_seconds = token_expiration_time_in_seconds
|
18
|
-
end
|
19
|
-
|
20
|
-
def default_headers
|
21
|
-
super.merge(Authorization: (@cache ? cached_token : auth_token))
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
def auth_token
|
26
|
-
response = @authentication.login
|
27
|
-
extract_token(response.body)
|
28
|
-
end
|
29
|
-
|
30
|
-
def cached_token
|
31
|
-
@cache.fetch(COOKIE_CACHE_KEY, expires_in: @token_expiration_time_in_seconds.seconds) do
|
32
|
-
auth_token
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def extract_token(value)
|
37
|
-
raise Bigid::Bgcheck::AuthenticationError unless value
|
38
|
-
|
39
|
-
value_json = JSON.parse(value)
|
40
|
-
"Bearer #{value_json['token']}"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bigid
|
4
|
-
module Bgcheck
|
5
|
-
module Auth
|
6
|
-
class Authentication
|
7
|
-
def initialize(connection: Connection.new,
|
8
|
-
username: Bigid::Bgcheck.configuration.username,
|
9
|
-
password: Bigid::Bgcheck.configuration.password,
|
10
|
-
token_expiration_time_in_seconds: Bigid::Bgcheck::AUTH_ENDPOINT)
|
11
|
-
@connection = connection
|
12
|
-
@token_expiration_time_in_seconds = Bigid::Bgcheck::TOKEN_EXPIRATION
|
13
|
-
@username = username
|
14
|
-
@password = password
|
15
|
-
end
|
16
|
-
|
17
|
-
def login
|
18
|
-
res = @connection.post(url: "Generate", body: login_body)
|
19
|
-
|
20
|
-
return res if res.status == 200
|
21
|
-
|
22
|
-
raise Bigid::Bgcheck::InvalidCredentialsError if res.status == 401
|
23
|
-
raise Bigid::Bgcheck::BadRequestError if res.status == 400
|
24
|
-
raise Bigid::Bgcheck::ServerError if res.status == 500
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
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
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bigid
|
4
|
-
module Bgcheck
|
5
|
-
module Auth
|
6
|
-
class Connection < Bigid::Bgcheck::Integration::Connection
|
7
|
-
def initialize(request_class: Faraday, base_url: Bigid::Bgcheck::AUTH_ENDPOINT)
|
8
|
-
super(request_class: request_class, base_url: base_url)
|
9
|
-
end
|
10
|
-
|
11
|
-
def default_headers
|
12
|
-
{
|
13
|
-
'Content-Type': "application/json",
|
14
|
-
'Accept': "application/json"
|
15
|
-
}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bigid
|
4
|
-
module Bgcheck
|
5
|
-
module Integration
|
6
|
-
class Connection
|
7
|
-
attr_reader :base_url
|
8
|
-
|
9
|
-
def initialize(base_url:, request_class: Faraday)
|
10
|
-
@request_class = request_class
|
11
|
-
@base_url = base_url
|
12
|
-
end
|
13
|
-
|
14
|
-
def get(url: "", params: {}, headers: {})
|
15
|
-
send_request(
|
16
|
-
method: :get,
|
17
|
-
url: url,
|
18
|
-
params: params,
|
19
|
-
headers: headers
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
|
-
def post(url: "", params: {}, headers: {}, body: {}, multipart: false)
|
24
|
-
send_request(
|
25
|
-
method: :post,
|
26
|
-
url: url,
|
27
|
-
params: params,
|
28
|
-
headers: headers,
|
29
|
-
body: body,
|
30
|
-
multipart: multipart
|
31
|
-
)
|
32
|
-
end
|
33
|
-
|
34
|
-
def put(url: "", params: {}, headers: {}, body: {})
|
35
|
-
send_request(
|
36
|
-
method: :put,
|
37
|
-
url: url,
|
38
|
-
params: params,
|
39
|
-
headers: headers,
|
40
|
-
body: body
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
|
-
def patch(url: "", params: {}, headers: {}, body: {})
|
45
|
-
send_request(
|
46
|
-
method: :patch,
|
47
|
-
url: url,
|
48
|
-
params: params,
|
49
|
-
headers: headers,
|
50
|
-
body: body
|
51
|
-
)
|
52
|
-
end
|
53
|
-
|
54
|
-
def delete(url: "", params: {}, headers: {}, body: {})
|
55
|
-
send_request(
|
56
|
-
method: :delete,
|
57
|
-
url: url,
|
58
|
-
params: params,
|
59
|
-
headers: headers,
|
60
|
-
body: body
|
61
|
-
)
|
62
|
-
end
|
63
|
-
|
64
|
-
def default_headers
|
65
|
-
{}
|
66
|
-
end
|
67
|
-
|
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)
|
71
|
-
|
72
|
-
merged_headers = default_headers.merge(headers)
|
73
|
-
|
74
|
-
request = build_request(
|
75
|
-
method, connection.build_url(url).to_s, params, merged_headers, body
|
76
|
-
)
|
77
|
-
|
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
|
85
|
-
|
86
|
-
build_response(request, result.status, result.headers, result.body)
|
87
|
-
end
|
88
|
-
|
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
|
95
|
-
end
|
96
|
-
|
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
|
107
|
-
|
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
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bigid
|
4
|
-
module Bgcheck
|
5
|
-
module Integration
|
6
|
-
class MultipartFlat < Faraday::Request::Multipart
|
7
|
-
self.mime_type = "multipart/form-data"
|
8
|
-
DEFAULT_BOUNDARY_PREFIX = "-----------RubyMultipartPost" unless defined? DEFAULT_BOUNDARY_PREFIX
|
9
|
-
|
10
|
-
def process_params(params, prefix = nil, pieces = nil, &block)
|
11
|
-
params.inject(pieces || []) do |all, (key, value)|
|
12
|
-
key = prefix.to_s if prefix
|
13
|
-
|
14
|
-
case value
|
15
|
-
when Array
|
16
|
-
values = value.inject([]) { |a, v| a << [nil, v] }
|
17
|
-
process_params(values, key, all, &block)
|
18
|
-
when Hash
|
19
|
-
process_params(value, key, all, &block)
|
20
|
-
else
|
21
|
-
all << block.call(key, value)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bigid
|
4
|
-
module Bgcheck
|
5
|
-
module Integration
|
6
|
-
class Request
|
7
|
-
attr_reader :method, :url, :params, :headers, :body, :time
|
8
|
-
|
9
|
-
def initialize(attributes)
|
10
|
-
@method = attributes.fetch(:method)
|
11
|
-
@url = attributes.fetch(:url)
|
12
|
-
@params = attributes[:params] || {}
|
13
|
-
@headers = attributes[:headers] || {}
|
14
|
-
@body = attributes[:body] || {}
|
15
|
-
@time = attributes[:time] || Time.current
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bigid
|
4
|
-
module Bgcheck
|
5
|
-
module Integration
|
6
|
-
class Response
|
7
|
-
attr_reader :request, :status, :headers, :body, :time
|
8
|
-
|
9
|
-
def initialize(attributes)
|
10
|
-
@request = attributes.fetch(:request)
|
11
|
-
@status = attributes.fetch(:status)
|
12
|
-
@headers = attributes[:headers] || {}
|
13
|
-
@body = attributes[:body] || {}
|
14
|
-
@time = attributes[:time] || Time.current
|
15
|
-
end
|
16
|
-
|
17
|
-
def success?
|
18
|
-
@status.between?(200, 299)
|
19
|
-
end
|
20
|
-
|
21
|
-
def error?
|
22
|
-
!success?
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|