Permalink
Browse files

Ground up rewrite

  • Loading branch information...
1 parent b831a44 commit 2092560f28f97fc381e3dcddca202561d7f6f785 Neil Middleton committed Oct 13, 2011
Showing with 95 additions and 142 deletions.
  1. +4 −3 .gitignore
  2. +1 −0 .rspec
  3. +4 −0 Gemfile
  4. +0 −20 LICENSE
  5. +0 −5 Manifest
  6. +1 −12 Rakefile
  7. +0 −30 Readme.rdoc
  8. +0 −1 VERSION
  9. +32 −25 lib/vatman.rb
  10. +3 −0 lib/vatman/version.rb
  11. +8 −0 spec/spec_helper.rb
  12. +25 −0 spec/vatman_spec.rb
  13. +0 −2 test/test_helper.rb
  14. +0 −18 test/test_vatman.rb
  15. +17 −26 vatman.gemspec
View
@@ -1,3 +1,4 @@
-pkg
-coverage
-rdoc
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
View
1 .rspec
@@ -0,0 +1 @@
+--color
View
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in vatman.gemspec
+gemspec
View
20 LICENSE
@@ -1,20 +0,0 @@
-Copyright (c) 2010 Neil Middleton
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,5 +0,0 @@
-Rakefile
-lib/vatman.rb
-test/test_helper.rb
-test/test_vatman.rb
-Manifest
View
@@ -1,12 +1 @@
-require 'rubygems'
-require 'rake'
-require 'echoe'
-
-Echoe.new('vatman', '0.1.0') do |p|
- p.description = "A gem that checks VAT numbers against the Europa web service"
- p.url = "http://github.com/neilmiddleton/vatman"
- p.author = "Neil Middleton"
- p.email = "neilmiddleton @nospam@ gmail.com"
- p.ignore_pattern = ["tmp/*", "script/*"]
- p.development_dependencies = []
-end
+require "bundler/gem_tasks"
View
@@ -1,30 +0,0 @@
-= vatman
-
-vatman is a library for checking VAT numbers against the Europa webservice.
-This is the ONLY way to check if a VAT number is genuine and in use.
-
-== Usage
-
- vat_number = Vatman.new('GB', 802925148)
-
- vat_number.valid? => true
- vat_number.name => 'MONOCHROME LIMITED'
- vat_number.address => 'SUITE K\nTHE PAVILLIONS\n1 WESTERN ROAD\nEPSOM\nSURREY\nKT17 1JG'
-
-== Installation
-
- gem install vatman
-
-and then
-
- require 'vatman'
-
-== Note on Patches/Pull Requests
-
-* Fork the project.
-* Make your feature addition or bug fix.
-* Add tests for it. This is important so I don’t break it in a future version unintentionally.
-* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-* Send me a pull request. Bonus points for topic branches.
-
-
View
@@ -1 +0,0 @@
-0.1.0
View
@@ -1,29 +1,36 @@
-require 'soap/wsdlDriver'
+require "vatman/version"
+require 'savon'
-class Vatman
- def initialize(country, number)
- @country, @number = country, number
- end
-
- def name
- get_variable(:name)
- end
-
- def address
- get_variable(:address)
- end
-
- def valid?
- get_variable(:valid) == 'true'
- end
-
- private
-
- def response
- @response ||= SOAP::WSDLDriverFactory.new('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl').create_rpc_driver.checkVat(:countryCode => @country, :vatNumber => @number)
+module Vatman
+ class Check
+
+ def initialize(country, number)
+ @country, @number = country, number.to_s.gsub(' ', '')
end
- def get_variable(var)
- response.send(var) if response.respond_to?(var)
+ def valid?
+ response[:valid]
end
-end
+
+ def name
+ response[:name]
+ end
+
+ def address
+ response[:address]
+ end
+
+ private
+
+ def response
+ @response ||= get_vat_check
+ end
+
+ def get_vat_check
+ client = ::Savon::Client.new("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl")
+ response = client.request :tnsl, :check_vat, :body => {:country_code => @country, :vat_number => @number}
+ response.to_hash[:check_vat_response]
+ end
+ end
+end
+
View
@@ -0,0 +1,3 @@
+module Vatman
+ VERSION = "1.0.0"
+end
View
@@ -0,0 +1,8 @@
+require 'rubygems'
+require 'bundler/setup'
+
+require File.dirname(__FILE__) + '/../lib/vatman'
+
+RSpec.configure do |config|
+
+end
View
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe Vatman do
+ it 'should return details of a valid VAT number' do
+ v = Vatman::Check.new("GB", 800634860)
+ v.should be_valid
+ v.name.should == 'KYANMEDIA LTD'
+ v.address.should == "171 HIGH STREET\nGUILDFORD\nSURREY\n\n\nGU1 3AJ"
+ end
+
+ it 'should accept string formatted numbers' do
+ v = Vatman::Check.new("GB", "800 6348 60")
+ v.should be_valid
+ end
+
+ it 'should reject invalid VAT numbers' do
+ v = Vatman::Check.new("GB", 12345679)
+ v.should_not be_valid
+ end
+
+ it 'should reject invalid string vat numbers' do
+ v = Vatman::Check.new("GB", "abcdefghijkl")
+ v.should_not be_valid
+ end
+end
View
@@ -1,2 +0,0 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../lib/vatman'
View
@@ -1,18 +0,0 @@
-class TestVatman < Test::Unit::TestCase
-
- def setup
- end
-
- def test_vatman
- v = Vatman.new('GB', 802925148)
- assert v.valid?
- assert_equal 'MONOCHROME LIMITED', v.name
- assert_equal "SUITE K\nTHE PAVILLIONS\n1 WESTERN ROAD\nEPSOM\nSURREY\nKT17 1JG", v.address
-
- v = Vatman.new('GB', 123456789)
- assert !v.valid?
-
- v = Vatman.new('GB', "abcdefg")
- assert !v.valid?
- end
-end
View
@@ -1,33 +1,24 @@
# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "vatman/version"
Gem::Specification.new do |s|
- s.name = %q{vatman}
- s.version = "0.1.0"
+ s.name = "vatman"
+ s.version = Vatman::VERSION
+ s.authors = ["Neil Middleton"]
+ s.email = ["neil.middleton@gmail.com"]
+ s.homepage = ""
+ s.summary = %q{A gem that checks VAT numbers against the Europa web service}
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
- s.authors = ["Neil Middleton"]
- s.cert_chain = ["/Users/neil/.ssh/gem-public_cert.pem"]
- s.date = %q{2010-09-24}
- s.description = %q{A gem that checks VAT numbers against the Europa web service}
- s.email = %q{neilmiddleton @nospam@ gmail.com}
- s.extra_rdoc_files = ["lib/vatman.rb"]
- s.files = ["Rakefile", "lib/vatman.rb", "test/test_helper.rb", "test/test_vatman.rb", "Manifest", "vatman.gemspec"]
- s.homepage = %q{http://github.com/neilmiddleton/vatman}
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Vatman", "--main", "Readme.rdoc"]
- s.require_paths = ["lib"]
- s.rubyforge_project = %q{vatman}
- s.rubygems_version = %q{1.3.7}
- s.signing_key = %q{/Users/neil/.ssh/gem-private_key.pem}
- s.summary = %q{A gem that checks VAT numbers against the Europa web service}
- s.test_files = ["test/test_helper.rb", "test/test_vatman.rb"]
+ s.rubyforge_project = "vatman"
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- else
- end
- else
- end
+ # specify any dependencies here; for example:
+ s.add_development_dependency "rspec"
+ s.add_runtime_dependency "savon"
+ s.add_runtime_dependency "curb"
end

0 comments on commit 2092560

Please sign in to comment.