Valnzbn

A simple wrapper to check New Zealand business numbers.

Installation

Add this line to your application's Gemfile:

gem 'valnzbn'

And then execute:

$ bundle

Or install it yourself as:

$ gem install valnzbn

Usage

If you just need to check the format of the ABN, just use:

require 'valnzbn'

Valnzbn::Utils.validate_format(number) #=> Boolean

In order to lookup real NZBN, you'll need to get an access token. Once you've got one initialize the gem like this:

require 'valnzbn'

Valnzbn::Lookup.configure do |config|
  config.access_token = 'your_access_token'
  config.mode = :production # (optional):production or :sandbox
  config.cache_host = 'localhost' # (optional) The host of the redis server
  config.cache_port = '6379' # (optional) The port of the redis server
end

cache_host and cache_port are optional configuration attributes in order to keep a cache on a redis database. The current cache configuration lives up to two hours.

After that, you can invoke

Valabn::Lookup.validate(abn) #=> Hash or nil

# or

number = Valabn.new(abn)
number.exists? #=> Boolean
number.exists?(details: true) #=> Hash, false or nil

nil is a value that should be rarely returned. Just check it if the NZBN API endpoint has issues.

License

(The MIT License)

Copyright © 2018 Quaderno

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.