afipws 1.3.0 → 2.1.0

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
- SHA1:
3
- metadata.gz: e083e48130414df572623a49024d5d68fc169d57
4
- data.tar.gz: c87895059bef97f564ecd82e59771a6569c6b011
2
+ SHA256:
3
+ metadata.gz: c62722b5dadabc183a975922b0177b63d8bce82c24fafdd35e74240856b25d8e
4
+ data.tar.gz: b1a0f1ce2a252d730fee01a0830fc3d2142b50df33c13864b95854bdffa856ca
5
5
  SHA512:
6
- metadata.gz: 9beb54c5fd1c0a08c829735cd8fb05edac37a50333eccdbab3517103eb453a9804324e2293936d2af43e42d868a198c1606c4de84bb81e0e35d52cf099a689ab
7
- data.tar.gz: 91069cf8b299dfb59c6e1eac27d7ac3fbe4748f89682e6a4bca049f0fc8669d949292c8a384e9aa7578723928c3ad564d29eb270a4f6f1fc6665c0439e8d7cee
6
+ metadata.gz: 969630cf2f9cb2b9ae629a61f0c0cdfe79832825ea6a6fe43745d341b5b29b1117ce230567ed0e9fd27ff22f73936135bf1c4cfc6aed856fb5090ec1eeadd9eb
7
+ data.tar.gz: 4601ea842fcd9d84ed968fd6e8a0d11e7304353b92782dfe79ad18d6894d8c8eada013b893d8ea0f424ac004722cee6edd9e879513204d7cb354321dfb16ad75
data/.envrc ADDED
@@ -0,0 +1,2 @@
1
+ layout ruby
2
+ use nix
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ spec/manual/*.key
5
5
  spec/manual/*.crt
6
6
  .DS_Store
7
7
  tmp
8
+ /.direnv
data/.rubocop.yml CHANGED
@@ -55,19 +55,31 @@ Style/MutableConstant:
55
55
  Style/RescueModifier:
56
56
  Enabled: false
57
57
 
58
+ Style/HashEachMethods:
59
+ Enabled: false
60
+
61
+ Style/HashTransformKeys:
62
+ Enabled: false
63
+
64
+ Style/HashTransformValues:
65
+ Enabled: false
66
+
67
+ Layout/LineLength:
68
+ Max: 120
69
+
58
70
  Layout/SpaceInsideHashLiteralBraces:
59
71
  Enabled: false
60
72
 
61
73
  Layout/MultilineMethodCallIndentation:
62
74
  Enabled: false
63
75
 
64
- Layout/TrailingBlankLines:
76
+ Layout/TrailingEmptyLines:
65
77
  Enabled: false
66
78
 
67
- Layout/IndentArray:
79
+ Layout/FirstArrayElementIndentation:
68
80
  EnforcedStyle: consistent
69
81
 
70
- Layout/AlignParameters:
82
+ Layout/ParameterAlignment:
71
83
  EnforcedStyle: with_fixed_indentation
72
84
 
73
85
  Layout/SpaceInLambdaLiteral:
@@ -79,10 +91,6 @@ Metrics:
79
91
  Bundler:
80
92
  Enabled: false
81
93
 
82
- Lint/Void:
83
- Exclude:
84
- - spec/**/*.rb
85
-
86
94
  Lint/AssignmentInCondition:
87
95
  Enabled: false
88
96
 
@@ -98,5 +106,5 @@ Lint/AmbiguousOperator:
98
106
  Lint/AmbiguousBlockAssociation:
99
107
  Enabled: false
100
108
 
101
- Naming/UncommunicativeMethodParamName:
109
+ Naming/MethodParameterName:
102
110
  Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.7.5
data/.travis.yml CHANGED
@@ -2,4 +2,4 @@
2
2
  sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
