bigid_bgcheck 0.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +21 -20
  5. data/Rakefile +1 -1
  6. data/lib/bigid/bgcheck/request.rb +8 -4
  7. data/lib/bigid/bgcheck/result.rb +14 -8
  8. data/lib/bigid/bgcheck/version.rb +1 -1
  9. data/lib/bigid_bgcheck.rb +20 -41
  10. data/lib/locales/en.yml +17 -0
  11. data/lib/locales/pt-BR.yml +17 -0
  12. data/spec/bigid/bgcheck/bad_request_error_spec.rb +7 -0
  13. data/spec/bigid/bgcheck/base_error_spec.rb +7 -0
  14. data/spec/{lib → bigid}/bgcheck/doc_type_spec.rb +0 -1
  15. data/spec/bigid/bgcheck/document_not_supported_error_spec.rb +7 -0
  16. data/spec/bigid/bgcheck/internal_error_spec.rb +7 -0
  17. data/spec/bigid/bgcheck/invalid_credentials_error_spec.rb +7 -0
  18. data/spec/bigid/bgcheck/invalid_document_value_error_spec.rb +7 -0
  19. data/spec/bigid/bgcheck/no_info_error_spec.rb +7 -0
  20. data/spec/bigid/bgcheck/request_spec.rb +99 -0
  21. data/spec/{lib → bigid}/bgcheck/result_code_spec.rb +0 -1
  22. data/spec/bigid/bgcheck/server_error_spec.rb +7 -0
  23. data/spec/bigid_bgcheck_spec.rb +4 -23
  24. data/spec/factories/result.rb +45 -0
  25. data/spec/spec_helper.rb +29 -7
  26. data/spec/support/shared_examples/errors_shared_examples.rb +53 -0
  27. metadata +83 -45
  28. data/lib/bigid/bgcheck/auth/authenticated_connection.rb +0 -45
  29. data/lib/bigid/bgcheck/auth/authenticated_resource.rb +0 -13
  30. data/lib/bigid/bgcheck/auth/authentication.rb +0 -38
  31. data/lib/bigid/bgcheck/auth/connection.rb +0 -20
  32. data/lib/bigid/bgcheck/integration/connection.rb +0 -120
  33. data/lib/bigid/bgcheck/integration/multipart_flat.rb +0 -28
  34. data/lib/bigid/bgcheck/integration/request.rb +0 -20
  35. data/lib/bigid/bgcheck/integration/response.rb +0 -27
  36. 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: b0e56b8286ff8c62b9e3fc0e4b4c147df0737c1bf8af5d32ac6c12fb162ba1cd
4
- data.tar.gz: cc0203dfb074f3960d6c96ed832279f8d07e52927fbb3f6880219d502b96403f
3
+ metadata.gz: d94fea79e3d064b136018dea55150a1839ce25218b82054626a1c32e05495961
4
+ data.tar.gz: 55164f99a7d2804515214a8b7db4610e04d5a1a0270bf94c2f8da188534206a5
5
5
  SHA512:
6
- metadata.gz: e7cc45959661c9cb9d62d1237253544af5545454b8de12047d824968cdf7b76c36752b8b12b7ab4d70205c669ba6b749813a3ae40b226b6473fc1afcf60dbce4
7
- data.tar.gz: a2f88c24add0312d6e2871432ead1c5eba93d8cca6fe4ebfea966c0ca751a9e320686e4d8b1261a6dc65031de8a0fc17c65e403ead78b9dcac300429f5ec4e40
6
+ metadata.gz: b2a7bc286c6fabb63e6524c8882923414c7e940016fc9952fd2dd6f6484e6518df3ab910e4df21f205b957def7bbb698fbdfedd58bb7ade69671b251335d3026
7
+ data.tar.gz: 7f4218efcdff8cffacee26fbce626d3d14339f776fe0017657ef9b254157ce7e4a1c75e2c4db8467bc3baf760ffb48241838317cb730b00d6532917aad6f50c3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # CHANGELOG for bigid_bgcheck
2
2
 
3
+ ## v0.3.0
4
+
5
+ * Bump "bigid_auth" version from v0.1.0 to v0.2.0
6
+
7
+ ## v0.2.0
8
+
9
+ Features
10
+
11
+ * Add fields to service return: "raw_data", "score_details", "related_score_details" and "raw_response" (the complete json file)
12
+
13
+ ## v0.1.3
14
+
15
+ * Fix a problem with the locale initialization in Rails projects
16
+
17
+ ## v0.1.2
18
+
19
+ * Move auth service to an external package
20
+
3
21
  ## v0.1.1
4
22
 
