Sha256: 94c067328e89a051ad516b671c22cdf08be07b956b4953949923b0bdc3c3763c

Contents?: true

Size: 517 Bytes

Versions: 1

Compression:

Stored size: 517 Bytes

Contents

require 'valvat'
require 'net/http'
require 'yaml'

class Valvat
  module Lookup
    def self.validate(vat)
      vat = Valvat(vat)
      return false unless vat.european?
      result = begin
        YAML.load(Net::HTTP.start("isvat.appspot.com", 80) {|http|
          http.get("/#{vat.to_a.join("/")}/")
        }.body)
      rescue => err
        raise if FakeWeb::NetConnectNotAllowedError === err
        nil
      end
      
      result.is_a?(Hash) && result["error_code"] == 1 ? nil : result
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
valvat-0.2.0 lib/valvat/lookup.rb