- before_install: gem install bundler -v 1.16.2
5
+ before_install: gem install bundler -v 2.1.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## [2.0.0] - 2020-10-28
8
+
9
+ ### Added
10
+
11
+ - Long overdue CHANGELOG file.
12
+ - Include `httpclient` dependency so we can wrap network errors.
13
+
14
+ ### Changed
15
+
16
+ - Rename `Afipws::WSError` to `Afipws::Error`, and create subclasses to distinguish between different types of errors.
data/Gemfile.lock CHANGED
@@ -1,38 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- afipws (1.3.0)
4
+ afipws (2.1.0)
5
5
  activesupport
6
6
  builder
7
+ httpclient
7
8
  nokogiri
8
- savon (~> 2.11.0)
9
+ savon (~> 2.12.0)
9
10
 
10
11
  GEM
11
12
  remote: http://rubygems.org/
12
13
  specs:
13
- activesupport (5.2.3)
14
+ activesupport (7.0.2.2)
14
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
- i18n (>= 0.7, < 2)
16
- minitest (~> 5.1)
17
- tzinfo (~> 1.1)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ addressable (2.8.0)
20
+ public_suffix (>= 2.0.2, < 5.0)
18
21
  akami (1.3.1)
19
22
  gyoku (>= 0.4.0)
20
23
  nokogiri
21
- ast (2.4.0)
22
- builder (3.2.3)
23
- byebug (11.0.1)
24
- coderay (1.1.2)
25
- concurrent-ruby (1.1.5)
24
+ ast (2.4.2)
25
+ builder (3.2.4)
26
+ coderay (1.1.3)
27
+ concurrent-ruby (1.1.9)
26
28
  diff-lcs (1.3)
27
- ffi (1.9.25)
28
- formatador (0.2.5)
29
- guard (2.14.2)
29
+ ffi (1.15.5)
30
+ formatador (1.1.0)
31
+ guard (2.18.0)
30
32
  formatador (>= 0.2.4)
31
33
  listen (>= 2.7, < 4.0)
32
34
  lumberjack (>= 1.0.12, < 2.0)
33
35
  nenv (~> 0.1)
34
36
  notiffany (~> 0.0)
35
- pry (>= 0.9.12)
37
+ pry (>= 0.13.0)
36
38
  shellany (~> 0.0)
37
39
  thor (>= 0.18.1)
38
40
  guard-compat (1.2.1)
@@ -42,45 +44,43 @@ GEM
42
44
  rspec (>= 2.99.0, < 4.0)
43
45
  gyoku (1.3.1)
44
46
  builder (>= 2.1.2)
45
- httpi (2.4.4)
47
+ httpclient (2.8.3)
48
+ httpi (2.5.0)
46
49
  rack
47
50
  socksify
48
- i18n (1.6.0)
51
+ i18n (1.10.0)
49
52
  concurrent-ruby (~> 1.0)
50
- jaro_winkler (1.5.1)
51
- listen (3.1.5)
52
- rb-fsevent (~> 0.9, >= 0.9.4)
53
- rb-inotify (~> 0.9, >= 0.9.7)
54
- ruby_dep (~> 1.2)
55
- lumberjack (1.0.13)
56
- method_source (0.9.0)
57
- mini_portile2 (2.4.0)
58
- minitest (5.11.3)
53
+ jaro_winkler (1.5.4)
54
+ listen (3.7.1)
55
+ rb-fsevent (~> 0.10, >= 0.10.3)
56
+ rb-inotify (~> 0.9, >= 0.9.10)
57
+ lumberjack (1.2.8)
58
+ method_source (1.0.0)
59
+ minitest (5.15.0)
59
60
  mocha (0.9.10)
60
61
  rake
61
62
  nenv (0.3.0)
62
- nokogiri (1.10.4)
63
- mini_portile2 (~> 2.4.0)
63
+ nokogiri (1.13.1-arm64-darwin)
64
+ racc (~> 1.4)
64
65
  nori (2.6.0)
65
- notiffany (0.1.1)
66
+ notiffany (0.1.3)
66
67
  nenv (~> 0.1)
