Sha256: f62021e9f5f0453c8bbf93291ef78a085504ba600b8713a1eebf29cd779c3b99

Contents?: true

Size: 471 Bytes

Versions: 1

Compression:

Stored size: 471 Bytes

Contents

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

module Valvat
  module Lookup
    def self.validate(vat)
      parts = Valvat::Utils.split(vat)
      return false unless parts[0]
      
      result = begin
        YAML.load(Net::HTTP.start("isvat.appspot.com", 80) {|http|
          http.get("/#{parts.join("/")}/")
        }.body)
      rescue
        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.1.1 lib/valvat/lookup.rb