zaig 1.0.5 → 1.0.6

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: 4d7e5e123adff444d932edaf15cf93f0d56c036e19a12391957736cdb5b3a0f1
4
- data.tar.gz: 6dff02d64d11a052be1a9dc47f77b6a490d3208b1de8b84d487527259099e546
3
+ metadata.gz: ab0151c32beb57d31bb2e3ccd10ff6408091c79c61dbbb9f85b03fed94b6498b
4
+ data.tar.gz: dc88f4a1dbb7601abddeb3c8812948a1f3c6b9633d1b6899168530831b125b4b
5
5
  SHA512:
6
- metadata.gz: 06ea034e23aef7a39e5dd7fe35260746b31d8095ce9f524bb45f60b02b92d6285fe24bd305e43c1f24b49b3d0cb9e61777d6612430741bc49de0f384c88d6f7f
7
- data.tar.gz: f637d5ab308c48793bda590598a41fdff30d8103f395c03cfaf38e87eba2446b4ef77cfe30d3020d174f397e10990802477865559610d80859d4f14f6382bad8
6
+ metadata.gz: 12d241a7a4b5124573f7b45d5a5818075fe45b117bce2ee3d21b404c009eeb9d2f4dbeeff52f6386841c204b568b71811cad6376f23295876645a9a011fd9a1c
7
+ data.tar.gz: d761bbadde669244ad80a1644d31350796f2d1e77ea6d2e01b29cf243b7f691f26d28a49675f37567a74a5d88d1c23403fbaa42044b49afbef2121aa918885aa
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zaig
4
- class AlreadyExistsError < BaseError
4
+ class AlreadyExistsError < Zaig::BaseError
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zaig
4
- class ExternalTimeoutError < BaseError
4
+ class ExternalTimeoutError < Zaig::BaseError
5
5
  end
6
6
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zaig
4
- class FieldValidationError < BaseError
4
+ class FieldValidationError < Zaig::BaseError
5
5
  attr_accessor :detail
6
6
  end
7
7
  end
@@ -56,7 +56,9 @@ module Zaig
56
56
  raise error
57
57
  end
58
58
 
59
- zaig_msg = parsed_res[:resposta_zaig][:msg]
59
+ title = parsed_res[:resposta_zaig][:conteudo][:title]
60
+ description = parsed_res[:resposta_zaig][:conteudo][:description]
61
+ zaig_msg = "#{title}: #{description}"
60
62
  zaig_http_status = parsed_res[:resposta_zaig][:status]
61
63
 
62
64
  raise_error_by_zaig_status(zaig_msg, zaig_http_status)
@@ -65,15 +67,15 @@ module Zaig
65
67
  def raise_error_by_zaig_status(msg, status)
66
68
  case status
67
69
  when 400
68
- raise ::Zaig::FieldValidationError, msg
70
+ raise ::Zaig::FieldValidationError.new msg
69
71
  when 408
70
- raise ::Zaig::ExternalTimeoutError, msg
72
+ raise ::Zaig::ExternalTimeoutError.new msg
71
73
  when 409
72
- raise ::Zaig::AlreadyExistsError, msg
74
+ raise ::Zaig::AlreadyExistsError.new msg
73
75
  when 422
74
- raise ::Zaig::UnprocessableEntityError, msg
76
+ raise ::Zaig::UnprocessableEntityError.new msg
75
77
  else
76
- raise ::Zaig::UnexpectedError, msg
78
+ raise ::Zaig::UnexpectedError.new msg
77
79
  end
78
80
  end
79
81
  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
- 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
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
@@ -76,10 +77,10 @@ module Zaig
76
77
  declared_assets: format_money(s[:declared_assets]),
77
78
  document_number: CPF.new(s[:document_number]).formatted,
78
79
  email: s[:email],
79
- father_name: s[:father_name],
80
+ father_name: filter_blank(s[:father_name]),
80
81
  gender: s[:gender],
81
82
  monthly_income: format_money(s[:monthly_income]),
82
- mother_name: s[:mother_name],
83
+ mother_name: filter_blank(s[:mother_name]),
83
84
  name: s[:name],
84
85
  nationality: s[:nationality],
85
86
  occupation: s[:occupation],
@@ -161,7 +162,14 @@ module Zaig
161
162
  signers
162
163
  end
163
164
 
165
+ def filter_blank(value)
166
+ return value if value.nil?
167
+
168
+ value.strip == "" ? nil : value
169
+ end
170
+
164
171
  def format_cep(cep)
172
+ cep = cep.delete("-")
165
173
  cep.gsub(/[^0-9]/, "").insert(5, "-")
166
174
  end
167
175
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zaig
4
- class ServerError < BaseError
4
+ class ServerError < Zaig::BaseError
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zaig
4
- class ServerTimeoutError < BaseError
4
+ class ServerTimeoutError < Zaig::BaseError
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zaig
4
- class UnexpectedError < BaseError
4
+ class UnexpectedError < Zaig::BaseError
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zaig
4
- class UnprocessableEntityError < BaseError
4
+ class UnprocessableEntityError < Zaig::BaseError
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zaig
4
- class ValidationError < BaseError
4
+ class ValidationError < Zaig::BaseError
5
5
  end
6
6
  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.5"
11
+ VERSION = "1.0.6"
12
12
  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.5
4
+ version: 1.0.6
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-18 00:00:00.000000000 Z
11
+ date: 2022-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cpf_cnpj