ruby-experian 0.0.7 → 0.0.8

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: '00883bdb912d6cb092d8166da29b6391ddac2c34dd02fd19d1022dd3834bfe89'
4
- data.tar.gz: 44199478048a4226285f265aef767e7888e736df8d00366e4a7a2117e9b7a74f
3
+ metadata.gz: 29b12fedd33ce8b9f2b1686ac1b2256477890e23fd08cd9d85fce514b6fea010
4
+ data.tar.gz: 496330fae0eb1cca5090dbe68c0759ddfd4b86e0451f0657fde0bb83f308ca11
5
5
  SHA512:
6
- metadata.gz: 8ac7ddea991154bc3957bbf53e1d2c01dc23eccce1a539798b9186e80e971ca16810f99fe7fd0dd82e58c199366e4d9abd3bb5d05f2536c0d7ad51bb18b8039c
7
- data.tar.gz: d827b25616e56df8069171dfda6f69cc7bb4d8c1cbf851921be6c252276897bc7ee254a1a3261335ce51dd7908e1f1d5dacba543e20e5249d1fa4058c96af4cb
6
+ metadata.gz: 9af32023b8b37a1aac6344e477b6dbc1121835d243bec35e269cb09216c341bdaf62691cfa1ce86ebf49730581ecd15a8ba08d80df33d772327e5583c0e7f9d2
7
+ data.tar.gz: eef00bbc5b09714183e62edcf4d52a45ad85145f7dcf689f37e0474531ebccc3444672ce8fc49d4fc56efb7993ac7377dbddaa50aeae399694f823827b876c0d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-experian (0.0.7)
4
+ ruby-experian (0.0.8)
5
5
  faraday (>= 1)
6
6
  multi_xml (>= 0.6.0)
7
7
  rexml (>= 3.2)
@@ -2,6 +2,9 @@ module Experian
2
2
  class Client
3
3
  include Experian::HTTP
4
4
 
5
+ TRADE_REPORT = 388
6
+ CREDIT_REPORT = 57
7
+
5
8
  CONFIG_KEYS = %i[
6
9
  user_code password request_timeout base_uri extra_headers
7
10
  ].freeze
@@ -16,10 +19,29 @@ module Experian
16
19
  @faraday_middleware = faraday_middleware
17
20
  end
18
21
 
19
- def report(cif:, format: :xml)
20
- response = get(path: "/informe", format:, cif:, cod_servicio: 57)
22
+ def credit_report(cif:, format: :xml, as_response: false)
23
+ response = get(
24
+ path: "/informe",
25
+ format:,
26
+ cif:,
27
+ cod_servicio: CREDIT_REPORT
28
+ )
29
+
30
+ return Experian::CreditReport.new(response) if format == :xml && !as_response
31
+
32
+ response
33
+ end
34
+
35
+ def trade_report(cif:, format: :xml, request_update: true, as_response: false)
36
+ response = get(
37
+ path: "/informe",
38
+ format:,
39
+ cif:,
40
+ garantizar_bajo_demanda: request_update ? 1 : 0,
41
+ cod_servicio: TRADE_REPORT,
42
+ )
21
43
 
22
- return Experian::Report.new(response) if format == :xml
44
+ return Experian::TradeReport.new(response) if format == :xml && !as_response
23
45
 
24
46
  response
25
47
  end
