valvat 0.0.1 → 0.0.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.
- data/CHANGES.markdown +5 -0
- data/Gemfile.lock +0 -14
- data/{README.markdown → README.rdoc} +17 -1
- data/lib/valvat/lookup.rb +9 -24
- data/lib/valvat/version.rb +1 -1
- data/spec/valvat/lookup_spec.rb +3 -2
- data/valvat.gemspec +3 -2
- metadata +14 -28
data/CHANGES.markdown
ADDED
data/Gemfile.lock
CHANGED
@@ -2,14 +2,11 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
valvat (0.0.1)
|
5
|
-
savon (>= 0.8.2)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: http://rubygems.org/
|
9
8
|
specs:
|
10
|
-
builder (3.0.0)
|
11
9
|
configuration (1.2.0)
|
12
|
-
crack (0.1.8)
|
13
10
|
diff-lcs (1.1.2)
|
14
11
|
growl (1.0.3)
|
15
12
|
guard (0.2.2)
|
@@ -17,16 +14,11 @@ GEM
|
|
17
14
|
thor (~> 0.14.3)
|
18
15
|
guard-rspec (0.1.9)
|
19
16
|
guard (>= 0.2.2)
|
20
|
-
gyoku (0.1.1)
|
21
|
-
builder (>= 2.1.2)
|
22
|
-
httpi (0.7.7)
|
23
|
-
rack
|
24
17
|
launchy (0.3.7)
|
25
18
|
configuration (>= 0.0.5)
|
26
19
|
rake (>= 0.8.1)
|
27
20
|
open_gem (1.4.2)
|
28
21
|
launchy (~> 0.3.5)
|
29
|
-
rack (1.2.1)
|
30
22
|
rake (0.8.7)
|
31
23
|
rb-fsevent (0.3.9)
|
32
24
|
rspec (2.4.0)
|
@@ -37,11 +29,6 @@ GEM
|
|
37
29
|
rspec-expectations (2.4.0)
|
38
30
|
diff-lcs (~> 1.1.2)
|
39
31
|
rspec-mocks (2.4.0)
|
40
|
-
savon (0.8.2)
|
41
|
-
builder (>= 2.1.2)
|
42
|
-
crack (~> 0.1.8)
|
43
|
-
gyoku (>= 0.1.1)
|
44
|
-
httpi (>= 0.7.5)
|
45
32
|
thor (0.14.6)
|
46
33
|
|
47
34
|
PLATFORMS
|
@@ -52,5 +39,4 @@ DEPENDENCIES
|
|
52
39
|
guard-rspec (>= 0.1.9)
|
53
40
|
rb-fsevent (>= 0.3.9)
|
54
41
|
rspec (>= 2.4.0)
|
55
|
-
savon (>= 0.8.2)
|
56
42
|
valvat!
|
@@ -8,7 +8,7 @@ Validates european vat numbers. Supports simple syntax verification and lookup v
|
|
8
8
|
|
9
9
|
== Basic Usage
|
10
10
|
|
11
|
-
To verify the syntax of
|
11
|
+
To verify the syntax of a vat number:
|
12
12
|
|
13
13
|
Valvat::Syntax.validate("DE345789003")
|
14
14
|
=> true or false
|
@@ -22,6 +22,22 @@ Keep in mind that the VIES webservice might be offline at some time for some cou
|
|
22
22
|
|
23
23
|
See http://ec.europa.eu/taxation_customs/vies/viesspec.do for more accurate information at what time the service for a specific country will be down.
|
24
24
|
|
25
|
+
== Utilities
|
26
|
+
|
27
|
+
To split a vat number into the ISO country code and the remaining chars:
|
28
|
+
|
29
|
+
Valvat::Utils.split("ATU345789003")
|
30
|
+
=> ["AT", "U345789003"]
|
31
|
+
|
32
|
+
_split_ always returns an array. If it can not detect the country it returns [nil, nil].
|
33
|
+
|
34
|
+
To normalize a vat number:
|
35
|
+
|
36
|
+
Valvat::Utils.normalize("atu345789003")
|
37
|
+
=> "ATU345789003"
|
38
|
+
|
39
|
+
This basically just removes trailing spaces and ensures all chars are upcase.
|
40
|
+
|
25
41
|
== Links
|
26
42
|
|
27
43
|
* http://ec.europa.eu/taxation_customs/vies
|
data/lib/valvat/lookup.rb
CHANGED
@@ -1,33 +1,18 @@
|
|
1
1
|
require 'valvat/utils'
|
2
|
+
require 'net/http'
|
3
|
+
require 'yaml'
|
2
4
|
|
3
5
|
module Valvat
|
4
6
|
module Lookup
|
5
|
-
|
6
7
|
def self.validate(vat)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
rescue
|
14
|
-
false if err.to_hash[:fault] && err.to_hash[:faultstring] = 'INVALID_INPUT'
|
8
|
+
parts = Valvat::Utils.split(vat)
|
9
|
+
return false unless parts[0]
|
10
|
+
|
11
|
+
YAML.load(Net::HTTP.start("isvat.appspot.com", 80) {|http|
|
12
|
+
http.get("/#{parts.join("/")}/")
|
13
|
+
}.body)
|
14
|
+
rescue
|
15
15
|
nil
|
16
16
|
end
|
17
|
-
|
18
|
-
def self.client
|
19
|
-
@client ||= begin
|
20
|
-
# Require Savon only if really needed!
|
21
|
-
require 'savon' unless defined?(Savon)
|
22
|
-
|
23
|
-
# Quiet down Savon and HTTPI
|
24
|
-
Savon.logger.level = Logger::WARN
|
25
|
-
HTTPI.logger.level = Logger::WARN
|
26
|
-
|
27
|
-
Savon::Client.new do
|
28
|
-
wsdl.document = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
17
|
end
|
33
18
|
end
|
data/lib/valvat/version.rb
CHANGED
data/spec/valvat/lookup_spec.rb
CHANGED
@@ -10,8 +10,9 @@ describe Valvat::Lookup do
|
|
10
10
|
Valvat::Lookup.validate("BE0817331994").should eql(false)
|
11
11
|
end
|
12
12
|
|
13
|
-
it "returns
|
14
|
-
Valvat::Lookup.validate("AE259597697").should eql(
|
13
|
+
it "returns false on invalid country code / input" do
|
14
|
+
Valvat::Lookup.validate("AE259597697").should eql(false)
|
15
|
+
Valvat::Lookup.validate("").should eql(false)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
data/valvat.gemspec
CHANGED
@@ -17,10 +17,11 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
s.add_dependency 'savon', '>=0.8.2'
|
21
|
-
|
22
20
|
s.add_development_dependency 'rspec', '>= 2.4.0'
|
23
21
|
s.add_development_dependency 'guard-rspec', '>=0.1.9'
|
24
22
|
s.add_development_dependency 'growl', '>=1.0.3'
|
25
23
|
s.add_development_dependency 'rb-fsevent', '>=0.3.9'
|
24
|
+
|
25
|
+
s.has_rdoc = true
|
26
|
+
s.extra_rdoc_files = ['README.rdoc']
|
26
27
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sebastian Munz
|
@@ -17,25 +17,10 @@ cert_chain: []
|
|
17
17
|
date: 2011-01-06 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
name: savon
|
22
|
-
prerelease: false
|
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
20
|
- !ruby/object:Gem::Dependency
|
36
21
|
name: rspec
|
37
22
|
prerelease: false
|
38
|
-
requirement: &
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
39
24
|
none: false
|
40
25
|
requirements:
|
41
26
|
- - ">="
|
@@ -46,11 +31,11 @@ dependencies:
|
|
46
31
|
- 0
|
47
32
|
version: 2.4.0
|
48
33
|
type: :development
|
49
|
-
version_requirements: *
|
34
|
+
version_requirements: *id001
|
50
35
|
- !ruby/object:Gem::Dependency
|
51
36
|
name: guard-rspec
|
52
37
|
prerelease: false
|
53
|
-
requirement: &
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
54
39
|
none: false
|
55
40
|
requirements:
|
56
41
|
- - ">="
|
@@ -61,11 +46,11 @@ dependencies:
|
|
61
46
|
- 9
|
62
47
|
version: 0.1.9
|
63
48
|
type: :development
|
64
|
-
version_requirements: *
|
49
|
+
version_requirements: *id002
|
65
50
|
- !ruby/object:Gem::Dependency
|
66
51
|
name: growl
|
67
52
|
prerelease: false
|
68
|
-
requirement: &
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
69
54
|
none: false
|
70
55
|
requirements:
|
71
56
|
- - ">="
|
@@ -76,11 +61,11 @@ dependencies:
|
|
76
61
|
- 3
|
77
62
|
version: 1.0.3
|
78
63
|
type: :development
|
79
|
-
version_requirements: *
|
64
|
+
version_requirements: *id003
|
80
65
|
- !ruby/object:Gem::Dependency
|
81
66
|
name: rb-fsevent
|
82
67
|
prerelease: false
|
83
|
-
requirement: &
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
84
69
|
none: false
|
85
70
|
requirements:
|
86
71
|
- - ">="
|
@@ -91,7 +76,7 @@ dependencies:
|
|
91
76
|
- 9
|
92
77
|
version: 0.3.9
|
93
78
|
type: :development
|
94
|
-
version_requirements: *
|
79
|
+
version_requirements: *id004
|
95
80
|
description: Validates european vat numbers. Supports simple syntax verification and lookup via the VIES web service.
|
96
81
|
email:
|
97
82
|
- sebastian@yo.lk
|
@@ -99,16 +84,17 @@ executables: []
|
|
99
84
|
|
100
85
|
extensions: []
|
101
86
|
|
102
|
-
extra_rdoc_files:
|
103
|
-
|
87
|
+
extra_rdoc_files:
|
88
|
+
- README.rdoc
|
104
89
|
files:
|
105
90
|
- .gitignore
|
106
91
|
- .rvmrc
|
92
|
+
- CHANGES.markdown
|
107
93
|
- Gemfile
|
108
94
|
- Gemfile.lock
|
109
95
|
- Guardfile
|
110
96
|
- MIT-LICENSE
|
111
|
-
- README.
|
97
|
+
- README.rdoc
|
112
98
|
- Rakefile
|
113
99
|
- lib/valvat.rb
|
114
100
|
- lib/valvat/lookup.rb
|