67
68
  shellany (~> 0.0)
68
- parallel (1.12.1)
69
- parser (2.5.3.0)
70
- ast (~> 2.4.0)
71
- powerpack (0.1.2)
72
- pry (0.11.3)
73
- coderay (~> 1.1.0)
74
- method_source (~> 0.9.0)
75
- pry-byebug (3.7.0)
76
- byebug (~> 11.0)
77
- pry (~> 0.10)
78
- rack (2.0.8)
79
- rainbow (3.0.0)
80
- rake (10.4.2)
81
- rb-fsevent (0.10.3)
82
- rb-inotify (0.9.10)
83
- ffi (>= 0.5.0, < 2)
69
+ parallel (1.21.0)
70
+ parser (3.1.0.0)
71
+ ast (~> 2.4.1)
72
+ pry (0.14.1)
73
+ coderay (~> 1.1)
74
+ method_source (~> 1.0)
75
+ public_suffix (4.0.6)
76
+ racc (1.6.0)
77
+ rack (2.2.3)
78
+ rainbow (3.1.1)
79
+ rake (13.0.1)
80
+ rb-fsevent (0.11.1)
81
+ rb-inotify (0.10.1)
82
+ ffi (~> 1.0)
83
+ rexml (3.2.5)
84
84
  rspec (3.7.0)
85
85
  rspec-core (~> 3.7.0)
86
86
  rspec-expectations (~> 3.7.0)
@@ -94,32 +94,31 @@ GEM
94
94
  diff-lcs (>= 1.2.0, < 2.0)
95
95
  rspec-support (~> 3.7.0)
96
96
  rspec-support (3.7.1)
97
- rubocop (0.61.1)
97
+ rubocop (0.80.1)
98
98
  jaro_winkler (~> 1.5.1)
99
99
  parallel (~> 1.10)
100
- parser (>= 2.5, != 2.5.1.1)
101
- powerpack (~> 0.1)
100
+ parser (>= 2.7.0.1)
102
101
  rainbow (>= 2.2.2, < 4.0)
102
+ rexml
103
103
  ruby-progressbar (~> 1.7)
104
- unicode-display_width (~> 1.4.0)
105
- ruby-progressbar (1.10.0)
106
- ruby_dep (1.5.0)
107
- savon (2.11.2)
104
+ unicode-display_width (>= 1.4.0, < 1.7)
105
+ ruby-progressbar (1.11.0)
106
+ savon (2.12.1)
108
107
  akami (~> 1.2)
109
108
  builder (>= 2.1.2)
110
109
  gyoku (~> 1.2)
111
110
  httpi (~> 2.3)
112
- nokogiri (>= 1.4.0)
111
+ nokogiri (>= 1.8.1)
113
112
  nori (~> 2.4)
114
113
  wasabi (~> 3.4)
115
114
  shellany (0.0.1)
116
115
  socksify (1.7.1)
117
- thor (0.20.0)
118
- thread_safe (0.3.6)
119
- tzinfo (1.2.5)
120
- thread_safe (~> 0.1)
121
- unicode-display_width (1.4.0)
122
- wasabi (3.5.0)
116
+ thor (1.2.1)
117
+ tzinfo (2.0.4)
118
+ concurrent-ruby (~> 1.0)
119
+ unicode-display_width (1.6.1)
120
+ wasabi (3.7.0)
121
+ addressable
123
122
  httpi (~> 2.0)
124
123
  nokogiri (>= 1.4.2)
125
124
 
@@ -131,9 +130,8 @@ DEPENDENCIES
131
130
  guard-rspec
132
131
  mocha
133
132
  pry
134
- pry-byebug
135
133
  rspec
136
- rubocop
134
+ rubocop (~> 0.80.0)
137
135
 
138
136
  BUNDLED WITH
139
- 1.16.2
137
+ 2.1.4
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Ruby client para los web services de la AFIP.
4
4
 
