Module: Valvat::Lookup

Defined in:
lib/valvat/lookup.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) validate(vat)



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/valvat/lookup.rb', line 7

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