zaig 1.0.6 → 1.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab0151c32beb57d31bb2e3ccd10ff6408091c79c61dbbb9f85b03fed94b6498b
4
- data.tar.gz: dc88f4a1dbb7601abddeb3c8812948a1f3c6b9633d1b6899168530831b125b4b
3
+ metadata.gz: 8772408f0511d1fe3a5de65ddf6344af3d32754bdb7ce95252a05cb3e3cb144c
4
+ data.tar.gz: d01ca6b7f88430671f09a61a1af872650438113fac5bce59aa74838808b267cc
5
5
  SHA512:
6
- metadata.gz: 12d241a7a4b5124573f7b45d5a5818075fe45b117bce2ee3d21b404c009eeb9d2f4dbeeff52f6386841c204b568b71811cad6376f23295876645a9a011fd9a1c
7
- data.tar.gz: d761bbadde669244ad80a1644d31350796f2d1e77ea6d2e01b29cf243b7f691f26d28a49675f37567a74a5d88d1c23403fbaa42044b49afbef2121aa918885aa
6
+ metadata.gz: bacc2f06a07747edfff29022645d937cca069244b7857604bcebb0926578a498a3224c62153e8b5d18d40bc5754ed61dc29701db2bae3cab247db95b73cee06d
7
+ data.tar.gz: f1d7438aae92727b67056b38ddea0e39760ecc9ae925883682faed8b5ef4740cbdc0d9fd5b691740087b72b4555b95e0f45c915658ba8e14eb7f0d9450b06bf2
@@ -3,18 +3,30 @@
3
3
  module Zaig
4
4
  # Class to instance a authenticated connection object.
5
5
  class Connection < Flash::Integration::Connection
6
- def initialize(request_class: Faraday, base_url: Zaig.configuration.base_url, access_token: Zaig.configuration.access_token)
7
- @access_token = access_token
6
+ def initialize(request_class: Faraday, base_url: Zaig.configuration.base_url)
7
+ @jwt_algorithm = Zaig.configuration.jwt_algorithm
8
+ @jwt_exp_time = Zaig.configuration.jwt_exp_time
9
+ @jwt_secret = Zaig.configuration.jwt_secret
10
+ @jwt_user = Zaig.configuration.jwt_user
8
11
 
9
12
  super(request_class: request_class, base_url: base_url)
10
13
  end
11
14
 
12
15
  def default_headers
13
- {
16
+ headers = {
14
17
  "Content-Type": "application/json",
15
- Accept: "application/json",
16
- "x-api-key": @access_token
18
+ Accept: "application/json"
17
19
  }
20
+
21
+ return headers if @jwt_secret.nil? || @jwt_secret.empty?
22
+
23
+ headers[:Authorization] = "Bearer #{access_token}"
24
+ headers
18
25
  end
26
+
27
+ private
28
+ def access_token
29
+ JWT.encode({ exp: @jwt_exp_time, user: @jwt_user }, @jwt_secret, @jwt_algorithm)
30
+ end
19
31
  end
20
32
  end
@@ -17,9 +17,7 @@ module Zaig
17
17
  def call(obj)
18
18
  payload = @registration_payload.call(obj)
19
19
 
20
- req_endpoint = Zaig.configuration.registration_endpoint
21
-
22
- res = @connection.post(url: (req_endpoint.nil? ? ENDPOINT : req_endpoint), body: payload.to_json)
20
+ res = @connection.post(url: Zaig.configuration.registration_endpoint, body: payload.to_json)
23
21
 
24
22
  verify_response(res)
25
23
 
data/lib/zaig/version.rb CHANGED
@@ -8,5 +8,5 @@ module Zaig
8
8
  # Major - Incremented for incompatible changes with previous release (or big enough new features)
9
9
  # Minor - Incremented for new backwards-compatible features + deprecations
10
10
  # Patch - Incremented for backwards-compatible bug fixes
11
- VERSION = "1.0.6"
11
+ VERSION = "1.0.7"
12
12
  end
data/lib/zaig.rb CHANGED
@@ -48,6 +48,19 @@ module Zaig
48
48
 
49
49
  # Basic configuration settings
50
50
  class Configuration
51
- attr_accessor :access_token, :base_url, :registration_endpoint
51
+ attr_accessor :base_url, :jwt_secret, :jwt_user
52
+ attr_writer :jwt_algorithm, :jwt_exp_time, :registration_endpoint
53
+
54
+ def jwt_algorithm
55
+ @jwt_algorithm ||= "HS256"
56
+ end
57
+
58
+ def jwt_exp_time
59
+ @jwt_exp_time ||= 1_658_439_475
60
+ end
61
+
62
+ def registration_endpoint
63
+ @registration_endpoint ||= "zaig/consulta_de_credito"
64
+ end
52
65
  end
53
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaig
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Carolino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-19 00:00:00.000000000 Z
11
+ date: 2022-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cpf_cnpj
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jwt
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: singleton
43
57
  requirement: !ruby/object:Gem::Requirement