abn_search 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +22 -13
- data/abn_search.gemspec +3 -1
- data/lib/abn_search.rb +105 -36
- metadata +42 -6
data/README.rdoc
CHANGED
@@ -1,29 +1,38 @@
|
|
1
|
+
=== Important: Gem has been updated to support searching the Australian Business Registry (ABR) by name as well as abn. The syntax to call and validate ABN's has changed!
|
2
|
+
|
1
3
|
A simple ABN search library for validating and obtaining ABN details from the Australian Business Register.
|
2
4
|
|
3
5
|
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
6
|
http://www.abr.business.gov.au/Register.aspx
|
5
7
|
|
6
|
-
= Rails 3 Installation
|
8
|
+
= Rails 3+ Installation
|
7
9
|
|
8
10
|
Simply add the following line to your Gemfile and run bundle install.
|
9
11
|
|
10
12
|
gem 'abn_search'
|
11
|
-
|
13
|
+
|
12
14
|
= Usage
|
13
15
|
|
14
16
|
require 'abn_search'
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
# Search by ABN Number
|
19
|
+
abn = ABNSearch.new("YOUR_GUID_HERE")
|
20
|
+
result = abn.search("59001215354")
|
21
|
+
=> {:abn=>"59001215354", :entity_type=>"Australian Public Company", :status=>"Active", :main_name=>"SONY AUSTRALIA LIMITED", :trading_name=>"", :legal_name=>"", :other_trading_name=>"", :name=>"SONY AUSTRALIA LIMITED"}
|
22
|
+
|
23
|
+
puts result[:entity_type]
|
24
|
+
=> "Australian Public Company"
|
25
|
+
|
26
|
+
puts result[:status]
|
27
|
+
=> "Active"
|
28
|
+
|
29
|
+
puts result[:name]
|
30
|
+
=> "SONY AUSTRALIA LIMITED"
|
31
|
+
|
32
|
+
# Search by name
|
33
|
+
results = abn.search_by_name("Sony", ['NSW'], '2000')
|
34
|
+
|
35
|
+
puts results
|
27
36
|
|
28
37
|
= Errors
|
29
38
|
If an ABN is missing, invalid or expired - check the errors attribute.
|
data/abn_search.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "abn_search"
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.5'
|
7
7
|
s.authors = ["James Martin"]
|
8
8
|
s.email = ["james@visualconnect.net"]
|
9
9
|
s.homepage = "https://github.com/jamsi/abn_search"
|
@@ -16,5 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
+
s.add_dependency("savon")
|
19
20
|
s.add_dependency("nokogiri")
|
21
|
+
s.add_development_dependency("yard")
|
20
22
|
end
|
data/lib/abn_search.rb
CHANGED
@@ -1,59 +1,128 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
#
|
2
|
+
# ABN Search
|
3
|
+
#
|
4
|
+
# Request examples;
|
5
|
+
#
|
6
|
+
# Search by ABN number
|
7
|
+
# > a = ABNSearch.new("your-guid")
|
8
|
+
# > result = a.search("56206894472")
|
9
|
+
#
|
10
|
+
# Search by name and return an array of results
|
11
|
+
# > a = ABNSearch.new("your-guid")
|
12
|
+
# > result = a.search_by_name("Sony", ['NSW', 'VIC'])
|
13
|
+
#
|
14
|
+
|
15
|
+
require 'savon'
|
3
16
|
|
4
17
|
class ABNSearch
|
5
18
|
|
6
19
|
module Version
|
7
|
-
VERSION = "0.0.
|
20
|
+
VERSION = "0.0.5"
|
8
21
|
end
|
9
22
|
|
10
|
-
attr_accessor :
|
23
|
+
attr_accessor :errors, :guid, :proxy, :client_options
|
11
24
|
|
12
|
-
|
25
|
+
# Setup a new instance of the ABN search class.
|
26
|
+
#
|
27
|
+
# @param [String] guid - the ABR GUID for Web Services access
|
28
|
+
# @param [Hash] options - options detailed below
|
29
|
+
# @option options [String] :proxy Proxy URL string if required (Example: http://user:pass@host.example.com:443)
|
30
|
+
# @return [ABNSearch]
|
31
|
+
#
|
32
|
+
def initialize(guid=nil, options = {})
|
13
33
|
self.errors = []
|
14
|
-
self.abn = abn unless abn.nil?
|
15
34
|
self.guid = guid unless guid.nil?
|
16
|
-
self.
|
17
|
-
self.
|
35
|
+
self.proxy = options[:proxy] || nil
|
36
|
+
self.client_options = {}
|
37
|
+
self.client_options = { :wsdl => "http://www.abn.business.gov.au/abrxmlsearch/ABRXMLSearch.asmx?WSDL" }
|
38
|
+
self.client_options.merge!({ :proxy => self.proxy }) unless self.proxy.nil?
|
18
39
|
end
|
19
40
|
|
20
|
-
|
21
|
-
|
41
|
+
# Performs an ABR search for the ABN setup upon initialization
|
42
|
+
#
|
43
|
+
# @param [String] abn - the abn you wish to search for
|
44
|
+
# @return [ABNSearch] search results in class instance
|
45
|
+
def search(abn)
|
46
|
+
self.errors << "No ABN provided." && return if abn.nil?
|
22
47
|
self.errors << "No GUID provided. Please obtain one at - http://www.abr.business.gov.au/Webservices.aspx" && return if self.guid.nil?
|
23
48
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
trading_name = doc.xpath(base_path + '/maintradingname/organisationname')
|
33
|
-
main_name = doc.xpath(base_path + '/mainname/organisationname')
|
34
|
-
expires = doc.xpath(base_path + '/entitystatus/entitystatuscode')
|
35
|
-
|
36
|
-
# Did we find a valid ABN?
|
37
|
-
if abn[0].nil?
|
38
|
-
self.errors << "Invalid ABN number."
|
39
|
-
return
|
49
|
+
begin
|
50
|
+
client = Savon.client(self.client_options)
|
51
|
+
|
52
|
+
response = client.call(:abr_search_by_abn, message: { authenticationGuid: self.guid, searchString: abn.gsub(" ", ""), includeHistoricalDetails: "N" })
|
53
|
+
result = response.body[:abr_search_by_abn_response][:abr_payload_search_results][:response][:business_entity]
|
54
|
+
return parse_search_result(result)
|
55
|
+
rescue => ex
|
56
|
+
self.errors << ex.to_s
|
40
57
|
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Searches the ABR registry by name. Simply pass in the search term and which state(s) to search in.
|
61
|
+
#
|
62
|
+
# @param [String] name - the search term
|
63
|
+
# @param [Array] states - a list of states that you wish to filter by
|
64
|
+
# @param [String] postcode - the postcode you wish to filter by
|
65
|
+
def search_by_name(name, states=['NSW'], postcode='ALL')
|
41
66
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
67
|
+
begin
|
68
|
+
client = Savon.client(self.client_options)
|
69
|
+
request = {
|
70
|
+
externalNameSearch: {
|
71
|
+
authenticationGuid: self.guid, name: name,
|
72
|
+
filters: {
|
73
|
+
nameType: {
|
74
|
+
tradingName: 'Y', legalName: 'Y'
|
75
|
+
},
|
76
|
+
postcode: postcode,
|
77
|
+
"stateCode" => {
|
78
|
+
'QLD' => states.include?('QLD') ? "Y" : "N",
|
79
|
+
'NT' => states.include?('NT') ? "Y" : "N",
|
80
|
+
'SA' => states.include?('SA') ? "Y" : "N",
|
81
|
+
'WA' => states.include?('WA') ? "Y" : "N",
|
82
|
+
'VIC' => states.include?('VIC') ? "Y" : "N",
|
83
|
+
'ACT' => states.include?('ACT') ? "Y" : "N",
|
84
|
+
'TAS' => states.include?('TAS') ? "Y" : "N",
|
85
|
+
'NSW' => states.include?('NSW') ? "Y" : "N"
|
86
|
+
}
|
87
|
+
}
|
88
|
+
},
|
89
|
+
authenticationGuid: self.guid
|
90
|
+
}
|
91
|
+
|
92
|
+
response = client.call(:abr_search_by_name, message: request)
|
93
|
+
results = response.body[:abr_search_by_name_response][:abr_payload_search_results][:response][:search_results_list][:search_results_record]
|
94
|
+
|
95
|
+
return [parse_search_result(results)] if !results.is_a?(Array)
|
96
|
+
return results.map do |r| parse_search_result(r) end
|
97
|
+
rescue => ex
|
98
|
+
self.errors << ex.to_s
|
46
99
|
end
|
100
|
+
end
|
47
101
|
|
48
|
-
|
49
|
-
|
102
|
+
# Parses results for a search by ABN
|
103
|
+
def parse_search_result(result)
|
104
|
+
result = {
|
105
|
+
abn: result[:abn][:identifier_value],
|
106
|
+
entity_type: result[:entity_type].blank? ? "" : result[:entity_type][:entity_description],
|
107
|
+
status: result[:entity_status].blank? ? "" : result[:entity_status][:entity_status_code],
|
108
|
+
main_name: result[:main_name].blank? ? "" : result[:main_name][:organisation_name],
|
109
|
+
trading_name: result[:main_trading_name].blank? ? "" : result[:main_trading_name][:organisation_name],
|
110
|
+
legal_name: result[:legal_name].blank? ? "" : "#{result[:legal_name][:given_name]} #{result[:legal_name][:family_name]}",
|
111
|
+
other_trading_name: result[:other_trading_name].blank? ? "" : result[:other_trading_name][:organisation_name]
|
112
|
+
}
|
50
113
|
|
51
|
-
#
|
52
|
-
if trading_name
|
53
|
-
|
114
|
+
# Work out what we should return as a name
|
115
|
+
if !result[:trading_name].blank?
|
116
|
+
result[:name] = result[:trading_name]
|
117
|
+
elsif !result[:main_name].blank?
|
118
|
+
result[:name] = result[:main_name]
|
119
|
+
elsif !result[:other_trading_name].blank?
|
120
|
+
result[:name] = result[:other_trading_name]
|
54
121
|
else
|
55
|
-
|
122
|
+
result[:name] = result[:legal_name]
|
56
123
|
end
|
124
|
+
|
125
|
+
return result
|
57
126
|
end
|
58
127
|
|
59
128
|
def valid?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abn_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,27 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: savon
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: nokogiri
|
16
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
17
33
|
none: false
|
18
34
|
requirements:
|
19
35
|
- - ! '>='
|
@@ -21,7 +37,28 @@ dependencies:
|
|
21
37
|
version: '0'
|
22
38
|
type: :runtime
|
23
39
|
prerelease: false
|
24
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: yard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
25
62
|
description: A simple ABN search library for validating and obtaining ABN details
|
26
63
|
from the Australian Business Register.
|
27
64
|
email:
|
@@ -56,9 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
93
|
version: '0'
|
57
94
|
requirements: []
|
58
95
|
rubyforge_project: abn_search
|
59
|
-
rubygems_version: 1.8.
|
96
|
+
rubygems_version: 1.8.25
|
60
97
|
signing_key:
|
61
98
|
specification_version: 3
|
62
99
|
summary: ABNSearch library for Australian businesses.
|
63
100
|
test_files: []
|
64
|
-
has_rdoc:
|