@@ -0,0 +1,57 @@
1
+ require "multi_xml"
2
+ require "rexml"
3
+
4
+ module Experian
5
+ class CreditReport < Report
6
+ def id
7
+ if (id_xml = data["DatosIdentificativos"])
8
+ OpenStruct.new(
9
+ cif: id_xml["Cif"],
10
+ name: id_xml["Nombre"],
11
+ infotel_code: id_xml["CodigoInfotel"],
12
+ incorporation_date: Date.parse(id_xml["FechaFundacion"]),
13
+ social_form: id_xml["FormaSocial"]["__content__"],
14
+ )
15
+ end
16
+ end
17
+
18
+ def address
19
+ if (address_xml = data["DomicilioComercial"])
20
+ OpenStruct.new(
21
+ line: address_xml["Domicilio"],
22
+ city: address_xml["Poblacion"],
23
+ province: address_xml["Provincia"],
24
+ postal_code: address_xml["CodigoPostal"],
25
+ municipality: address_xml["Municipio"],
26
+ )
27
+ end
28
+ end
29
+
30
+ # Number of employees in the last recorded excercise
31
+ def number_of_employees
32
+ data.dig("ListaAnualEmpleados", "Empleado")&.first&.dig("EmpleadoFijo")&.to_i
33
+ end
34
+
35
+ def rating
36
+ if (rating_xml = data["Rating"])
37
+ return unless rating_xml["RatingAxesorDef"]
38
+
39
+ OpenStruct.new(
40
+ score: rating_xml["RatingAxesorDef"]&.strip&.to_i,
41
+ default_probability: rating_xml["ProbImpago"]&.to_f,
42
+ risk: rating_xml["GrupoRiesgo"],
43
+ size: rating_xml["Tamaño"],
44
+ )
45
+ end
46
+ end
47
+
48
+ def cnae
49
+ data.dig("ActividadComercial", "Cnae")&.first&.dig("Codigo")&.to_i
50
+ end
51
+
52
+ def constitution_date
53
+ date = data.dig("DatosConstitutivos", "FechaConstitucion")
54
+ date && Date.parse(date)
55
+ end
56
+ end
57
+ end
@@ -12,59 +12,27 @@ module Experian
12
12
  MultiXml.parser = :rexml
13
13
  @xml = MultiXml.parse(@raw_xml)
14
14
 
15
- raise Experian::AuthenticationError if authentication_error?
15
+ raise error, error_message if error
16
16
  end
17
17
 
18
- def id
19
- if (id_xml = data["DatosIdentificativos"])
20
- OpenStruct.new(
21
- cif: id_xml["Cif"],
22
- name: id_xml["Nombre"],
23
- infotel_code: id_xml["CodigoInfotel"],
24
- incorporation_date: Date.parse(id_xml["FechaFundacion"]),
25
- social_form: id_xml["FormaSocial"]["__content__"],
26
- )
27
- end
28
- end
29
-
30
- def address
31
- if (address_xml = data["DomicilioComercial"])
32
- OpenStruct.new(
33
- line: address_xml["Domicilio"],
34
- city: address_xml["Poblacion"],
35
- province: address_xml["Provincia"],
36
- postal_code: address_xml["CodigoPostal"],
37
- municipality: address_xml["Municipio"],
38
- )
39
- end
40
- end
18
+ protected
41
19
 
42
- # Number of employees in the last recorded excercise
43
- def number_of_employees
44
- data.dig("ListaAnualEmpleados", "Empleado")&.first&.dig("EmpleadoFijo")&.to_i
20
+ def data
21
+ xml.dig("ServicioWebAxesor", "ListaPaquetesNegocio")
45
22
  end
46
23
 
47
- def rating
48
- if (rating_xml = data["Rating"])
49
- return unless rating_xml["RatingAxesorDef"]
24
+ def error
25
+ return Experian::AuthenticationError if authentication_error?
50
26
 
51
- OpenStruct.new(
52
- score: rating_xml["RatingAxesorDef"]&.strip&.to_i,
53
- default_probability: rating_xml["ProbImpago"]&.to_f,
54
- risk: rating_xml["GrupoRiesgo"],
55
- size: rating_xml["Tamaño"],
56
- )
57
- end
27
+ Experian::Error if any_other_error?
58
28
  end
59
29
 
60
- def cnae
61
- data.dig("ActividadComercial", "Cnae")&.first&.dig("Codigo")&.to_i
30
+ def error_message
31
+ xml.dig("DatosError", "DesError")
62
32
  end
63
33
 
64
- private
65
-
66
- def data
67
- xml.dig("ServicioWebAxesor", "ListaPaquetesNegocio")
34
+ def any_other_error?
35
+ xml.dig("DatosError", "CodError")
68
36
  end
69
37
 
70
38
  def authentication_error?