5
23
  * Fix a problem with the credentials when its get by the env variables
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2021 Danilo Carolino
1
+ Copyright (c) 2021 Quasar Flash
2
2
 
3
3
  MIT LICENSE
4
4
 
data/README.md CHANGED
@@ -3,19 +3,19 @@ BigId Background Check's Library for Ruby
3
3
 
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
+ [![bigid_bgcheck](https://github.com/Quasar-Flash/bigid-bgcheck-ruby/actions/workflows/ruby.yml/badge.svg)](https://github.com/Quasar-Flash/bigid-bgcheck-ruby/actions/workflows/ruby.yml)
6
7
 
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
8
+ Requirements
14
9
  -----------------
15
10
 
16
11
  - Ruby: Any version
17
12
  - Bundler
18
13
 
14
+ Included Modules
15
+ -----------------
16
+
17
+ - [bigid-auth-ruby](https://github.com/Quasar-Flash/bigid-auth-ruby) - BigID API authentication module
18
+
19
19
  Global Installation
20
20
  -----------------
21
21
 
@@ -25,35 +25,36 @@ Installation for Rails
25
25
  -----------------
26
26
 
27
27
  # Add to the Gemfile
28
- gem 'bigid_bgcheck', '~> 0.1.0'
28
+ gem "bigid_bgcheck", "~> 0.2"
29
+ gem "bigid_bgcheck", github: "Quasar-Flash/bigid-bgcheck-ruby"
29
30
 
30
31
  Setting the BigID credentials
31
32
  -----------------
32
33
 
33
34
  # Set the env variables
34
- ENV['BIGID_USERNAME'] = 'your_username'
35
- ENV['BIGID_PASSWORD'] = 'your_password'
35
+ ENV["BIGID_USERNAME"] = "your_username"
36
+ ENV["BIGID_PASSWORD"] = "your_password"
36
37
 
37
38
  Setting the BigID credentials - Rails Project
38
39
  -----------------
39
40
 
40
- Create the config/initializers/bigid_bgcheck.rb file and define:
41
+ Create the config/initializers/bigid.rb file and define:
41
42
 
42
43
  # Set the env variables
43
- Bigid::Bgcheck.configure do |config|
44
- config.username = 'your_username'
45
- config.password = 'your_password'
44
+ Bigid.configure do |config|
45
+ config.username = "your_username"
46
+ config.password = "your_password"
46
47
  end
47
48
 
48
49
  Applying a background check
49
50
  -----------------
50
51
 
51
- require 'bigid_bgcheck'
52
+ require "bigid_bgcheck"
52
53
 
53
54
  Bigid::Bgcheck::Request.new.call(
54
- document: '000.000.000-00',
55
- document_type: 'CPF',
56
- group: 'Default'
55
+ document: "000.000.000-00",
56
+ document_type: "CPF",
57
+ group: "Default"
57
58
  )
58
59
 
59
60
  Result Example
@@ -77,8 +78,8 @@ Searching the [issues](https://github.com/Quasar-Flash/bigid-bgcheck-ruby/issues
77
78
  Contributing
78
79
  -----------------
79
80
 
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;
81
+ - Check out the latest master to make sure the feature hasn"t been implemented or the bug hasn't been fixed yet;
82
+ - Check out the issue tracker to make sure someone already hasn"t requested it and/or contributed it;
82
83
  - Fork the project;
83
84
  - Start a feature/bugfix branch;
84
85
  - Commit and push until you are happy with your contribution;
data/Rakefile CHANGED
@@ -45,4 +45,4 @@ rescue LoadError
45
45
  # no rspec available
46
46
  end
47
47
 
48
- task default: %i[rubocop ]
48
+ task default: %i[rubocop spec]
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Bigid
4
4
  module Bgcheck
5
- class Request < Bigid::Bgcheck::Auth::AuthenticatedResource
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::Bgcheck.configuration.username
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)
@@ -47,11 +47,15 @@ module Bigid
47
47
 
48
48
  Bigid::Bgcheck::Result.new(
49
49
  approved: ResultCode.approved?(body["ResultCode"]),
50
- ticket_id: body["TicketId"],
51
50
  code: body["ResultCode"],
51
+ score_details: body["ScoreDetails"],
52
+ limit_score: body["LimitScore"],
52
53
  message: body["ResultMessage"],
54
+ raw_data: body["RawData"],
55
+ raw_response: body.to_json,
56
+ related_score_details: body["RelatedScoreDetails"],
53
57
  score: body["Score"],
54
- limit_score: body["LimitScore"]
58
+ ticket_id: body["TicketId"]
55
59
  )
56
60
  end
57
61
  end
@@ -3,15 +3,21 @@
3
3
  module Bigid
4
4
  module Bgcheck
5
5
  class Result
6
- attr_accessor :approved, :ticket_id, :code, :message, :score, :limit_score
6
+ attr_accessor :approved, :code, :score_details, :limit_score, :message, :raw_data,
7
+ :raw_response, :related_score_details, :score, :ticket_id
7
8
 
8
- def initialize(approved:, ticket_id:, code:, message:, score:, limit_score:)
9
- @approved = approved
10
- @ticket_id = ticket_id
11
- @code = code
12
- @message = message
13
- @score = score
14
- @limit_score = limit_score
9
+ def initialize(approved:, code:, score_details:, limit_score:, message:, raw_data:, raw_response:,
10
+ related_score_details:, score:, ticket_id:)
11
+ @approved = approved
12
+ @code = code
13
+ @score_details = score_details
14
+ @limit_score = limit_score
15
+ @message = message
16
+ @raw_data = raw_data
17
+ @raw_response = raw_response
18
+ @related_score_details = related_score_details
19
+ @score = score
20
+ @ticket_id = ticket_id
15
21
  end
16
22
  end
17
23
  end
@@ -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.1"
12
+ VERSION = "0.3.0"
13
13
  end
14
14
  end
data/lib/bigid_bgcheck.rb CHANGED
@@ -1,70 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "faraday"
4
3
  require "i18n"
5
4
  require "json"
5
+ require "cpf_cnpj"
6
6
 
7
- require "bigid/bgcheck/version"
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/auth/connection"
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
- module Bigid
34
- module Bgcheck
35
- BASE_URL = "https://bigid.bigdatacorp.com.br"
36
- AUTH_ENDPOINT = "https://accesstoken.bigdatacorp.com.br"
37
- SRV_ENDPOINT = "backgroundcheck"
38
- TOKEN_EXPIRATION = 60_000
25
+ I18n.load_path += Dir[File.join(__dir__, "locales", "**/*.yml")]
26
+ I18n.reload! if I18n.backend.initialized?
39
27
 
40
- class << self
41
- attr_writer :configuration
42
-
43
- def configuration
44
- @configuration ||= Configuration.new
45
- end
46
- end
47
-
48
- def self.configure
49
- self.configuration ||= Configuration.new
28
+ module Bigid
29
+ class << self
30
+ attr_writer :configuration
50
31
 
51
- yield(configuration)
32
+ def configuration
33
+ @configuration ||= Configuration.new
52
34
  end
35
+ end
53
36
 
54
- class Configuration
55
- attr_writer :username, :password
37
+ def self.configure
38
+ self.configuration ||= Configuration.new
56
39
 
57
- def username
58
- @username ||= ENV["BIGID_USERNAME"]
59
- end
40
+ yield(configuration)
41
+ end
60
42
 
61
- def password
62
- @password ||= ENV["BIGID_PASSWORD"]
63
- end
64
- end
43
+ class Configuration
44
+ end
65
45
 
66
- I18n.load_path << Dir["#{File.expand_path('config/locales')}/*.yml"]
67
- I18n.config.available_locales = :en, :'pt-BR'
68
- I18n.default_locale = :en
46
+ module Bgcheck
47
+ SRV_ENDPOINT = "backgroundcheck"
69
48
  end
70
49
  end
@@ -0,0 +1,17 @@
1
+ en:
2
+ errors:
3
+ bigid:
4
+ auth:
5
+ authentication_error: An error ocurred during the authentication
6
+ bad_request_error: The request body or format is invalid
7
+ invalid_credentials_error: The credentials informed are invalid
8
+ server_error: An internal server error ocurred
9
+ bgcheck:
10
+ bad_request_error: The request body or format is invalid
11
+ document_not_supported_error: The document type is not supported
12
+ internal_error: An internal error on the BigId server ocurred
13
+ invalid_document_value_error: The document value is invalid
14
+ invalid_credentials_error: The credentials informed are invalid
15
+ no_info_error: No informations available
16
+ not_permission_error: Action not allowed
17
+ server_error: An internal server error ocurred
@@ -0,0 +1,17 @@
1
+ 'pt-BR':
2
+ errors:
3
+ bigid:
4
+ auth:
5
+ authentication_error: Ocorreu um erro durante a autenticação
6
+ bad_request_error: O corpo ou formato da requisição é inválido
7
+ invalid_credentials_error: As credenciais informadas são inválidas
8
+ server_error: Ocorreu um erro inesperado no servidor
9
+ bgcheck:
10
+ bad_request_error: O corpo ou formato da requisição é inválido
11
+ document_not_supported_error: O tipo de documento é inválido
12
+ internal_error: Ocorreu um erro ao verificar a pessoa no BigId
13
+ invalid_document_value_error: O valor do documento é inválido
14
+ invalid_credentials_error: As credenciais informadas são inválidas
15
+ no_info_error: Sem informações disponíveis
16
+ not_permission_error: Ação não permitida
17
+ server_error: Ocorreu um erro inesperado no servidor
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Bigid::Bgcheck::BadRequestError do
6
+ include_examples "error"
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Bigid::Bgcheck::BaseError do
6
+ include_examples "error"
7
+ end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "spec_helper"
4
- require "bigid/bgcheck/doc_type"
5
4
 
6
5
  RSpec.describe Bigid::Bgcheck::DocType do
7
6
  describe ".valid?(document_type)" do
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Bigid::Bgcheck::DocumentNotSupportedError do
6
+ include_examples "error"
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Bigid::Bgcheck::InternalError do
6
+ include_examples "http_error"
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Bigid::Bgcheck::InvalidCredentialsError do
6
+ include_examples "error"
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Bigid::Bgcheck::InvalidDocumentValueError do
6
+ include_examples "error"
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Bigid::Bgcheck::NoInfoError do
6
+ include_examples "http_error"
7
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Bigid::Bgcheck::Request do
6
+ describe "#call" do
7
+ let(:connection) { instance_double(Bigid::Auth::AuthenticatedConnection) }
8
+ let(:body) {
9
+ {
10
+ Login: "username_value",
11
+ parameters: { CNPJ: document },
12
+ Group: group
13
+ }.to_json
14
+ }
15
+ let(:success_result) { build(:result, :approved) }
16
+ let(:success_result_response) {
17
+ JSON.parse({
18
+ body: {
19
+ RawData: success_result.raw_data,
20
+ ScoreDetails: success_result.score_details,
21
+ RelatedScoreDetails: success_result.related_score_details,
22
+ LimitScore: success_result.limit_score,
23
+ ResultCode: success_result.code,
24
+ ResultMessage: success_result.message,
25
+ Score: success_result.score,
26
+ TicketId: success_result.ticket_id
27
+ }.to_json,
28
+ status: request_status
29
+ }.to_json, object_class: OpenStruct)
30
+ }
31
+ let(:document) { CNPJ.generate }
32
+ let(:document_type) { "CNPJ" }
33
+ let(:group) { "Default" }
34
+ let(:request_status) { 200 }
35
+
36
+ subject { described_class.new.call(document: document, document_type: document_type, group: group) }
37
+
38
+ before do
39
+ allow(Bigid::Auth::AuthenticatedConnection).to receive(:new).and_return(connection)
40
+ allow(connection).to receive(:post).and_return(success_result_response)
41
+ end
42
+
43
+ describe ".call" do
44
+ subject { described_class.call(document: document, document_type: document_type, group: group) }
45
+
46
+ it { expect(subject).to be_kind_of(Bigid::Bgcheck::Result) }
47
+
48
+ it { subject; expect(connection).to have_received(:post) }
49
+ end
50
+
51
+ context "when all parameters are valid" do
52
+ it { expect(subject).to be_kind_of(Bigid::Bgcheck::Result) }
53
+
54
+ it { subject; expect(connection).to have_received(:post) }
55
+ end
56
+
57
+ context "when document type is invalid" do
58
+ let(:document_type) { "CNP" }
59
+
60
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::DocumentNotSupportedError) }
61
+ end
62
+
63
+ context "when request status is null" do
64
+ let(:request_status) { nil }
65
+
66
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::InternalError) }
67
+ end
68
+
69
+ context "when request status is server error" do
70
+ let(:request_status) { 500 }
71
+
72
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::ServerError) }
73
+ end
74
+
75
+ context "when request status is auth error" do
76
+ let(:request_status) { 401 }
77
+
78
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::InvalidCredentialsError) }
79
+ end
80
+
81
+ context "when request status is bad request" do
82
+ let(:request_status) { 400 }
83
+
84
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::BadRequestError) }
85
+ end
86
+
87
+ context "when the result code is empty" do
88
+ let(:success_result) { build(:result, :approved, code: nil) }
89
+
90
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::InvalidDocumentValueError) }
91
+ end
92
+
93
+ context "when the result code is empty" do
94
+ let(:success_result) { build(:result, :approved, code: Bigid::Bgcheck::ResultCode::NO_INFO) }
95
+
96
+ it { expect { subject }.to raise_error(Bigid::Bgcheck::NoInfoError) }
97
+ end
98
+ end
99
+ end