zaig 1.0.5 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zaig/already_exists_error.rb +1 -1
- data/lib/zaig/connection.rb +17 -5
- data/lib/zaig/external_timeout_error.rb +1 -1
- data/lib/zaig/field_validation_error.rb +1 -1
- data/lib/zaig/registration.rb +11 -11
- data/lib/zaig/registration_payload.rb +20 -11
- data/lib/zaig/server_error.rb +1 -1
- data/lib/zaig/server_timeout_error.rb +1 -1
- data/lib/zaig/unexpected_error.rb +1 -1
- data/lib/zaig/unprocessable_entity_error.rb +1 -1
- data/lib/zaig/validation_error.rb +1 -1
- data/lib/zaig/version.rb +1 -1
- data/lib/zaig.rb +15 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05cec7da728cfbfdf5457960a2d289e4963d22874f9790e12408eb2498aff1de
|
4
|
+
data.tar.gz: 1b73d0fe9a384e2bb73dd6af74939117329142fa9bf9aa27eeb28ccca5af2f95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f5c7152922f7a0823b805ad584986ed2c4b2f86484b5ca1f0c5544960cc15a20cbc48a1c0c299eb7b8e226a09d61eb74b5915a928fc4492876b0d7ca8fe4443
|
7
|
+
data.tar.gz: fa24fdd51580ef3a9f64bc02eda165e2c928fbc087b8595b5570324657e2509def4a510f84ca3452f0b54e24dd15c58ba44a01a9bd41e0a85e780ec8a88944a0
|
data/lib/zaig/connection.rb
CHANGED
@@ -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
|
7
|
-
@
|
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
|
data/lib/zaig/registration.rb
CHANGED
@@ -17,9 +17,7 @@ module Zaig
|
|
17
17
|
def call(obj)
|
18
18
|
payload = @registration_payload.call(obj)
|
19
19
|
|
20
|
-
|
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
|
|
@@ -50,13 +48,15 @@ module Zaig
|
|
50
48
|
unless parsed_res.key?(:resposta_zaig)
|
51
49
|
detail = JSON.parse(res.body, symbolize_names: true)[:detail]
|
52
50
|
|
53
|
-
error = ::Zaig::FieldValidationError.new I18n.t("zaig.errors.validation_error"
|
54
|
-
error.detail =
|
51
|
+
error = ::Zaig::FieldValidationError.new I18n.t("zaig.errors.validation_error")
|
52
|
+
error.detail = detail
|
55
53
|
|
56
54
|
raise error
|
57
55
|
end
|
58
56
|
|
59
|
-
|
57
|
+
title = parsed_res[:resposta_zaig][:conteudo][:title]
|
58
|
+
description = parsed_res[:resposta_zaig][:conteudo][:description]
|
59
|
+
zaig_msg = "#{title}: #{description}"
|
60
60
|
zaig_http_status = parsed_res[:resposta_zaig][:status]
|
61
61
|
|
62
62
|
raise_error_by_zaig_status(zaig_msg, zaig_http_status)
|
@@ -65,15 +65,15 @@ module Zaig
|
|
65
65
|
def raise_error_by_zaig_status(msg, status)
|
66
66
|
case status
|
67
67
|
when 400
|
68
|
-
raise ::Zaig::FieldValidationError
|
68
|
+
raise ::Zaig::FieldValidationError.new msg
|
69
69
|
when 408
|
70
|
-
raise ::Zaig::ExternalTimeoutError
|
70
|
+
raise ::Zaig::ExternalTimeoutError.new msg
|
71
71
|
when 409
|
72
|
-
raise ::Zaig::AlreadyExistsError
|
72
|
+
raise ::Zaig::AlreadyExistsError.new msg
|
73
73
|
when 422
|
74
|
-
raise ::Zaig::UnprocessableEntityError
|
74
|
+
raise ::Zaig::UnprocessableEntityError.new msg
|
75
75
|
else
|
76
|
-
raise ::Zaig::UnexpectedError
|
76
|
+
raise ::Zaig::UnexpectedError.new msg
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -6,7 +6,7 @@ module Zaig
|
|
6
6
|
include Singleton
|
7
7
|
|
8
8
|
def call(obj)
|
9
|
-
{
|
9
|
+
payload = {
|
10
10
|
address: build_address(obj[:address]),
|
11
11
|
client_category: obj[:client_category],
|
12
12
|
constitution_date: obj[:constitution_date],
|
@@ -15,18 +15,19 @@ module Zaig
|
|
15
15
|
credit_type: obj[:credit_type] || "clean",
|
16
16
|
document_number: CNPJ.new(obj[:document_number]).formatted,
|
17
17
|
email: obj[:email],
|
18
|
-
financial: obj.key?("financial") ? build_financial(obj[:financial]) : nil,
|
19
|
-
guarantors: obj.key?("guarantors") ? build_shareholders(obj[:guarantors]) : nil,
|
20
18
|
id: obj[:id],
|
21
19
|
legal_name: obj[:legal_name],
|
22
20
|
monthly_revenue: format_money(obj[:monthly_revenue], require_positive: true),
|
23
21
|
phones: build_phones(obj[:phones]),
|
24
22
|
shareholders: build_shareholders(obj[:shareholders]),
|
25
|
-
|
26
|
-
scr_parameters: obj.key?("scr_parameters") ? build_scr_parameters(obj[:scr_parameters]) : nil,
|
27
|
-
trading_name: obj[:trading_name],
|
28
|
-
warrants: obj.key?("warrants") ? build_warrants(obj[:warrants]) : nil
|
23
|
+
trading_name: obj[:trading_name]
|
29
24
|
}
|
25
|
+
payload[:guarantors] = build_shareholders(obj[:guarantors]) if obj.key?(:guarantors)
|
26
|
+
payload[:financial] = build_financial(obj[:financial]) if obj.key?(:financial)
|
27
|
+
payload[:scr_parameters] = build_scr_parameters(obj[:scr_parameters]) if obj.key?(:scr_parameters)
|
28
|
+
payload[:source] = build_source(obj[:source]) if obj.key?(:source)
|
29
|
+
payload[:warrants] = build_warrants(obj[:warrants]) if obj.key?(:warrants)
|
30
|
+
payload
|
30
31
|
end
|
31
32
|
|
32
33
|
private
|
@@ -35,9 +36,8 @@ module Zaig
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def build_address(obj_address)
|
38
|
-
{
|
39
|
+
address = {
|
39
40
|
city: obj_address[:city],
|
40
|
-
complement: obj_address[:complement] || "",
|
41
41
|
country: obj_address[:country] || "BRA",
|
42
42
|
neighborhood: obj_address[:neighborhood],
|
43
43
|
number: obj_address[:number],
|
@@ -45,6 +45,8 @@ module Zaig
|
|
45
45
|
street: obj_address[:street],
|
46
46
|
uf: obj_address[:uf]
|
47
47
|
}
|
48
|
+
address[:complement] = obj_address[:complement] if !obj_address[:complement].nil? || !obj_address[:complement]&.empty?
|
49
|
+
address
|
48
50
|
end
|
49
51
|
|
50
52
|
def build_phone(obj)
|
@@ -76,10 +78,10 @@ module Zaig
|
|
76
78
|
declared_assets: format_money(s[:declared_assets]),
|
77
79
|
document_number: CPF.new(s[:document_number]).formatted,
|
78
80
|
email: s[:email],
|
79
|
-
father_name: s[:father_name],
|
81
|
+
father_name: filter_blank(s[:father_name]),
|
80
82
|
gender: s[:gender],
|
81
83
|
monthly_income: format_money(s[:monthly_income]),
|
82
|
-
mother_name: s[:mother_name],
|
84
|
+
mother_name: filter_blank(s[:mother_name]),
|
83
85
|
name: s[:name],
|
84
86
|
nationality: s[:nationality],
|
85
87
|
occupation: s[:occupation],
|
@@ -161,7 +163,14 @@ module Zaig
|
|
161
163
|
signers
|
162
164
|
end
|
163
165
|
|
166
|
+
def filter_blank(value)
|
167
|
+
return value if value.nil?
|
168
|
+
|
169
|
+
value.strip == "" ? nil : value
|
170
|
+
end
|
171
|
+
|
164
172
|
def format_cep(cep)
|
173
|
+
cep = cep.delete("-")
|
165
174
|
cep.gsub(/[^0-9]/, "").insert(5, "-")
|
166
175
|
end
|
167
176
|
end
|
data/lib/zaig/server_error.rb
CHANGED
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.
|
11
|
+
VERSION = "1.0.8"
|
12
12
|
end
|
data/lib/zaig.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "cpf_cnpj"
|
4
4
|
require "flash_integration"
|
5
5
|
require "i18n"
|
6
|
+
require "jwt"
|
6
7
|
require "singleton"
|
7
8
|
|
8
9
|
require "zaig/base_error"
|
@@ -48,6 +49,19 @@ module Zaig
|
|
48
49
|
|
49
50
|
# Basic configuration settings
|
50
51
|
class Configuration
|
51
|
-
attr_accessor :
|
52
|
+
attr_accessor :base_url, :jwt_secret, :jwt_user
|
53
|
+
attr_writer :jwt_algorithm, :jwt_exp_time, :registration_endpoint
|
54
|
+
|
55
|
+
def jwt_algorithm
|
56
|
+
@jwt_algorithm ||= "HS256"
|
57
|
+
end
|
58
|
+
|
59
|
+
def jwt_exp_time
|
60
|
+
@jwt_exp_time ||= 1_658_439_475
|
61
|
+
end
|
62
|
+
|
63
|
+
def registration_endpoint
|
64
|
+
@registration_endpoint ||= "zaig/consulta_de_credito"
|
65
|
+
end
|
52
66
|
end
|
53
67
|
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.
|
4
|
+
version: 1.0.8
|
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-
|
11
|
+
date: 2022-07-21 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
|