valvat 0.4.1 → 0.4.2

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.
@@ -0,0 +1 @@
1
+ plugin
@@ -0,0 +1 @@
1
+ 1.9.3-p286
data/CHANGES.md CHANGED
@@ -1,6 +1,14 @@
1
1
  ### dev
2
2
 
3
- [full changelog](http://github.com/yolk/valvat/compare/v0.4.1...master)
3
+ [full changelog](http://github.com/yolk/valvat/compare/v0.4.2...master)
4
+
5
+ ### 0.4.2 / 2012-11-16
6
+
7
+ [full changelog](http://github.com/yolk/valvat/compare/v0.4,1...v0.4.2)
8
+
9
+ * Fixed usage with savon version 1.2
10
+ * Require version 1.2 of the savon gem from now on
11
+ * Added :raise_error option to throw errors instead of returning nil
4
12
 
5
13
  ### 0.4.1 / 2012-07-17
6
14
 
@@ -9,19 +9,19 @@ class Valvat
9
9
  vat = Valvat(vat)
10
10
  return false unless vat.european?
11
11
 
12
- request = options[:requester_vat] ?
13
- Valvat::Lookup::RequestWithId.new(vat, Valvat(options[:requester_vat])) :
12
+ request = options[:requester_vat] ?
13
+ Valvat::Lookup::RequestWithId.new(vat, Valvat(options[:requester_vat])) :
14
14
  Valvat::Lookup::Request.new(vat)
15
-
15
+
16
16
  begin
17
17
  response = request.perform(self.client)
18
- response[:valid] && (options[:detail] || options[:requester_vat]) ?
18
+ response[:valid] && (options[:detail] || options[:requester_vat]) ?
19
19
  filter_detail(response) : response[:valid]
20
20
  rescue => err
21
- @last_error = err
22
- if err.respond_to?(:to_hash) && err.to_hash[:fault] && err.to_hash[:fault][:faultstring] == "{ 'INVALID_INPUT' }"
21
+ if err.respond_to?(:to_hash) && err.to_hash[:fault] && e(rr.to_hash[:fault][:faultstring] || "").upcase =~ /INVALID_INPUT/
23
22
  return false
24
23
  end
24
+ raise err if options[:raise_error]
25
25
  nil
26
26
  end
27
27
  end
@@ -37,20 +37,14 @@ class Valvat
37
37
  end
38
38
  HTTPI.log = false
39
39
 
40
- Savon::Client.new do
41
- wsdl.document = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'
42
- end
40
+ Savon::Client.new('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl')
43
41
  end
44
42
  end
45
-
46
- def self.last_error
47
- @last_error
48
- end
49
-
43
+
50
44
  private
51
-
52
- REMOVE_KEYS = [:valid, :@xmlns]
53
-
45
+
46
+ REMOVE_KEYS = [:valid, :@xmlns]
47
+
54
48
  def self.filter_detail(response)
55
49
  response.inject({}) do |hash, kv|
56
50
  key, value = kv
@@ -4,24 +4,23 @@ class Valvat
4
4
  def initialize(vat)
5
5
  @vat = vat
6
6
  end
7
-
7
+
8
8
  def perform(client)
9
- client.request("n1", action) do
10
- soap.body = body
11
- soap.namespaces["xmlns:n1"] = "urn:ec.europa.eu:taxud:vies:services:checkVat:types"
9
+ client.request(action) do |r|
10
+ r.body = body
12
11
  end.to_hash[response_key]
13
12
  end
14
-
13
+
15
14
  private
16
-
15
+
17
16
  def body
18
- {"n1:countryCode" => @vat.vat_country_code, "n1:vatNumber" => @vat.to_s_wo_country}
17
+ {:country_code => @vat.vat_country_code, :vat_number => @vat.to_s_wo_country}
19
18
  end
20
-
19
+
21
20
  def action
22
- "checkVat"
21
+ :check_vat
23
22
  end
24
-
23
+
25
24
  def response_key
26
25
  :check_vat_response
27
26
  end
@@ -5,20 +5,20 @@ class Valvat
5
5
  @vat = vat
6
6
  @requester_vat = requester_vat
7
7
  end
8
-
8
+
9
9
  private
10
-
10
+
11
11
  def body
12
12
  super.merge(
13
- "n1:requesterCountryCode" => @requester_vat.vat_country_code,
14
- "n1:requesterVatNumber" => @requester_vat.to_s_wo_country
13
+ :requester_country_code => @requester_vat.vat_country_code,
14
+ :requester_vat_number => @requester_vat.to_s_wo_country
15
15
  )
16
16
  end
17
-
17
+
18
18
  def action
19
- "checkVatApprox"
19
+ :check_vat_approx
20
20
  end
21
-
21
+
22
22
  def response_key
23
23
  :check_vat_approx_response
24
24
  end
@@ -1,3 +1,3 @@
1
1
  class Valvat
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -6,6 +6,13 @@ require File.dirname(__FILE__) + '/../lib/valvat.rb'
6
6
 
7
7
  $fakeweb = true
8
8
 
9
+ RSpec.configure do |config|
10
+ config.mock_with :rspec
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.filter_run :focus => true
13
+ config.run_all_when_everything_filtered = true
14
+ end
15
+
9
16
  class ModelBase
10
17
  include ActiveModel::Serialization
11
18
  include ActiveModel::Validations
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Valvat::Lookup do
4
- context "#validate" do
4
+ describe "#validate" do
5
5
  context "existing vat number" do
6
6
 
7
7
  it "returns true" do
@@ -27,41 +27,41 @@ describe Valvat::Lookup do
27
27
  Valvat::Lookup.validate("").should eql(false)
28
28
  end
29
29
  end
30
-
30
+
31
31
  context "with details" do
32
32
  it "returns hash of details instead of true" do
33
33
  Valvat::Lookup.validate("IE6388047V", :detail => true).should eql({
34
- :country_code=>"IE",
35
- :vat_number=>"6388047V",
36
- :request_date=> Date.today,
37
- :name=>"GOOGLE IRELAND LIMITED",
34
+ :country_code=>"IE",
35
+ :vat_number=>"6388047V",
36
+ :request_date=> Date.today,
37
+ :name=>"GOOGLE IRELAND LIMITED",
38
38
  :address=>"1ST & 2ND FLOOR ,GORDON HOUSE ,BARROW STREET ,DUBLIN 4"
39
39
  })
40
-
40
+
41
41
  Valvat::Lookup.validate("LU21416127", :detail => true).should eql({
42
- :country_code=>"LU",
43
- :vat_number=>"21416127",
44
- :request_date=> Date.today,
45
- :name=>"EBAY EUROPE S.A R.L.",
42
+ :country_code=>"LU",
43
+ :vat_number=>"21416127",
44
+ :request_date=> Date.today,
45
+ :name=>"EBAY EUROPE S.A R.L.",
46
46
  :address=>"22, BOULEVARD ROYAL\nL-2449 LUXEMBOURG"
47
47
  })
48
48
  end
49
-
49
+
50
50
  it "still returns false on not existing vat number" do
51
51
  Valvat::Lookup.validate("BE08173319921", :detail => true).should eql(false)
52
52
  end
53
53
  end
54
-
54
+
55
55
  context "with request identifier" do
56
56
  it "returns hash of details instead of true" do
57
57
  response = Valvat::Lookup.validate("LU21416127", :requester_vat => "IE6388047V")
58
58
  response[:request_identifier].size.should eql(16)
59
59
  response[:request_identifier] = "some_uniq_string"
60
60
  response.should eql({
61
- :country_code=>"LU",
62
- :vat_number=>"21416127",
63
- :request_date=> Date.today,
64
- :name => "EBAY EUROPE S.A R.L.",
61
+ :country_code=>"LU",
62
+ :vat_number=>"21416127",
63
+ :request_date=> Date.today,
64
+ :name => "EBAY EUROPE S.A R.L.",
65
65
  :address => "22, BOULEVARD ROYAL\nL-2449 LUXEMBOURG",
66
66
  :company_type => nil,
67
67
  :request_identifier => "some_uniq_string"
@@ -69,13 +69,29 @@ describe Valvat::Lookup do
69
69
  end
70
70
  end
71
71
 
72
+ context "error on request" do
73
+ before do
74
+ @request = mock("request")
75
+ Valvat::Lookup::Request.stub(:new => @request)
76
+ @request.stub(:perform).and_raise(ArgumentError.new)
77
+ end
78
+
79
+ it "should return nil" do
80
+ Valvat::Lookup.validate("LU21416127").should eql(nil)
81
+ end
82
+
83
+ it "should raise error with raise_error option" do
84
+ lambda {Valvat::Lookup.validate("LU21416127", :raise_error => true)}.should raise_error(ArgumentError)
85
+ end
86
+ end
87
+
72
88
  # TODO : Reactivate with coorect "down" response
73
89
  # context "country web service down" do
74
90
  # before do
75
91
  # json = "{\"error_message\": \"Member State service unavailable.\", \"error_code\": 1, \"error\": true}"
76
92
  # FakeWeb.register_uri(:get, "http://isvat.appspot.com/DE/259597697/", :body => json)
77
93
  # end if $fakeweb
78
- #
94
+
79
95
  # it "returns nil" do
80
96
  # Valvat::Lookup.validate("DE259597697").should eql(nil)
81
97
  # end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Valvat::Syntax do
4
- context "#validate" do
4
+ describe "#validate" do
5
5
  it "validates a DE vat number" do
6
6
  Valvat::Syntax.validate("DE345889003").should eql(true)
7
7
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Valvat::Utils do
4
- context "#split" do
4
+ describe "#split" do
5
5
  it "returns country and rest on vat number as array" do
6
6
  Valvat::Utils.split("DE345889003").should eql(["DE", "345889003"])
7
7
  Valvat::Utils.split("ESX4588900X").should eql(["ES", "X4588900X"])
@@ -25,7 +25,7 @@ describe Valvat::Utils do
25
25
  end
26
26
  end
27
27
 
28
- context "#normalize" do
28
+ describe "#normalize" do
29
29
  it "returns vat number with upcase chars" do
30
30
  Valvat::Utils.normalize("de345889003").should eql("DE345889003")
31
31
  Valvat::Utils.normalize("EsX4588900y").should eql("ESX4588900Y")
@@ -52,7 +52,7 @@ describe Valvat::Utils do
52
52
  end
53
53
  end
54
54
 
55
- context "#vat_country_to_iso_country" do
55
+ describe "#vat_country_to_iso_country" do
56
56
  it "returns iso country code on greek iso language 'EL'" do
57
57
  Valvat::Utils.vat_country_to_iso_country("EL").should eql("GR")
58
58
  end
@@ -64,7 +64,7 @@ describe Valvat::Utils do
64
64
  end
65
65
  end
66
66
 
67
- context "#iso_country_to_vat_country" do
67
+ describe "#iso_country_to_vat_country" do
68
68
  it "returns vat country on greek iso country code 'GR'" do
69
69
  Valvat::Utils.iso_country_to_vat_country("GR").should eql("EL")
70
70
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Valvat do
6
- context "#new" do
6
+ describe "#new" do
7
7
  it "demands one and only one argument" do
8
8
  lambda{ Valvat.new }.should raise_error(ArgumentError)
9
9
  lambda{ Valvat.new("a", "b") }.should raise_error(ArgumentError)
@@ -33,7 +33,7 @@ describe Valvat do
33
33
  let(:at_vat) { Valvat.new("ATU458890031") } # invalid
34
34
  let(:gr_vat) { Valvat.new("EL999943280") } # valid & exists
35
35
 
36
- context "#valid?" do
36
+ describe "#valid?" do
37
37
  it "returns true on valid numbers" do
38
38
  de_vat.should be_valid
39
39
  gr_vat.should be_valid
@@ -44,7 +44,7 @@ describe Valvat do
44
44
  end
45
45
  end
46
46
 
47
- context "#exist(s)?" do
47
+ describe "#exist(s)?" do
48
48
  context "on existing vat numbers" do
49
49
  before do
50
50
  Valvat::Lookup.stub(:validate => true)
@@ -77,7 +77,7 @@ describe Valvat do
77
77
  end
78
78
  end
79
79
 
80
- context "#iso_country_code" do
80
+ describe "#iso_country_code" do
81
81
  it "returns iso country code on iso_country_code" do
82
82
  de_vat.iso_country_code.should eql("DE")
83
83
  at_vat.iso_country_code.should eql("AT")
@@ -88,7 +88,7 @@ describe Valvat do
88
88
  end
89
89
  end
90
90
 
91
- context "#vat_country_code" do
91
+ describe "#vat_country_code" do
92
92
  it "returns iso country code on iso_country_code" do
93
93
  de_vat.vat_country_code.should eql("DE")
94
94
  at_vat.vat_country_code.should eql("AT")
@@ -99,7 +99,7 @@ describe Valvat do
99
99
  end
100
100
  end
101
101
 
102
- context "#european?" do
102
+ describe "#european?" do
103
103
  it "returns true" do
104
104
  de_vat.should be_european
105
105
  at_vat.should be_european
@@ -107,7 +107,7 @@ describe Valvat do
107
107
  end
108
108
  end
109
109
 
110
- context "#to_s" do
110
+ describe "#to_s" do
111
111
  it "returns full vat number" do
112
112
  de_vat.to_s.should eql("DE259597697")
113
113
  at_vat.to_s.should eql("ATU458890031")
@@ -115,7 +115,7 @@ describe Valvat do
115
115
  end
116
116
  end
117
117
 
118
- context "#inspect" do
118
+ describe "#inspect" do
119
119
  it "returns vat number with iso country code" do
120
120
  de_vat.inspect.should eql("#<Valvat DE259597697 DE>")
121
121
  at_vat.inspect.should eql("#<Valvat ATU458890031 AT>")
@@ -123,7 +123,7 @@ describe Valvat do
123
123
  end
124
124
  end
125
125
 
126
- context "#to_a" do
126
+ describe "#to_a" do
127
127
  it "calls Valvat::Utils.split with raw vat number and returns result" do
128
128
  de_vat # initialize
129
129
  Valvat::Utils.should_receive(:split).once.with("DE259597697").and_return(["a", "b"])
@@ -136,14 +136,14 @@ describe Valvat do
136
136
  let(:us_vat) { Valvat.new("US345889003") }
137
137
  let(:ch_vat) { Valvat.new("CH445889003") }
138
138
 
139
- context "#valid?" do
139
+ describe "#valid?" do
140
140
  it "returns false" do
141
141
  us_vat.should_not be_valid
142
142
  ch_vat.should_not be_valid
143
143
  end
144
144
  end
145
145
 
146
- context "#exist?" do
146
+ describe "#exist?" do
147
147
  without_any_web_requests!
148
148
 
149
149
  it "returns false" do
@@ -152,35 +152,35 @@ describe Valvat do
152
152
  end
153
153
  end
154
154
 
155
- context "#iso_country_code" do
155
+ describe "#iso_country_code" do
156
156
  it "returns nil" do
157
157
  us_vat.iso_country_code.should eql(nil)
158
158
  ch_vat.iso_country_code.should eql(nil)
159
159
  end
160
160
  end
161
161
 
162
- context "#vat_country_code" do
162
+ describe "#vat_country_code" do
163
163
  it "returns nil" do
164
164
  us_vat.vat_country_code.should eql(nil)
165
165
  ch_vat.vat_country_code.should eql(nil)
166
166
  end
167
167
  end
168
168
 
169
- context "#european?" do
169
+ describe "#european?" do
170
170
  it "returns false" do
171
171
  us_vat.should_not be_european
172
172
  ch_vat.should_not be_european
173
173
  end
174
174
  end
175
175
 
176
- context "#to_s" do
176
+ describe "#to_s" do
177
177
  it "returns full given vat number" do
178
178
  us_vat.to_s.should eql("US345889003")
179
179
  ch_vat.to_s.should eql("CH445889003")
180
180
  end
181
181
  end
182
182
 
183
- context "#inspect" do
183
+ describe "#inspect" do
184
184
  it "returns vat number without iso country code" do
185
185
  us_vat.inspect.should eql("#<Valvat US345889003>")
186
186
  ch_vat.inspect.should eql("#<Valvat CH445889003>")
@@ -195,7 +195,7 @@ describe Valvat do
195
195
  let(:empty_vat) { Valvat.new("") }
196
196
  let(:nil_vat) { Valvat.new("") }
197
197
 
198
- context "#valid?" do
198
+ describe "#valid?" do
199
199
  it "returns false" do
200
200
  only_iso_vat.should_not be_valid
201
201
  num_vat.should_not be_valid
@@ -204,7 +204,7 @@ describe Valvat do
204
204
  end
205
205
  end
206
206
 
207
- context "#exist?" do
207
+ describe "#exist?" do
208
208
  without_any_web_requests!
209
209
 
210
210
  it "returns false" do
@@ -215,7 +215,7 @@ describe Valvat do
215
215
  end
216
216
  end
217
217
 
218
- context "#iso_country_code" do
218
+ describe "#iso_country_code" do
219
219
  it "returns nil" do
220
220
  only_iso_vat.iso_country_code.should eql(nil)
221
221
  num_vat.iso_country_code.should eql(nil)
@@ -224,7 +224,7 @@ describe Valvat do
224
224
  end
225
225
  end
226
226
 
227
- context "#vat_country_code" do
227
+ describe "#vat_country_code" do
228
228
  it "returns nil" do
229
229
  only_iso_vat.vat_country_code.should eql(nil)
230
230
  num_vat.vat_country_code.should eql(nil)
@@ -233,7 +233,7 @@ describe Valvat do
233
233
  end
234
234
  end
235
235
 
236
- context "#european?" do
236
+ describe "#european?" do
237
237
  it "returns false" do
238
238
  only_iso_vat.should_not be_european
239
239
  num_vat.should_not be_european
@@ -242,7 +242,7 @@ describe Valvat do
242
242
  end
243
243
  end
244
244
 
245
- context "#to_s" do
245
+ describe "#to_s" do
246
246
  it "returns full given vat number" do
247
247
  only_iso_vat.to_s.should eql("DE")
248
248
  num_vat.to_s.should eql("12445889003")
@@ -251,7 +251,7 @@ describe Valvat do
251
251
  end
252
252
  end
253
253
 
254
- context "#inspect" do
254
+ describe "#inspect" do
255
255
  it "returns vat number without iso country code" do
256
256
  only_iso_vat.inspect.should eql("#<Valvat DE>")
257
257
  num_vat.inspect.should eql("#<Valvat 12445889003>")
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
 
16
16
  * Simple syntax verification
17
17
  * Lookup via the VIES web service
18
- * Works standalone without any gem dependencies
18
+ * Supports details & requester identification
19
19
  * (Optional) ActiveModel/Rails3 integration
20
20
  * I18n locales for country specific error messages
21
21
  END
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
28
  s.require_paths = ["lib"]
29
29
 
30
- s.add_dependency 'savon', '>=0.9.12'
30
+ s.add_dependency 'savon', '>=1.2.0'
31
31
 
32
32
  s.add_development_dependency 'rspec', '>= 2.4.0'
33
33
  s.add_development_dependency 'guard-rspec', '>=0.1.9'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valvat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-17 00:00:00.000000000 Z
12
+ date: 2012-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.9.12
21
+ version: 1.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.9.12
29
+ version: 1.2.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -124,9 +124,9 @@ dependencies:
124
124
  - !ruby/object:Gem::Version
125
125
  version: 1.3.0
126
126
  description: ! " Validates european vat numbers. Standalone or as a ActiveModel validator.\n\n
127
- \ * Simple syntax verification\n * Lookup via the VIES web service\n * Works standalone
128
- without any gem dependencies\n * (Optional) ActiveModel/Rails3 integration\n *
129
- I18n locales for country specific error messages\n"
127
+ \ * Simple syntax verification\n * Lookup via the VIES web service\n * Supports
128
+ details & requester identification\n * (Optional) ActiveModel/Rails3 integration\n
129
+ \ * I18n locales for country specific error messages\n"
130
130
  email:
131
131
  - sebastian@yo.lk
132
132
  executables: []
@@ -134,7 +134,8 @@ extensions: []
134
134
  extra_rdoc_files: []
135
135
  files:
136
136
  - .gitignore
137
- - .rvmrc
137
+ - .rbenv-gemsets
138
+ - .rbenv-version
138
139
  - CHANGES.md
139
140
  - Gemfile
140
141
  - Guardfile
@@ -171,21 +172,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
172
  - - ! '>='
172
173
  - !ruby/object:Gem::Version
173
174
  version: '0'
174
- segments:
175
- - 0
176
- hash: -443670798108934611
177
175
  required_rubygems_version: !ruby/object:Gem::Requirement
178
176
  none: false
179
177
  requirements:
180
178
  - - ! '>='
181
179
  - !ruby/object:Gem::Version
182
180
  version: '0'
183
- segments:
184
- - 0
185
- hash: -443670798108934611
186
181
  requirements: []
187
182
  rubyforge_project:
188
- rubygems_version: 1.8.24
183
+ rubygems_version: 1.8.23
189
184
  signing_key:
190
185
  specification_version: 3
191
186
  summary: Validates european vat numbers. Standalone or as a ActiveModel validator.
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-1.9.3@valvat --create