Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 4a0b078b5211ce8661a5fc21f6276145d96cfd22 @fd committed
Showing with 178 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +4 −0 Gemfile
  3. +22 −0 LICENSE.txt
  4. +42 −0 README.md
  5. +1 −0 Rakefile
  6. +22 −0 be-data-api.gemspec
  7. +63 −0 lib/be-data-api.rb
  8. +7 −0 lib/be-data-api/version.rb
17 .gitignore
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
4 Gemfile
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in be-data-api.gemspec
+gemspec
22 LICENSE.txt
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Simon Menke
+
+MIT License
+
+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.
42 README.md
@@ -0,0 +1,42 @@
+# Be::Data::Api
+
+API client for [Data.be](http://api.data.be/)
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'be-data-api'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install be-data-api
+
+## Usage
+
+```ruby
+require 'be-data-api'
+
+client = Be::Data::Api.new(API_ID, API_KEY)
+
+client.vat_valid?("882381185")
+# => true
+
+client.vat_status("882381185")
+# => #<struct Be::Data::Api::VatStatus vat_clean="0882381185", vat_formatted="BE 0882.381.185", active=true, valid=true>
+
+client.vat_basic("882381185")
+# => #<struct Be::Data::Api::VatBasic vat_clean="0882381185", vat_formatted="BE 0882.381.185", active=true, valid=true, company_name="Mr.Henry", start_date="2006-07-03", language="nl", address_fr="Veldenstraat 14, , 2470 Retie", address_nl="Veldenstraat 14, , 2470 Retie">
+```
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
1 Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
22 be-data-api.gemspec
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'be-data-api/version'
+
+Gem::Specification.new do |gem|
+ gem.name = "be-data-api"
+ gem.version = Be::Data::Api::VERSION
+ gem.authors = ["Simon Menke"]
+ gem.email = ["simon.menke@gmail.com"]
+ gem.description = %q{Data.be is the first api provider for Belgian Business Information.}
+ gem.summary = %q{Data.be API client}
+ gem.homepage = "http://github.com/fd/be-data-api"
+
+ gem.files = `git ls-files`.split($/)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.require_paths = ["lib"]
+
+ gem.add_runtime_dependency 'multi_json'
+ gem.add_runtime_dependency 'excon'
+end
63 lib/be-data-api.rb
@@ -0,0 +1,63 @@
+require "be-data-api/version"
+require 'multi_json'
+require 'excon'
+
+module Be
+ module Data
+ class Api
+
+ def initialize(api_id, api_key)
+ @conn = Excon.new("https://api.data.be", :query => { "api_id" => api_id, "api_key" => api_key })
+ end
+
+ # API DOC: http://api.data.be/#validity
+ # @example
+ # Be::Data::Api.new(...).vat_valid? "844044609"
+ # Be::Data::Api.new(...).vat_valid? "0844.044.609"
+ # Be::Data::Api.new(...).vat_valid? "BE-0844-044-609"
+ def vat_valid?(vat_number)
+ response = get("/1.0/vat/#{vat_number}/validity")
+ p response
+ return !!response["valid"]
+ end
+
+ # API DOC: http://api.data.be/#status
+ # @example
+ # Be::Data::Api.new(...).vat_status "844044609"
+ # Be::Data::Api.new(...).vat_status "0844.044.609"
+ # Be::Data::Api.new(...).vat_status "BE-0844-044-609"
+ def vat_status(vat_number)
+ response = get("/1.0/vat/#{vat_number}/status")
+ return VatStatus.new(response['vat-clean'], response['vat-formatted'], !!response['active'], !!response['valid'])
+ end
+ class VatStatus < Struct.new(:vat_clean, :vat_formatted, :active, :valid) ; end
+
+ # API DOC: http://api.data.be/#basic
+ # @example
+ # Be::Data::Api.new(...).vat_status "844044609"
+ # Be::Data::Api.new(...).vat_status "0844.044.609"
+ # Be::Data::Api.new(...).vat_status "BE-0844-044-609"
+ def vat_basic(vat_number)
+ response = get("/1.0/vat/#{vat_number}/basic")
+ return VatBasic.new(response['vat-clean'], response['vat-formatted'], !!response['active'], !!response['valid'],
+ response['company-name'], response['start-date'], response['language'], response['address-fr'],
+ response['address-nl'])
+ end
+ class VatBasic < Struct.new(:vat_clean, :vat_formatted, :active, :valid, :company_name, :start_date, :language, :address_fr, :address_nl)
+ end
+
+ private
+
+ def get(path)
+ response = @conn.get(:path => path)
+ response = MultiJson.decode(response.body)
+ if response['success'] == true
+ return response['data']
+ else
+ raise "Be::Data::Api.call failed: #{response.inspect}"
+ end
+ end
+
+ end
+ end
+end
7 lib/be-data-api/version.rb
@@ -0,0 +1,7 @@
+module Be
+ module Data
+ class Api
+ VERSION = "0.0.1"
+ end
+ end
+end

0 comments on commit 4a0b078

Please sign in to comment.
Something went wrong with that request. Please try again.