5
- [![Build Status](https://travis-ci.org/eeng/afipws.svg?branch=master)](https://travis-ci.org/eeng/afipws)
5
+ [![Build Status](https://app.travis-ci.com/eeng/afipws.svg?branch=master)](https://app.travis-ci.com/eeng/afipws)
6
6
 
7
7
  ## Servicios Disponibles
8
8
 
data/afipws.gemspec CHANGED
@@ -21,11 +21,11 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency 'rspec'
22
22
  s.add_development_dependency 'mocha'
23
23
  s.add_development_dependency 'guard-rspec'
24
- s.add_development_dependency 'rubocop'
24
+ s.add_development_dependency 'rubocop', '~> 0.80.0'
25
25
  s.add_development_dependency 'pry'
26
- s.add_development_dependency 'pry-byebug'
27
26
  s.add_dependency "builder"
28
- s.add_dependency "savon", '~> 2.11.0'
27
+ s.add_dependency "savon", '~> 2.12.0'
28
+ s.add_dependency "httpclient"
29
29
  s.add_dependency "nokogiri"
30
30
  s.add_dependency "activesupport"
31
31
  end
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'afipws'
5
+
6
+ require 'pry'
7
+ Pry.start
data/lib/afipws/client.rb CHANGED
@@ -1,15 +1,19 @@
1
1
  module Afipws
2
2
  class Client
3
3
  def initialize savon_options
4
- @client = Savon.client savon_options.reverse_merge(soap_version: 2, ssl_version: :TLSv1)
4
+ @savon = Savon.client savon_options.reverse_merge(soap_version: 2, ssl_version: :TLSv1_2)
5
5
  end
6
6
 
7
7
  def request action, body = nil
8
- @client.call action, message: body
8
+ @savon.call action, message: body
9
+ rescue Savon::SOAPFault => e
10
+ raise ServerError, e
11
+ rescue HTTPClient::TimeoutError => e
12
+ raise NetworkError, e
9
13
  end
10
14
 
11
15
  def operations
12
- @client.operations
16
+ @savon.operations
13
17
  end
14
18
  end
15
19
  end
@@ -4,10 +4,6 @@ module Afipws
4
4
  def select_keys *keys
5
5
  select { |k, _| keys.include? k }
6
6
  end
7
-
8
- def has_entries? entries
9
- entries.each_pair.all? { |k, v| self[k] == v }
10
- end
11
7
  end
12
8
  end
13
9
  end
@@ -0,0 +1,7 @@
1
+ module Afipws
2
+ class Error < StandardError
3
+ def code? _code
4
+ false
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ module Afipws
2
+ class NetworkError < Error
3
+ end
4
+ end
@@ -0,0 +1,16 @@
1
+ module Afipws
2
+ class ResponseError < Error
3
+ attr_reader :errors
4
+
5
+ def initialize errors
6
+ raise ArgumentError, '`errors` must be an array of maps, each with :code and :msg keys' unless errors.is_a? Array
7
+
8
+ super errors.map { |e| "#{e[:code]}: #{e[:msg]}" }.join '; '
9
+ @errors = errors
10
+ end
11
+
12
+ def code? code
13
+ @errors.any? { |e| e[:code].to_s == code.to_s }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ module Afipws
2
+ class ServerError < Error
3
+ end
4
+ end
@@ -44,8 +44,6 @@ module Afipws
44
44
 
45
45
  def request action, body = nil
46
46
  @client.request(action, body).to_hash[:"#{action}_response"]
47
- rescue Savon::SOAPFault => f
48
- raise WSError, f.message
49
47
  end
50
48
  end
51
49
  end
@@ -27,8 +27,6 @@ module Afipws
27
27
 
28
28
  def request action, body = nil
29
29
  @client.request(action, body).to_hash[:"#{action}_response"]
30
- rescue Savon::SOAPFault => f
31
- raise WSError, f.message
32
30
  end
33
31
  end
34
32
  end
@@ -21,15 +21,13 @@ module Afipws
21
21
 
22
22
  def get_persona id
23
23
  message = @wsaa.auth.merge(cuitRepresentada: @cuit, idPersona: id)
24
- request(:get_persona, message)[:persona_return][:datos_generales]
24
+ request(:get_persona, message)[:persona_return]
25
25
  end
26
26
 
27
27
  private
28
28
 
29
29
  def request action, body = nil
30
30
  @client.request(action, body).to_hash[:"#{action}_response"]
31
- rescue Savon::SOAPFault => f
32
- raise WSError, f.message
33
31
  end
34
32
  end
35
33
  end
@@ -1,3 +1,3 @@
1
1
  module Afipws
2
- VERSION = '1.3.0'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -40,12 +40,10 @@ module Afipws
40
40
  def request action, body = nil
41
41
  response = @client.request(action, body).to_hash[:"#{action}_response"][:"#{action}_result"]
42
42
  if response[:lista_errores] && response[:lista_errores][:detalle_error][:codigo] != '0'
43
- raise WSError, Array.wrap(response[:lista_errores][:detalle_error]).map { |e| {code: e[:codigo], msg: e[:descripcion]} }
43
+ raise ResponseError, Array.wrap(response[:lista_errores][:detalle_error]).map { |e| {code: e[:codigo], msg: e[:descripcion]} }
44
44
  else
45
45
  response
46
46
  end
47
- rescue Savon::SOAPFault => f
48
- raise WSError, f.message
49
47
  end
50
48
 
51
49
  def auth
@@ -27,8 +27,6 @@ module Afipws
27
27
 
28
28
  def request action, body = nil
29
29
  @client.request(action, body).to_hash[:"#{action}_response"]
30
- rescue Savon::SOAPFault => f
31
- raise WSError, f.message
32
30
  end
33
31
  end
34
32
  end
data/lib/afipws/wsaa.rb CHANGED
@@ -55,8 +55,6 @@ module Afipws
55
55
  generation_time: from_xsd_datetime(ta.css('generationTime').text),
56
56
  expiration_time: from_xsd_datetime(ta.css('expirationTime').text)
57
57
  }
58
- rescue Savon::SOAPFault => f
59
- raise WSError, f.message
60
58
  end
61
59
 
62
60
  def auth
data/lib/afipws/wsfe.rb CHANGED
@@ -92,8 +92,8 @@ module Afipws
92
92
 
93
93
  def solicitar_caea
94
94
  convertir_rta_caea request(:fecaea_solicitar, auth.merge(periodo_para_solicitud_caea))
95
- rescue Afipws::WSError => e
96
- if e.errors.any? { |e| e[:code] == '15008' }
95
+ rescue Afipws::ResponseError => e
96
+ if e.code? 15008
97
97
  consultar_caea fecha_inicio_quincena_siguiente
98
98
  else
99
99
  raise
@@ -163,7 +163,7 @@ module Afipws
163
163
  def request action, body = nil
164
164
  response = @client.request(action, body).to_hash[:"#{action}_response"][:"#{action}_result"]
165
165
  if response[:errors]
166
- raise WSError, Array.wrap(response[:errors][:err])
166
+ raise ResponseError, Array.wrap(response[:errors][:err])
167
167
  else
168
168
  response
169
169
  end
data/lib/afipws.rb CHANGED
@@ -5,12 +5,16 @@ end
5
5
  require 'forwardable'
6
6
  require 'builder'
7
7
  require 'base64'
8
+ require 'httpclient'
8
9
  require 'savon'
9
10
  require 'nokogiri'
10
11
  require 'active_support'
11
12
  require 'active_support/core_ext'
12
13
  require 'afipws/core_ext/hash'
13
- require 'afipws/wserror'
14
+ require 'afipws/errors/error'
15
+ require 'afipws/errors/response_error'
16
+ require 'afipws/errors/server_error'
17
+ require 'afipws/errors/network_error'
14
18
  require 'afipws/type_conversions'
15
19
  require 'afipws/client'
16
20
  require 'afipws/wsaa'
data/shell.nix ADDED
@@ -0,0 +1,6 @@
1
+ with import <nixpkgs> {};
2
+ mkShell {
3
+ nativeBuildInputs = [
4
+ ruby
5
+ ];
6
+ }
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module Afipws
4
+ describe Client do
5
+ context 'manejo de errores' do
6
+ subject { Client.new(wsdl: Afipws::WSFE::WSDL[:test]) }
7
+
8
+ it 'Savon::SOAPFault se encapsulan en ServerError' do
9
+ savon.expects(:fe_dummy).returns(fixture('wsaa/login_cms/fault'))
10
+ -> { subject.request :fe_dummy }.should raise_error ServerError, /CMS no es valido/
11
+ end
12
+
13
+ it 'HTTPClient::TimeoutError se encapsulan en NetworkError' do
14
+ # Hack to mock exceptions on Savon
15
+ subject.instance_eval('@savon').expects(:call).raises(HTTPClient::ReceiveTimeoutError, 'execution expired')
16
+ -> { subject.request :fe_dummy }.should raise_error NetworkError, /execution expired/
17
+ end
18
+ end
19
+ end
20
+ end
@@ -10,14 +10,4 @@ describe Hash do
10
10
  hash.select_keys(5, 3).should == {3 => 4}
11
11
  end
12
12
  end
13
-
14
- context 'has_entries?' do
15
- subject { Hash[1, 2, 3, 4] }
16
-
17
- it 'debería devolver true cuando self incluye todas las entries del hash parametro' do
18
- should include 1 => 2
19
- should include 3 => 4, 1 => 2
20
- should_not include 1 => 3
21
- end
22
- end
23
13
  end
@@ -16,7 +16,7 @@ module Afipws
16
16
  savon.expects(:get_persona)
17
17
  .with(message: message.merge(idPersona: '98765432198'))
18
18
  .returns(fixture('ws_sr_padron_a5/get_persona/success'))
19
- ws.get_persona('98765432198').should include apellido: 'ALEXA'
19
+ ws.get_persona('98765432198').should have_key :datos_generales
20
20
  end
21
21
  end
22
22
  end
@@ -55,7 +55,7 @@ module Afipws
55
55
  savon.expects(:detallada_lista_declaraciones).with(message: :any)
56
56
  .returns(fixture('wconsdeclaracion/detallada_lista_declaraciones/por_id_inexistente'))
57
57
  -> { ws.detallada_lista_declaraciones identificador_declaracion: '...' }
58
- .should raise_error WSError, '21248: Declaracion 19093SIMI000434. inexistente o invalida'
58
+ .should raise_error ResponseError, '21248: Declaracion 19093SIMI000434. inexistente o invalida'
59
59
  end
60
60
  end
61
61
 
@@ -51,7 +51,7 @@ module Afipws
51
51
  savon.expects(:get_persona)
52
52
  .with(message: message.merge(id_persona: '123'))
53
53
  .returns(fixture('ws_sr_constancia_inscripcion/get_persona/fault'))
54
- -> { ws.get_persona '123' }.should raise_error WSError, /No existe persona con ese Id/
54
+ -> { ws.get_persona '123' }.should raise_error ServerError, /No existe persona con ese Id/
55
55
  end
56
56
  end
57
57
 
@@ -39,12 +39,6 @@ module Afipws
39
39
  ta[:generation_time].should == Time.new(2011, 1, 12, 18, 57, 4, '-03:00')
40
40
  ta[:expiration_time].should == Time.new(2011, 1, 13, 6, 57, 4, '-03:00')
41
41
  end
42
-
43
- it 'debería encapsular SOAP Faults' do
44
- subject.stubs(:tra).returns('')
45
- savon.expects(:login_cms).with(message: :any).returns(fixture('wsaa/login_cms/fault'))
46
- -> { subject.login }.should raise_error WSError, /CMS no es valido/
47
- end
48
42
  end
49
43
 
50
44
  context 'auth' do
@@ -70,7 +70,7 @@ module Afipws
70
70
  it 'cuando la moneda no existe' do
71
71
  savon.expects(:fe_param_get_cotizacion).with(message: auth.merge(mon_id: 'PES')).returns(fixture('wsfe/fe_param_get_cotizacion/inexistente'))
72
72
  -> { ws.cotizacion('PES') }.should raise_error { |error|
73
- error.should be_a WSError
73
+ error.should be_a ResponseError
74
74
  error.message.should match /602: Sin Resultados/
75
75
  error.code?(602).should be true
76
76
  error.code?(603).should be false
@@ -195,9 +195,9 @@ module Afipws
195
195
  ws.solicitar_caea.should include caea: '21043476341977', fch_vig_desde: Date.new(2011, 0o2, 0o1)
196
196
  end
197
197
 
198
- it 'cuando hay otro error debería burbujearlo' do
198
+ it 'cuando encapsular errores' do
199
199
  savon.expects(:fecaea_solicitar).with(message: :any).returns(fixture('wsfe/fecaea_solicitar/error_distinto'))
200
- -> { ws.solicitar_caea }.should raise_error WSError, /15007/
200
+ -> { ws.solicitar_caea }.should raise_error ResponseError, /15007/
201
201
  end
202
202
  end
203
203
 
@@ -287,7 +287,7 @@ module Afipws
287
287
  it 'cuando hay un error' do
288
288
  savon.expects(:fe_param_get_tipos_cbte).with(message: :any).returns(fixture('wsfe/fe_param_get_tipos_cbte/failure_1_error'))
289
289
  -> { ws.tipos_comprobantes }.should raise_error { |e|
290
- e.should be_a WSError
290
+ e.should be_a ResponseError
291
291
  e.errors.should == [{ code: '600', msg: 'No se corresponden token con firma' }]
292
292
  e.message.should == '600: No se corresponden token con firma'
293
293
  }
@@ -296,8 +296,11 @@ module Afipws
296
296
  it 'cuando hay varios errores' do
297
297
  savon.expects(:fe_param_get_tipos_cbte).with(message: :any).returns(fixture('wsfe/fe_param_get_tipos_cbte/failure_2_errors'))
298
298
  -> { ws.tipos_comprobantes }.should raise_error { |e|
299
- e.should be_a WSError
300
- e.errors.should == [{ code: '600', msg: 'No se corresponden token con firma' }, { code: '601', msg: 'CUIT representada no incluida en token' }]
299
+ e.should be_a ResponseError
300
+ e.errors.should == [
301
+ { code: '600', msg: 'No se corresponden token con firma' },
302
+ { code: '601', msg: 'CUIT representada no incluida en token' }
303
+ ]
301
304
  e.message.should == '600: No se corresponden token con firma; 601: CUIT representada no incluida en token'
302
305
  }
303
306
  end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,6 @@ require 'rspec'
2
2
  require 'afipws'
3
3
  require 'savon/mock/spec_helper'
4
4
  require 'mocha'
5
- require 'pry-byebug'
6
5
 
7
6
  Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
8
7
 
@@ -24,14 +24,14 @@ end
24
24
 
25
25
  class HasXPath
26
26
  include RSpec::Matchers
27
-
27
+
28
28
  def initialize(paths)
29
29
  @paths = paths
30
30
  end
31
-
31
+
32
32
  def verify! xml
33
33
  @actual_xml = xml
34
- @paths.each do |(path, value)|
34
+ @paths.each do |(path, value)|
35
35
  @expected_xpath, @expected_value = path, value
36
36
  @actual_xml.should match_xpath @expected_xpath, @expected_value
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: afipws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Nicolau
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-13 00:00:00.000000000 Z
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.80.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.80.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -81,13 +81,13 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry-byebug
84
+ name: builder
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
- type: :development
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
@@ -95,33 +95,33 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: builder
98
+ name: savon
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 2.12.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 2.12.0
111
111
  - !ruby/object:Gem::Dependency
112
- name: savon
112
+ name: httpclient
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 2.11.0
117
+ version: '0'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 2.11.0
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: nokogiri
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -153,15 +153,18 @@ dependencies:
153
153
  description: ''
154
154
  email:
155
155
  - emmanicolau@gmail.com
156
- executables: []
156
+ executables:
157
+ - console
157
158
  extensions: []
158
159
  extra_rdoc_files: []
159
160
  files:
161
+ - ".envrc"
160
162
  - ".gitignore"
161
163
  - ".rspec"
162
164
  - ".rubocop.yml"
163
165
  - ".ruby-version"
164
166
  - ".travis.yml"
167
+ - CHANGELOG.md
165
168
  - Gemfile
166
169
  - Gemfile.lock
167
170
  - Guardfile
@@ -169,9 +172,14 @@ files:
169
172
  - README.md
170
173
  - Rakefile
171
174
  - afipws.gemspec
175
+ - bin/console
172
176
  - lib/afipws.rb
173
177
  - lib/afipws/client.rb
174
178
  - lib/afipws/core_ext/hash.rb
179
+ - lib/afipws/errors/error.rb
180
+ - lib/afipws/errors/network_error.rb
181
+ - lib/afipws/errors/response_error.rb
182
+ - lib/afipws/errors/server_error.rb
175
183
  - lib/afipws/persona_service_a100.rb
176
184
  - lib/afipws/persona_service_a4.rb
177
185
  - lib/afipws/persona_service_a5.rb
@@ -180,8 +188,9 @@ files:
180
188
  - lib/afipws/w_cons_declaracion.rb
181
189
  - lib/afipws/ws_constancia_inscripcion.rb
182
190
  - lib/afipws/wsaa.rb
183
- - lib/afipws/wserror.rb
184
191
  - lib/afipws/wsfe.rb
192
+ - shell.nix
193
+ - spec/afipws/client_spec.rb
185
194
  - spec/afipws/core_ext/hash_spec.rb
186
195
  - spec/afipws/persona_service_a100_spec.rb
187
196
  - spec/afipws/persona_service_a4_spec.rb
@@ -255,7 +264,7 @@ files:
255
264
  homepage: https://github.com/eeng/afipws
256
265
  licenses: []
257
266
  metadata: {}
258
- post_install_message:
267
+ post_install_message:
259
268
  rdoc_options: []
260
269
  require_paths:
261
270
  - lib
@@ -270,12 +279,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
279
  - !ruby/object:Gem::Version
271
280
  version: '0'
272
281
  requirements: []
273
- rubyforge_project: afipws
274
- rubygems_version: 2.5.1
275
- signing_key:
282
+ rubygems_version: 3.2.26
283
+ signing_key:
276
284
  specification_version: 4
277
285
  summary: Ruby client para los web services de la AFIP
278
286
  test_files:
287
+ - spec/afipws/client_spec.rb
279
288
  - spec/afipws/core_ext/hash_spec.rb
280
289
  - spec/afipws/persona_service_a100_spec.rb
281
290
  - spec/afipws/persona_service_a4_spec.rb
@@ -1,19 +0,0 @@
1
- module Afipws
2
- class WSError < StandardError
3
- attr_reader :errors
4
-
5
- def initialize errors
6
- if errors.is_a? Array
7
- super errors.map { |e| "#{e[:code]}: #{e[:msg]}" }.join '; '
8
- @errors = errors
9
- else
10
- super
11
- @errors = []
12
- end
13
- end
14
-
15
- def code? code
16
- @errors.any? { |e| e[:code].to_s == code.to_s }
17
- end
18
- end
19
- end