@@ -0,0 +1,55 @@
1
+ module Experian
2
+ class TradeReport < Report
3
+ def model_200(period: last_submitted_year)
4
+ {
5
+ # Balance Sheet - Assets
6
+ "00101" => financial_data("Activo", "11000", period:), # ACTIVO NO CORRIENTE
7
+ "00102" => financial_data("Activo", "11100", period:), # Inmovilizado intangible
8
+ "00136" => financial_data("Activo", "12000", period:), # ACTIVO CORRIENTE
9
+ "00138" => financial_data("Activo", "12200", period:), # Existencias
10
+ "00149" => financial_data("Activo", "12300", period:), # Deudores comerciales y otras cuentas a cobrar
11
+ "00177" => financial_data("Activo", "12700", period:), # Efectivo y otros activos líquidos equivalentes
12
+ "00180" => financial_data("Activo", "10000", period:), # TOTAL ACTIVO
13
+
14
+ # Balance Sheet - Liabilities
15
+ "00185" => financial_data("Pasivo", "20000", period:), # PATRIMONIO NETO
16
+ "00210" => financial_data("Pasivo", "31000", period:), # PASIVO NO CORRIENTE
17
+ "00216" => financial_data("Pasivo", "31200", period:), # Deudas a largo plazo
18
+ "00228" => financial_data("Pasivo", "32000", period:), # PASIVO CORRIENTE
19
+ "00231" => financial_data("Pasivo", "32300", period:), # Deudas a corto plazo
20
+ "00239" => financial_data("Pasivo", "32500", period:), # Acreedores comerciales y otras cuentas a pagar
21
+
22
+ # P&L
23
+ "00255" => financial_data("PerdidasGanancias", "40100", period:), # Importe neto de la cifra de negocios
24
+ "00260" => financial_data("PerdidasGanancias", "40400", period:), # Aprovisionamientos
25
+ "00265" => financial_data("PerdidasGanancias", "40500", period:), # Otros ingresos de explotación
26
+ "00284" => financial_data("PerdidasGanancias", "40800", period:), # Amortización del inmovilizado
27
+ "00285" => financial_data("PerdidasGanancias", "40900", period:), # Imputación de subvenciones de inmovilizado no financiero y otras
28
+ "00286" => financial_data("PerdidasGanancias", "41000", period:), # Excesos de provisiones
29
+ "00287" => financial_data("PerdidasGanancias", "41100", period:), # Deterioro y resultado por enajenaciones del inmovilizad
30
+ "00296" => financial_data("PerdidasGanancias", "49100", period:), # Resultado de explotacion
31
+ "00305" => financial_data("PerdidasGanancias", "41500", period:), # Gastos Financieros
32
+ "00326" => financial_data("PerdidasGanancias", "41900", period:), # Impuestos Sobre Beneficios
33
+ "00327" => financial_data("PerdidasGanancias", "49500", period:), # RESULTADO DEL EJERCICIO PROCEDENTE DE OPERACIONES CONTINUADAS
34
+ }
35
+ end
36
+
37
+ private
38
+
39
+ def last_submitted_year
40
+ (Date.today << 18).year
41
+ end
42
+
43
+ def financial_data(section_name, value_name, period:)
44
+ value_section = section(section_name)
45
+
46
+ if value_name
47
+ value_section&.find { |d| d["Tipo"] == value_name }&.dig("ListaValores", "Valor")&.find { |v| v["Periodo"] == period.to_s }&.dig("Individual")&.to_i
48
+ end
49
+ end
50
+
51
+ def section(section_name)
52
+ data.dig("InformeEconomicoFinanciero")&.first&.dig("ListaGrupos", "Grupo").find { |d| d["Tipo"][section_name] }&.dig("ListaColumnas", "Columna", "ListaDatos", "Dato")
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module Experian
2
- VERSION = "0.0.7".freeze
2
+ VERSION = "0.0.8".freeze
3
3
  end
data/lib/experian.rb CHANGED
@@ -4,6 +4,8 @@ require_relative "experian/http"
4
4
  require_relative "experian/client"
5
5
  require_relative "experian/version"
6
6
  require_relative "experian/report"
7
+ require_relative "experian/credit_report"
8
+ require_relative "experian/trade_report"
7
9
 
8
10
  module Experian
9
11
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-experian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Mochetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-02 00:00:00.000000000 Z
11
+ date: 2024-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -92,8 +92,10 @@ files:
92
92
  - bin/setup
93
93
  - lib/experian.rb
94
94
  - lib/experian/client.rb
95
+ - lib/experian/credit_report.rb
95
96
  - lib/experian/http.rb
96
97
  - lib/experian/report.rb
98
+ - lib/experian/trade_report.rb
97
99
  - lib/experian/version.rb
98
100
  - lib/ruby/experian.rb
99
101
  - ruby-experian.gemspec