zaig 1.0.3 → 1.0.4
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 +4 -4
- data/lib/locales/en.yml +1 -0
- data/lib/locales/pt-BR.yml +1 -0
- data/lib/zaig/field_validation_error.rb +1 -0
- data/lib/zaig/registration.rb +11 -6
- data/lib/zaig/registration_payload.rb +76 -70
- data/lib/zaig/version.rb +1 -1
- data/lib/zaig.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 445f2312bf3306d59b548373e139522dbea660d2078c7c617837ffbff8429dc7
|
|
4
|
+
data.tar.gz: 2dfd8b0ac9f20729abf3df0447a5a3a3d349371bd3558d86e62ff84355f89f20
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c055883e1eac329a7249f79542eb10186fd2a508575e90a1e4dfd10f68e95ab2819f05386213ee4a06e37158440245a588f1d3ee260f8790a5759abb856652c7
|
|
7
|
+
data.tar.gz: b0ea93f0f3a76a3e7b4a698096e284dc5734c4cfd915f28a2de38cc4882bab5309065854061f07d1004e311c4b20a52ec0d1c034828ff054c7979233ef16c51d
|
data/lib/locales/en.yml
CHANGED
data/lib/locales/pt-BR.yml
CHANGED
data/lib/zaig/registration.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "singleton"
|
|
4
|
-
|
|
5
3
|
module Zaig
|
|
6
4
|
# Class to request a registration to the remote server.
|
|
7
5
|
class Registration
|
|
@@ -45,11 +43,18 @@ module Zaig
|
|
|
45
43
|
def verify_response(res)
|
|
46
44
|
return if res.status.between?(200, 299)
|
|
47
45
|
|
|
48
|
-
raise ::Zaig::
|
|
46
|
+
raise ::Zaig::ServerError, I18n.t("zaig.errors.unexpected_error") if res.status.between?(500, 599)
|
|
49
47
|
|
|
50
48
|
parsed_res = JSON.parse(res.body, symbolize_names: true)
|
|
51
49
|
|
|
52
|
-
|
|
50
|
+
unless parsed_res.key?(:resposta_zaig)
|
|
51
|
+
detail = JSON.parse(res.body, symbolize_names: true)[:detail]
|
|
52
|
+
|
|
53
|
+
error = ::Zaig::FieldValidationError.new I18n.t("zaig.errors.validation_error", field_name: "resposta_zaig")
|
|
54
|
+
error.detail = JSON.parse(res.body, symbolize_names: true)[:detail]
|
|
55
|
+
|
|
56
|
+
raise error
|
|
57
|
+
end
|
|
53
58
|
|
|
54
59
|
zaig_msg = parsed_res[:resposta_zaig][:msg]
|
|
55
60
|
zaig_http_status = parsed_res[:resposta_zaig][:status]
|
|
@@ -59,12 +64,12 @@ module Zaig
|
|
|
59
64
|
|
|
60
65
|
def raise_error_by_zaig_status(msg, status)
|
|
61
66
|
case status
|
|
62
|
-
when 209
|
|
63
|
-
raise ::Zaig::AlreadyExistsError, msg
|
|
64
67
|
when 400
|
|
65
68
|
raise ::Zaig::FieldValidationError, msg
|
|
66
69
|
when 408
|
|
67
70
|
raise ::Zaig::ExternalTimeoutError, msg
|
|
71
|
+
when 409
|
|
72
|
+
raise ::Zaig::AlreadyExistsError, msg
|
|
68
73
|
when 422
|
|
69
74
|
raise ::Zaig::UnprocessableEntityError, msg
|
|
70
75
|
else
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "singleton"
|
|
4
|
-
|
|
5
3
|
module Zaig
|
|
6
4
|
# Service class to build a registration payload request.
|
|
7
5
|
class RegistrationPayload
|
|
@@ -9,48 +7,52 @@ module Zaig
|
|
|
9
7
|
|
|
10
8
|
def call(obj)
|
|
11
9
|
{
|
|
12
|
-
address: build_address(obj[
|
|
13
|
-
client_category: obj[
|
|
14
|
-
constitution_date:
|
|
15
|
-
constitution_type: obj[
|
|
16
|
-
credit_request_date: obj[
|
|
17
|
-
credit_type: obj[
|
|
18
|
-
document_number: CNPJ.new(obj[
|
|
19
|
-
email: obj[
|
|
20
|
-
financial: obj.key?("financial") ? build_financial(obj[
|
|
21
|
-
guarantors: obj.key?("guarantors") ? build_shareholders(obj[
|
|
22
|
-
id: obj[
|
|
23
|
-
legal_name: obj[
|
|
24
|
-
monthly_revenue: obj[
|
|
25
|
-
phones: build_phones(obj[
|
|
26
|
-
shareholders: build_shareholders(obj[
|
|
27
|
-
source: obj.key?("source") ? build_source(obj[
|
|
28
|
-
scr_parameters: obj.key?("scr_parameters") ? build_scr_parameters(obj[
|
|
29
|
-
trading_name: obj[
|
|
30
|
-
warrants: obj.key?("warrants") ? build_warrants(obj[
|
|
10
|
+
address: build_address(obj[:address]),
|
|
11
|
+
client_category: obj[:client_category],
|
|
12
|
+
constitution_date: obj[:constitution_date],
|
|
13
|
+
constitution_type: obj[:constitution_type],
|
|
14
|
+
credit_request_date: obj[:credit_request_date],
|
|
15
|
+
credit_type: obj[:credit_type] || "clean",
|
|
16
|
+
document_number: CNPJ.new(obj[:document_number]).formatted,
|
|
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
|
+
id: obj[:id],
|
|
21
|
+
legal_name: obj[:legal_name],
|
|
22
|
+
monthly_revenue: format_money(obj[:monthly_revenue], require_positive: true),
|
|
23
|
+
phones: build_phones(obj[:phones]),
|
|
24
|
+
shareholders: build_shareholders(obj[:shareholders]),
|
|
25
|
+
source: obj.key?("source") ? build_source(obj[:source]) : nil,
|
|
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
|
|
31
29
|
}
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
private
|
|
33
|
+
def format_money(value, require_positive: false)
|
|
34
|
+
require_positive && !value.to_f.positive? ? 1.0 : value.to_f
|
|
35
|
+
end
|
|
36
|
+
|
|
35
37
|
def build_address(obj_address)
|
|
36
38
|
{
|
|
37
|
-
city: obj_address[
|
|
38
|
-
complement: obj_address[
|
|
39
|
-
country: obj_address[
|
|
40
|
-
neighborhood: obj_address[
|
|
41
|
-
number: obj_address[
|
|
42
|
-
postal_code: obj_address[
|
|
43
|
-
street: obj_address[
|
|
44
|
-
uf: obj_address[
|
|
39
|
+
city: obj_address[:city],
|
|
40
|
+
complement: obj_address[:complement] || "",
|
|
41
|
+
country: obj_address[:country] || "BRA",
|
|
42
|
+
neighborhood: obj_address[:neighborhood],
|
|
43
|
+
number: obj_address[:number],
|
|
44
|
+
postal_code: format_cep(obj_address[:postal_code]),
|
|
45
|
+
street: obj_address[:street],
|
|
46
|
+
uf: obj_address[:uf]
|
|
45
47
|
}
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
def build_phone(obj)
|
|
49
51
|
{
|
|
50
|
-
area_code: obj[
|
|
51
|
-
international_dial_code: obj[
|
|
52
|
-
number: obj[
|
|
53
|
-
type: obj[
|
|
52
|
+
area_code: obj[:area_code],
|
|
53
|
+
international_dial_code: obj[:international_dial_code],
|
|
54
|
+
number: obj[:number],
|
|
55
|
+
type: obj[:type]
|
|
54
56
|
}
|
|
55
57
|
end
|
|
56
58
|
|
|
@@ -69,19 +71,19 @@ module Zaig
|
|
|
69
71
|
|
|
70
72
|
obj_shareholders.each do |s|
|
|
71
73
|
shareholders << {
|
|
72
|
-
address: build_address(s[
|
|
73
|
-
birthdate:
|
|
74
|
-
declared_assets: s[
|
|
75
|
-
document_number: CPF.new(s[
|
|
76
|
-
email: s[
|
|
77
|
-
father_name: s[
|
|
78
|
-
gender: s[
|
|
79
|
-
monthly_income: s[
|
|
80
|
-
mother_name: s[
|
|
81
|
-
name: s[
|
|
82
|
-
nationality: s[
|
|
83
|
-
occupation: s[
|
|
84
|
-
phones: build_phones(s[
|
|
74
|
+
address: build_address(s[:address]),
|
|
75
|
+
birthdate: s[:birthdate],
|
|
76
|
+
declared_assets: format_money(s[:declared_assets]),
|
|
77
|
+
document_number: CPF.new(s[:document_number]).formatted,
|
|
78
|
+
email: s[:email],
|
|
79
|
+
father_name: s[:father_name],
|
|
80
|
+
gender: s[:gender],
|
|
81
|
+
monthly_income: format_money(s[:monthly_income]),
|
|
82
|
+
mother_name: s[:mother_name],
|
|
83
|
+
name: s[:name],
|
|
84
|
+
nationality: s[:nationality],
|
|
85
|
+
occupation: s[:occupation],
|
|
86
|
+
phones: build_phones(s[:phones])
|
|
85
87
|
}
|
|
86
88
|
end
|
|
87
89
|
shareholders
|
|
@@ -91,12 +93,12 @@ module Zaig
|
|
|
91
93
|
return nil if fin.nil?
|
|
92
94
|
|
|
93
95
|
{
|
|
94
|
-
amount: fin[
|
|
95
|
-
annual_interest_rate: fin[
|
|
96
|
-
cdi_percentage: fin[
|
|
97
|
-
currency: fin[
|
|
98
|
-
interest_type: fin[
|
|
99
|
-
number_of_installments: fin.key?("number_of_installments") ? fin[
|
|
96
|
+
amount: fin[:amount],
|
|
97
|
+
annual_interest_rate: fin[:annual_interest_rate],
|
|
98
|
+
cdi_percentage: fin[:cdi_percentage],
|
|
99
|
+
currency: fin[:currency] || "BRL",
|
|
100
|
+
interest_type: fin[:interest_type],
|
|
101
|
+
number_of_installments: fin.key?("number_of_installments") ? fin[:number_of_installments].to_i : 0
|
|
100
102
|
}
|
|
101
103
|
end
|
|
102
104
|
|
|
@@ -107,11 +109,11 @@ module Zaig
|
|
|
107
109
|
|
|
108
110
|
obj_warrants.each do |w|
|
|
109
111
|
warrants << {
|
|
110
|
-
warrant_type: w[
|
|
111
|
-
address: build_address(w[
|
|
112
|
-
property_type: w[
|
|
113
|
-
estimated_value: w[
|
|
114
|
-
forced_selling_value: w[
|
|
112
|
+
warrant_type: w[:warrant_type],
|
|
113
|
+
address: build_address(w[:address]),
|
|
114
|
+
property_type: w[:property_type],
|
|
115
|
+
estimated_value: w[:estimated_value],
|
|
116
|
+
forced_selling_value: w[:forced_selling_value]
|
|
115
117
|
}
|
|
116
118
|
end
|
|
117
119
|
warrants
|
|
@@ -121,9 +123,9 @@ module Zaig
|
|
|
121
123
|
return nil if obj_source.nil?
|
|
122
124
|
|
|
123
125
|
{
|
|
124
|
-
channel: obj_source[
|
|
125
|
-
ip: obj_source[
|
|
126
|
-
session_id: obj_source[
|
|
126
|
+
channel: obj_source[:channel],
|
|
127
|
+
ip: obj_source[:ip],
|
|
128
|
+
session_id: obj_source[:session_id]
|
|
127
129
|
}
|
|
128
130
|
end
|
|
129
131
|
|
|
@@ -131,14 +133,14 @@ module Zaig
|
|
|
131
133
|
return nil if obj_src.nil?
|
|
132
134
|
|
|
133
135
|
{
|
|
134
|
-
signers: build_signers(obj_src[
|
|
136
|
+
signers: build_signers(obj_src[:signers]),
|
|
135
137
|
signature_evidence: {
|
|
136
|
-
access_token: obj_src[
|
|
137
|
-
additional_data: obj_src[
|
|
138
|
-
ip_address: obj_src[
|
|
139
|
-
session_id: obj_src[
|
|
138
|
+
access_token: obj_src[:signature_evidence][:access_token],
|
|
139
|
+
additional_data: obj_src[:signature_evidence][:additional_data],
|
|
140
|
+
ip_address: obj_src[:signature_evidence][:ip_address],
|
|
141
|
+
session_id: obj_src[:signature_evidence][:session_id],
|
|
140
142
|
signed_term: {
|
|
141
|
-
raw_text: obj_src[
|
|
143
|
+
raw_text: obj_src[:signature_evidence][:signed_term][:raw_text]
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
146
|
}
|
|
@@ -150,13 +152,17 @@ module Zaig
|
|
|
150
152
|
signers = []
|
|
151
153
|
obj_signers.each do |s|
|
|
152
154
|
signers << {
|
|
153
|
-
document_number: CNPJ.new(s[
|
|
154
|
-
name: s[
|
|
155
|
-
email: s[
|
|
156
|
-
phone: build_phone(s[
|
|
155
|
+
document_number: CNPJ.new(s[:document_number]).number,
|
|
156
|
+
name: s[:name],
|
|
157
|
+
email: s[:email],
|
|
158
|
+
phone: build_phone(s[:phone])
|
|
157
159
|
}
|
|
158
160
|
end
|
|
159
161
|
signers
|
|
160
162
|
end
|
|
163
|
+
|
|
164
|
+
def format_cep(cep)
|
|
165
|
+
cep.gsub(/[^0-9]/, "").insert(5, "-")
|
|
166
|
+
end
|
|
161
167
|
end
|
|
162
168
|
end
|
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.4"
|
|
12
12
|
end
|
data/lib/zaig.rb
CHANGED
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.4
|
|
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-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: cpf_cnpj
|