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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 061bab2e6ded3cddad6973dca46452ac88a24b5930ad9d774a1dcd6b33b26a1e
4
- data.tar.gz: 95de36d25c4b50fb8680917b9dd2bef2f9fc3c74fa27ce238f9f250859130cfd
3
+ metadata.gz: b0e56b8286ff8c62b9e3fc0e4b4c147df0737c1bf8af5d32ac6c12fb162ba1cd
4
+ data.tar.gz: cc0203dfb074f3960d6c96ed832279f8d07e52927fbb3f6880219d502b96403f
5
5
  SHA512:
6
- metadata.gz: 354a23277c46fab26ca4982b0ce52335249ea0305cfd49166e506e7b2c06bf3eb9d455ee9ca7c2683936b83ed1cd191af51c8d3a4012d855551fdc21b0a591c0
7
- data.tar.gz: febce1e53fa05ab98ef4ad058a0331a5f0f90247094734378eafb8ed288e1aa6c80d6dec442883d868d614f6a288b23d0066bb0542660a76ac5ef91941e3d137
6
+ metadata.gz: e7cc45959661c9cb9d62d1237253544af5545454b8de12047d824968cdf7b76c36752b8b12b7ab4d70205c669ba6b749813a3ae40b226b6473fc1afcf60dbce4
7
+ data.tar.gz: a2f88c24add0312d6e2871432ead1c5eba93d8cca6fe4ebfea966c0ca751a9e320686e4d8b1261a6dc65031de8a0fc17c65e403ead78b9dcac300429f5ec4e40
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG for bigid_bgcheck
2
2
 
3
+ ## v0.1.1
4
+
5
+ * Fix a problem with the credentials when its get by the env variables
6
+ * Fix rubocop warnings
7
+
3
8
  ## v0.1.0
4
9
 
5
10
  * Initial release of bigid_bgcheck
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 'bundler/setup'
5
+ require "bundler/setup"
4
6
  rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
6
8
  end
9
+
7
10
  begin
8
- require 'rdoc/task'
11
+ require "rdoc/task"
9
12
  rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
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 = 'rdoc'
17
- rdoc.title = 'bigid_bgcheck'
18
- rdoc.options << '--line-numbers'
19
- rdoc.rdoc_files.include('README.rdoc')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
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
- require "rake/testtask"
40
+ begin
41
+ require "rspec/core/rake_task"
30
42
 
31
- Rake::TestTask.new(:spec) do |t|
32
- t.libs << 'lib'
33
- t.libs << 'spec'
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 :default => :spec
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 = 'BIG_ID_AUTHENTICATION_COOKIE_CACHE_KEY'.freeze
7
+ COOKIE_CACHE_KEY = "BIG_ID_AUTHENTICATION_COOKIE_CACHE_KEY"
6
8
 
7
9
  def initialize(authentication: Bigid::Bgcheck::Auth::Authentication.new,
8
- cache: defined?(Rails) ? Rails.cache : nil,
9
- request_class: Faraday,
10
- base_url: Bigid::Bgcheck::BASE_URL,
11
- token_expiration_time_in_seconds: Bigid::Bgcheck::TOKEN_EXPIRATION)
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
- def auth_token
25
- response = @authentication.login
26
- extract_token(response.body)
27
- end
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
- def extract_token(value)
36
- raise Bigid::Bgcheck::AuthenticationError unless value
36
+ def extract_token(value)
37
+ raise Bigid::Bgcheck::AuthenticationError unless value
37
38
 
38
- value_json = JSON.parse(value)
39
- "Bearer #{value_json['token']}"
40
- end
39
+ value_json = JSON.parse(value)
40
+ "Bearer #{value_json['token']}"
41
+ end
41
42
  end
42
43
  end
43
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bigid
2
4
  module Bgcheck
3
5
  module Auth
@@ -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
- username: Bigid::Bgcheck.configuration&.username,
7
- password: Bigid::Bgcheck.configuration&.password,
8
- token_expiration_time_in_seconds: Bigid::Bgcheck::AUTH_ENDPOINT)
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 ? username : ENV['BIGID_USERNAME']
12
- @password = password ? password : ENV['BIGID_PASSWORD']
13
+ @username = username
14
+ @password = password
13
15
  end
14
16
 
15
17
  def login
16
- res = @connection.post(url: 'Generate', body: login_body)
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
- def login_body
28
- {
29
- login: @username,
30
- password: @password,
31
- expires: @token_expiration_time_in_seconds.to_i
32
- }.to_json
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': 'application/json',
12
- 'Accept': 'application/json'
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 BadRequestError < BaseError
@@ -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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bigid
2
4
  module Bgcheck
3
5
  class DocumentNotSupportedError < BaseError
@@ -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, base_url:)
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: '', params: {}, headers: {})
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: '', params: {}, headers: {}, body: {}, multipart: false)
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: '', params: {}, headers: {}, body: {})
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: '', params: {}, headers: {}, body: {})
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: '', params: {}, headers: {}, body: {})
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
- def send_request(method:, url:, params:, headers:, body: nil, multipart: false)
69
- connection = multipart ? multipart_connection : @request_class.new(url: @base_url)
72
+ merged_headers = default_headers.merge(headers)
70
73
 
71
- merged_headers = default_headers.merge(headers)
74
+ request = build_request(
75
+ method, connection.build_url(url).to_s, params, merged_headers, body
76
+ )
72
77
 
73
- request = build_request(
74
- method, connection.build_url(url).to_s, params, merged_headers, body
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
- result =
78
- connection.send(method) do |request|
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
- def multipart_connection
89
- @request_class.new(url: @base_url) do |conn|
90
- conn.use Bigid::Bgcheck::Integration::MultipartFlat
91
- conn.request :url_encoded
92
- conn.adapter @request_class.default_adapter
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
- def build_request(method, url, params, headers, body)
97
- Bigid::Bgcheck::Integration::Request.new(
98
- method: method,
99
- url: url,
100
- params: params,
101
- headers: headers,
102
- body: body,
103
- time: Time.now.utc
104
- )
105
- end
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
- def build_response(request, status, headers, body)
108
- Bigid::Bgcheck::Integration::Response.new(
109
- request: request,
110
- status: status,
111
- headers: headers,
112
- body: body,
113
- time: Time.now.utc
114
- )
115
- end
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