abn_search 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Gemfile.lock +16 -0
- data/README.rdoc +37 -0
- data/Rakefile +1 -0
- data/abn_search.gemspec +20 -0
- data/lib/abn_search.rb +61 -0
- data/pkg/abn_search-0.0.1.gem +0 -0
- metadata +66 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
A simple ABN search library for validating and obtaining ABN details from the Australian Business Register.
|
2
|
+
|
3
|
+
PLEASE NOTE: You will need a GUID to be able to use the ABR business lookup API. You can obtain one at the following link;
|
4
|
+
http://www.abr.business.gov.au/Register.aspx
|
5
|
+
|
6
|
+
= Rails 3 Installation
|
7
|
+
|
8
|
+
Simply add the following line to your Gemfile and run bundle install.
|
9
|
+
|
10
|
+
gem 'abnsearch'
|
11
|
+
|
12
|
+
= Usage
|
13
|
+
|
14
|
+
require 'abnsearch'
|
15
|
+
|
16
|
+
abn = Abnsearch.new("34355893198")
|
17
|
+
=> #<Abnsearch:0x0000010109bc38 @errors=[], @abn="34355893198", @WSDL_URL="http://abr.business.gov.au/ABRXMLSearch/AbrXmlSearch.asmx/ABRSearchByABN?", @ABN_LOOKUP_GUID="ac60a98a-fe5e-4a4a-bfcc-bcf30a51e1a9", @name="sony", @entity_type="IND Individual/Sole Trader">
|
18
|
+
|
19
|
+
puts abn.name
|
20
|
+
=> "sony"
|
21
|
+
|
22
|
+
puts abn.entity_type
|
23
|
+
=> "IND Individual/Sole Trader"
|
24
|
+
|
25
|
+
abn.valid?
|
26
|
+
=> true
|
27
|
+
|
28
|
+
= Errors
|
29
|
+
If an ABN is missing, invalid or expired - check the errors attribute.
|
30
|
+
|
31
|
+
a.errors
|
32
|
+
=> ["Business ABN 89107860122 has expired."]
|
33
|
+
|
34
|
+
= Notes
|
35
|
+
- Australian Business Register: http://www.abr.business.gov.au/
|
36
|
+
- XML API: http://abr.business.gov.au/ABRXMLSearch/AbrXmlSearch.asmx
|
37
|
+
- GUID Registration link: http://www.abr.business.gov.au/Register.aspx
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/abn_search.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "abn_search"
|
6
|
+
s.version = '0.0.1'
|
7
|
+
s.authors = ["James Martin"]
|
8
|
+
s.email = ["james@visualconnect.net"]
|
9
|
+
s.homepage = "https://github.com/jamsi"
|
10
|
+
s.summary = "ABNSearch library for Australian businesses."
|
11
|
+
s.description = "A simple ABN search library for validating and obtaining ABN details from the Australian Business Register."
|
12
|
+
s.rubyforge_project = "abn_search"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_dependency("nokogiri")
|
20
|
+
end
|
data/lib/abn_search.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
class ABNSearch
|
5
|
+
|
6
|
+
module Version
|
7
|
+
VERSION = "0.0.1"
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :name, :abn, :entity_type, :errors, :guid
|
11
|
+
|
12
|
+
def initialize(abn=nil, guid=nil)
|
13
|
+
self.errors = []
|
14
|
+
self.abn = abn unless abn.nil?
|
15
|
+
self.guid = abn unless guid.nil?
|
16
|
+
self.search
|
17
|
+
end
|
18
|
+
|
19
|
+
def search
|
20
|
+
self.errors << "No ABN provided." && return if self.abn.nil?
|
21
|
+
self.errors << "No GUID provided. Please obtain one at - http://www.abr.business.gov.au/Webservices.aspx" && return if self.guid.nil?
|
22
|
+
|
23
|
+
@WSDL_URL = 'http://abr.business.gov.au/ABRXMLSearch/AbrXmlSearch.asmx/ABRSearchByABN?'
|
24
|
+
url = @WSDL_URL + "searchString=#{self.abn}&includeHistoricalDetails=n&authenticationGuid=#{self.guid}"
|
25
|
+
doc = Nokogiri::HTML(open(url))
|
26
|
+
|
27
|
+
# Fetch attributes we require
|
28
|
+
base_path = '//html/body/abrpayloadsearchresults/response/businessentity'
|
29
|
+
entity_type = doc.xpath(base_path + '/entitytype')
|
30
|
+
abn = doc.xpath(base_path + '/abn/identifiervalue')
|
31
|
+
trading_name = doc.xpath(base_path + '/maintradingname/organisationname')
|
32
|
+
main_name = doc.xpath(base_path + '/mainname/organisationname')
|
33
|
+
expires = doc.xpath(base_path + '/entitystatus/entitystatuscode')
|
34
|
+
|
35
|
+
# Did we find a valid ABN?
|
36
|
+
if abn[0].nil?
|
37
|
+
self.errors << "Invalid ABN number."
|
38
|
+
return
|
39
|
+
end
|
40
|
+
|
41
|
+
# Is the busines still valid?
|
42
|
+
if expires && expires[0].content.include?("Cancelled")
|
43
|
+
self.errors << "Business ABN #{self.abn} has expired."
|
44
|
+
return
|
45
|
+
end
|
46
|
+
|
47
|
+
# Set ABN business attributes
|
48
|
+
self.entity_type = entity_type[0].content unless entity_type[0].nil?
|
49
|
+
|
50
|
+
# Set the business name. Sometimes there's no trading name .. but a "main name".
|
51
|
+
if trading_name[0].nil?
|
52
|
+
self.name = main_name[0].content
|
53
|
+
else
|
54
|
+
self.name = trading_name[0].content
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def valid?
|
59
|
+
self.errors.size == 0
|
60
|
+
end
|
61
|
+
end
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: abn_search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James Martin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-11 00:00:00.000000000 +11:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
requirement: &2153090920 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2153090920
|
26
|
+
description: A simple ABN search library for validating and obtaining ABN details
|
27
|
+
from the Australian Business Register.
|
28
|
+
email:
|
29
|
+
- james@visualconnect.net
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- Gemfile
|
35
|
+
- Gemfile.lock
|
36
|
+
- README.rdoc
|
37
|
+
- Rakefile
|
38
|
+
- abn_search.gemspec
|
39
|
+
- lib/abn_search.rb
|
40
|
+
- pkg/abn_search-0.0.1.gem
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: https://github.com/jamsi
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project: abn_search
|
62
|
+
rubygems_version: 1.6.2
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: ABNSearch library for Australian businesses.
|
66
|
+
test_files: []
|