valvat 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,6 +1,13 @@
1
1
  ### dev
2
2
 
3
- [full changelog](http://github.com/yolk/valvat/compare/v0.2.1...master)
3
+ [full changelog](http://github.com/yolk/valvat/compare/v0.2.2...master)
4
+
5
+ ### 0.2.2 / 2011-01-10
6
+
7
+ [full changelog](http://github.com/yolk/valvat/compare/v0.2.1...v0.2.2)
8
+
9
+ * Using vies directly via soap/savon again; isvat.appspot.com is not _really_ reliable.
10
+ * Added support for Valvat#exist? as an alias of Valvat#exists?
4
11
 
5
12
  ### 0.2.1 / 2011-01-07
6
13
 
data/README.md CHANGED
@@ -6,8 +6,8 @@ Validates european vat numbers. Standalone or as a ActiveModel validator.
6
6
 
7
7
  * Simple syntax verification
8
8
  * Lookup via the VIES web service
9
- * Works standalone without any gem dependencies
10
9
  * (Optional) ActiveModel/Rails3 integration
10
+ * Works standalone without ActiveModel
11
11
  * I18n locales for country specific error messages
12
12
 
13
13
  valvat is tested and works with ruby 1.8.7/1.9.2 and ActiveModel 3.0.
@@ -70,13 +70,13 @@ By default blank vat numbers validate to false. To change this add the `:allow_b
70
70
 
71
71
  To allow vat numbers from outside of europe, add something like this to your model (country_code should return a upcase iso country code):
72
72
 
73
- class MyModel < ActiveRecord::Base
74
- validates :vat_number, :valvat => true, :if => :eu?
75
-
76
- def eu?
77
- Valvat::Utils::EU_COUNTRIES.include?(country_code)
73
+ class MyModel < ActiveRecord::Base
74
+ validates :vat_number, :valvat => true, :if => :eu?
75
+
76
+ def eu?
77
+ Valvat::Utils::EU_COUNTRIES.include?(country_code)
78
+ end
78
79
  end
79
- end
80
80
 
81
81
  ### Utilities
82
82
 
@@ -114,7 +114,6 @@ This basically just removes trailing spaces and ensures all chars are uppercase.
114
114
  * [VIES web service](http://ec.europa.eu/taxation_customs/vies)
115
115
  * [European vat number formats (german)](http://bzst.de/DE/Steuern_International/USt_Identifikationsnummer/Merkblaetter/Aufbau_USt_IdNr.html)
116
116
  * [European vat number formats on Wikipedia](http://en.wikipedia.org/wiki/European_Union_Value_Added_Tax)
117
- * [isvat VIES REST wrapper](http://isvat.appspot.com/)
118
117
 
119
118
  ### BlaBla
120
119
 
data/lib/valvat.rb CHANGED
@@ -13,6 +13,7 @@ class Valvat
13
13
  def exists?
14
14
  Valvat::Lookup.validate(self)
15
15
  end
16
+ alias_method :exist?, :exists?
16
17
 
17
18
  def iso_country_code
18
19
  Valvat::Utils.vat_country_to_iso_country(vat_country_code)
data/lib/valvat/lookup.rb CHANGED
@@ -4,20 +4,37 @@ require 'yaml'
4
4
 
5
5
  class Valvat
6
6
  module Lookup
7
+
7
8
  def self.validate(vat)
8
9
  vat = Valvat(vat)
9
10
  return false unless vat.european?
10
- result = begin
11
- YAML.load(Net::HTTP.start("isvat.appspot.com", 80) {|http|
12
- http.get("/#{vat.to_a.join("/")}/")
13
- }.body)
11
+
12
+ begin
13
+ client.request("n1", "checkVat") do
14
+ soap.body = {"n1:countryCode" => vat.vat_country_code, "n1:vatNumber" => vat.to_s_wo_country}
15
+ soap.namespaces["xmlns:n1"] = "urn:ec.europa.eu:taxud:vies:services:checkVat:types"
16
+ end.to_hash[:check_vat_response][:valid]
14
17
  rescue => err
15
- # Ugly, ugly for better specs
16
- raise if defined?(FakeWeb::NetConnectNotAllowedError) && FakeWeb::NetConnectNotAllowedError === err
18
+ if err.respond_to?(:to_hash) && err.to_hash[:fault] && err.to_hash[:fault][:faultstring] == "{ 'INVALID_INPUT' }"
19
+ return false
20
+ end
17
21
  nil
18
22
  end
19
-
20
- result.is_a?(Hash) && result["error_code"] == 1 ? nil : result
23
+ end
24
+
25
+ def self.client
26
+ @client ||= begin
27
+ # Require Savon only if really needed!
28
+ require 'savon' unless defined?(Savon)
29
+
30
+ # Quiet down Savon and HTTPI
31
+ Savon.logger.level = Logger::WARN
32
+ HTTPI.logger.level = Logger::WARN
33
+
34
+ Savon::Client.new do
35
+ wsdl.document = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'
36
+ end
37
+ end
21
38
  end
22
39
  end
23
40
  end
@@ -1,3 +1,3 @@
1
1
  class Valvat
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -3,9 +3,6 @@ require 'spec_helper'
3
3
  describe Valvat::Lookup do
4
4
  context "#validate" do
5
5
  context "existing vat number" do
6
- before do
7
- FakeWeb.register_uri(:get, "http://isvat.appspot.com/BE/0817331995/", :body => "true")
8
- end if $fakeweb
9
6
 
10
7
  it "returns true" do
11
8
  Valvat::Lookup.validate("BE0817331995").should eql(true)
@@ -17,12 +14,8 @@ describe Valvat::Lookup do
17
14
  end
18
15
 
19
16
  context "not existing vat number" do
20
- before do
21
- FakeWeb.register_uri(:get, "http://isvat.appspot.com/BE/0817331995/", :body => "false")
22
- end if $fakeweb
23
-
24
17
  it "returns false" do
25
- Valvat::Lookup.validate("BE0817331995").should eql(false)
18
+ Valvat::Lookup.validate("BE08173319921").should eql(false)
26
19
  end
27
20
  end
28
21
 
@@ -35,15 +28,16 @@ describe Valvat::Lookup do
35
28
  end
36
29
  end
37
30
 
38
- context "country web service down" do
39
- before do
40
- json = "{\"error_message\": \"Member State service unavailable.\", \"error_code\": 1, \"error\": true}"
41
- FakeWeb.register_uri(:get, "http://isvat.appspot.com/DE/259597697/", :body => json)
42
- end if $fakeweb
43
-
44
- it "returns nil" do
45
- Valvat::Lookup.validate("DE259597697").should eql(nil)
46
- end
47
- end
31
+ # TODO : Reactivate with coorect "down" response
32
+ # context "country web service down" do
33
+ # before do
34
+ # json = "{\"error_message\": \"Member State service unavailable.\", \"error_code\": 1, \"error\": true}"
35
+ # FakeWeb.register_uri(:get, "http://isvat.appspot.com/DE/259597697/", :body => json)
36
+ # end if $fakeweb
37
+ #
38
+ # it "returns nil" do
39
+ # Valvat::Lookup.validate("DE259597697").should eql(nil)
40
+ # end
41
+ # end
48
42
  end
49
43
  end
data/spec/valvat_spec.rb CHANGED
@@ -39,15 +39,17 @@ describe Valvat do
39
39
  end
40
40
  end
41
41
 
42
- context "#exist?" do
42
+ context "#exist(s)?" do
43
43
  context "on existing vat numbers" do
44
44
  before do
45
45
  Valvat::Lookup.stub(:validate => true)
46
46
  end
47
47
 
48
48
  it "returns true" do
49
- de_vat.should be_exist
50
- gr_vat.should be_exist
49
+ de_vat.exists?.should eql(true)
50
+ gr_vat.exists?.should eql(true)
51
+ de_vat.exist?.should eql(true)
52
+ gr_vat.exist?.should eql(true)
51
53
  end
52
54
  end
53
55
 
@@ -57,7 +59,8 @@ describe Valvat do
57
59
  end
58
60
 
59
61
  it "returns false" do
60
- at_vat.should_not be_exist
62
+ at_vat.exists?.should eql(false)
63
+ at_vat.exist?.should eql(false)
61
64
  end
62
65
  end
63
66
  end
data/valvat.gemspec CHANGED
@@ -27,10 +27,12 @@ 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_development_dependency 'rspec', '>= 2.4.0'
30
+ s.add_dependency 'savon', '>=0.8.2'
31
+
32
+ s.add_development_dependency 'rspec', '>= 2.4.0'
31
33
  s.add_development_dependency 'guard-rspec', '>=0.1.9'
32
- s.add_development_dependency 'growl', '>=1.0.3'
33
- s.add_development_dependency 'rb-fsevent', '>=0.3.9'
34
+ s.add_development_dependency 'growl', '>=1.0.3'
35
+ s.add_development_dependency 'rb-fsevent', '>=0.3.9'
34
36
  s.add_development_dependency 'activemodel', '>=3.0'
35
- s.add_development_dependency 'fakeweb'
37
+ s.add_development_dependency 'fakeweb', '>= 1.3.0'
36
38
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sebastian Munz
@@ -14,13 +14,28 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-07 00:00:00 +01:00
17
+ date: 2011-01-10 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rspec
21
+ name: savon
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 8
31
+ - 2
32
+ version: 0.8.2
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
24
39
  none: false
25
40
  requirements:
26
41
  - - ">="
@@ -31,11 +46,11 @@ dependencies:
31
46
  - 0
32
47
  version: 2.4.0
33
48
  type: :development
34
- version_requirements: *id001
49
+ version_requirements: *id002
35
50
  - !ruby/object:Gem::Dependency
36
51
  name: guard-rspec
37
52
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
53
+ requirement: &id003 !ruby/object:Gem::Requirement
39
54
  none: false
40
55
  requirements:
41
56
  - - ">="
@@ -46,11 +61,11 @@ dependencies:
46
61
  - 9
47
62
  version: 0.1.9
48
63
  type: :development
49
- version_requirements: *id002
64
+ version_requirements: *id003
50
65
  - !ruby/object:Gem::Dependency
51
66
  name: growl
52
67
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
68
+ requirement: &id004 !ruby/object:Gem::Requirement
54
69
  none: false
55
70
  requirements:
56
71
  - - ">="
@@ -61,11 +76,11 @@ dependencies:
61
76
  - 3
62
77
  version: 1.0.3
63
78
  type: :development
64
- version_requirements: *id003
79
+ version_requirements: *id004
65
80
  - !ruby/object:Gem::Dependency
66
81
  name: rb-fsevent
67
82
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
83
+ requirement: &id005 !ruby/object:Gem::Requirement
69
84
  none: false
70
85
  requirements:
71
86
  - - ">="
@@ -76,11 +91,11 @@ dependencies:
76
91
  - 9
77
92
  version: 0.3.9
78
93
  type: :development
79
- version_requirements: *id004
94
+ version_requirements: *id005
80
95
  - !ruby/object:Gem::Dependency
81
96
  name: activemodel
82
97
  prerelease: false
83
- requirement: &id005 !ruby/object:Gem::Requirement
98
+ requirement: &id006 !ruby/object:Gem::Requirement
84
99
  none: false
85
100
  requirements:
86
101
  - - ">="
@@ -90,20 +105,22 @@ dependencies:
90
105
  - 0
91
106
  version: "3.0"
92
107
  type: :development
93
- version_requirements: *id005
108
+ version_requirements: *id006
94
109
  - !ruby/object:Gem::Dependency
95
110
  name: fakeweb
96
111
  prerelease: false
97
- requirement: &id006 !ruby/object:Gem::Requirement
112
+ requirement: &id007 !ruby/object:Gem::Requirement
98
113
  none: false
99
114
  requirements:
100
115
  - - ">="
101
116
  - !ruby/object:Gem::Version
102
117
  segments:
118
+ - 1
119
+ - 3
103
120
  - 0
104
- version: "0"
121
+ version: 1.3.0
105
122
  type: :development
106
- version_requirements: *id006
123
+ version_requirements: *id007
107
124
  description: " Validates european vat numbers. Standalone or as a ActiveModel validator.\n \n * Simple syntax verification\n * Lookup via the VIES web service\n * Works standalone without any gem dependencies\n * (Optional) ActiveModel/Rails3 integration\n * I18n locales for country specific error messages\n"
108
125
  email:
109
126
  - sebastian@yo.lk