abr_lookup 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +11 -0
- data/LICENSE +21 -0
- data/README.md +86 -0
- data/Rakefile +1 -0
- data/abr_lookup.gemspec +26 -0
- data/config/abr.yml +1 -0
- data/config/alt.yml +1 -0
- data/lib/abr_lookup.rb +52 -0
- data/lib/abr_lookup/lookup.rb +81 -0
- data/lib/abr_lookup/server.rb +40 -0
- data/lib/abr_lookup/version.rb +3 -0
- data/spec/abr_lookup/lookup_spec.rb +90 -0
- data/spec/abr_lookup/server_spec.rb +47 -0
- data/spec/abr_lookup_spec.rb +28 -0
- data/spec/fixtures/failed_abn.xml +19 -0
- data/spec/fixtures/failed_guid.xml +23 -0
- data/spec/fixtures/successful.xml +55 -0
- data/spec/spec_helper.rb +26 -0
- metadata +131 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2011 Daniel Neighman
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# AbrLookup
|
2
|
+
|
3
|
+
A simple Gem to perform ABN and ACN lookups for Australian Businesses
|
4
|
+
|
5
|
+
## What you get
|
6
|
+
|
7
|
+
### Successful Lookup
|
8
|
+
|
9
|
+
<pre><code>
|
10
|
+
lookup = AbrLookup::Lookup.new('my abn').lookup_abn!
|
11
|
+
lookup.abn # abn number
|
12
|
+
lookup.current # true if the abn is currently active
|
13
|
+
lookup.lookup_number # The number that was given to query
|
14
|
+
|
15
|
+
# Entity Information
|
16
|
+
lookup.entity_status # Active for active abns
|
17
|
+
lookup.entity_type # A code to indicate the type of entity
|
18
|
+
lookup.entity_type_description
|
19
|
+
lookup.effective_from # The date the abn was registered
|
20
|
+
lookup.effective_to # Not usable if the abn is still active
|
21
|
+
lookup.trading_name
|
22
|
+
lookup.state_code # The state the abn is registered in
|
23
|
+
lookup.postcode
|
24
|
+
|
25
|
+
# Business Registerer
|
26
|
+
lookup.given_name
|
27
|
+
lookup.family_name
|
28
|
+
</code></pre>
|
29
|
+
|
30
|
+
### Failed Request
|
31
|
+
|
32
|
+
When a request fails, the lookup object implements an ActiveModel errors
|
33
|
+
object.
|
34
|
+
|
35
|
+
<pre><code>
|
36
|
+
lookup = AbrLookup::Lookup.new('something bad').lookup_abn!
|
37
|
+
lookup.errors.full_messages # Array of messages
|
38
|
+
</code></pre>
|
39
|
+
|
40
|
+
### Use as middleware
|
41
|
+
|
42
|
+
You can use AbrLookup as middleware in your Rack application to respond
|
43
|
+
to JSON requests at "/abn\_lookup" and takes a parameter of 'abn'
|
44
|
+
containig the number to search for
|
45
|
+
|
46
|
+
#### Example
|
47
|
+
|
48
|
+
/abn\_lookup?abn=12345677 #=> A JSON response
|
49
|
+
|
50
|
+
To setup the middleware
|
51
|
+
|
52
|
+
#### Rack
|
53
|
+
|
54
|
+
<pre><code>use AbrLookup::Server
|
55
|
+
run app
|
56
|
+
</code></pre>
|
57
|
+
|
58
|
+
#### Rails
|
59
|
+
|
60
|
+
<pre><code>Rails.configuration.middleware.insert AbrLookup::Server</code></pre>
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
## Configuration
|
65
|
+
|
66
|
+
There is only one configuration option at the moment that is valid.
|
67
|
+
|
68
|
+
guid - The guid that you get when you apply for access to the web
|
69
|
+
service from http://abr.business.gov.au/
|
70
|
+
|
71
|
+
By default, if there is a file config/abr.yml present, it will be loaded
|
72
|
+
and used as the configuration.
|
73
|
+
|
74
|
+
Customize the the configuration path with
|
75
|
+
<pre><code>AbrLookup.config_path = "my_path"</code></pre>
|
76
|
+
|
77
|
+
Configuration can also be set via a hash
|
78
|
+
<pre><code>AbrLookup.configuration = {'guid' => 'some
|
79
|
+
guid'}</code></pre>
|
80
|
+
|
81
|
+
## Requirements
|
82
|
+
|
83
|
+
In order to use this gem, you'll need to get an authorized guid from http://www.abr.business.gov.au/Webservices.aspx
|
84
|
+
|
85
|
+
This is unfortunately a bit of a manual process, but it's not too
|
86
|
+
painful.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/abr_lookup.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "abr_lookup/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "abr_lookup"
|
7
|
+
s.version = AbrLookup::VERSION
|
8
|
+
s.authors = ["Daniel Neighman"]
|
9
|
+
s.email = ["has.sox@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{A simple ABN / ACN lookup utility}
|
12
|
+
s.description = %q{An ABN / ACN lookup utility that includes middleware}
|
13
|
+
|
14
|
+
s.rubyforge_project = "abr_lookup"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
|
23
|
+
s.add_runtime_dependency "nokogiri"
|
24
|
+
s.add_runtime_dependency "activemodel"
|
25
|
+
s.add_runtime_dependency 'rack'
|
26
|
+
end
|
data/config/abr.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
guid: 123
|
data/config/alt.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
guid: alternative
|
data/lib/abr_lookup.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "abr_lookup/version"
|
2
|
+
require 'yaml'
|
3
|
+
require 'uri'
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
module AbrLookup
|
7
|
+
autoload :Lookup, 'abr_lookup/lookup'
|
8
|
+
autoload :Server, 'abr_lookup/server'
|
9
|
+
|
10
|
+
def self.abn_lookup_uri
|
11
|
+
@abn_lookup_url ||= URI.parse("http://abr.business.gov.au/ABRXMLSearchRPC/ABRXMLSearch.asmx/ABRSearchByABN")
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.guid
|
15
|
+
(configuration['guid'] || configuration[:guid]).to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
# The configuration for abn lookup
|
19
|
+
# The available options are
|
20
|
+
# :guid - the authentication guid http://abr.business.gov.au/
|
21
|
+
# :path - the path to match when using middleware
|
22
|
+
def self.configuration
|
23
|
+
@configuration ||= setup_config
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set the configuration for the abn lookup
|
27
|
+
# The options that are useful are
|
28
|
+
# @see AbrLookup
|
29
|
+
def self.configuration=(config)
|
30
|
+
@configuration = config
|
31
|
+
end
|
32
|
+
|
33
|
+
# The path to find the configuration file
|
34
|
+
def self.config_path
|
35
|
+
@config_path ||= 'config/abr.yml'
|
36
|
+
end
|
37
|
+
|
38
|
+
# Set the path to the configuration file
|
39
|
+
def self.config_path=(path)
|
40
|
+
@config_path = path
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def self.setup_config
|
46
|
+
config = {}
|
47
|
+
if File.exists?(config_path)
|
48
|
+
config = YAML.load(ERB.new(File.read(config_path)).result)
|
49
|
+
end
|
50
|
+
config
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'active_model'
|
4
|
+
|
5
|
+
module AbrLookup
|
6
|
+
class Lookup
|
7
|
+
include ActiveModel::Conversion
|
8
|
+
include ActiveModel::Validations
|
9
|
+
include ActiveModel::Naming
|
10
|
+
include ActiveModel::Serializers::JSON
|
11
|
+
|
12
|
+
ATTRIBUTES = [:abn, :current, :effective_from, :effective_to, :entity_status, :entity_type, :entity_type_description, :given_name, :family_name, :trading_name, :state_code, :postcode]
|
13
|
+
|
14
|
+
attr_reader :lookup_number
|
15
|
+
attr_accessor *ATTRIBUTES
|
16
|
+
|
17
|
+
def initialize(lookup_number)
|
18
|
+
@lookup_number = lookup_number.to_s.gsub(/([^\w]|_)/, '')
|
19
|
+
end
|
20
|
+
|
21
|
+
def attributes
|
22
|
+
attrs = {:lookup_number => lookup_number}
|
23
|
+
if errors.present?
|
24
|
+
attrs[:errors] = errors.full_messages.join(", ")
|
25
|
+
else
|
26
|
+
ATTRIBUTES.inject(attrs){|hash, attr| hash[attr] = send(attr) if send(attr).present?; hash }
|
27
|
+
end
|
28
|
+
attrs
|
29
|
+
end
|
30
|
+
|
31
|
+
def as_json(*args)
|
32
|
+
attributes.stringify_keys
|
33
|
+
end
|
34
|
+
|
35
|
+
def lookup_abn!
|
36
|
+
parse_abn_response(perform_abn_lookup)
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def parse_abn_response(response)
|
42
|
+
doc = Nokogiri::XML(response)
|
43
|
+
doc.css('response').each do |node|
|
44
|
+
# Get the returned abn
|
45
|
+
self.abn = node.css('ABN identifierValue').text
|
46
|
+
|
47
|
+
# Get the effective dates
|
48
|
+
effective_from, effective_to = node.css('entityStatus effectiveFrom').text, node.css('entityStatus effectiveTo').text
|
49
|
+
self.effective_from = Date.parse(effective_from) if effective_from.present?
|
50
|
+
self.effective_to = Date.parse(effective_to ) if effective_to.present?
|
51
|
+
|
52
|
+
# Is this abn current
|
53
|
+
is_current = node.css('ABN isCurrentIndicator').text
|
54
|
+
self.current = !!(is_current && is_current =~ /Y/i)
|
55
|
+
|
56
|
+
|
57
|
+
self.entity_status = node.css('entityStatus entityStatusCode' ).text.strip
|
58
|
+
self.entity_type = node.css('entityType entityTypeCode' ).text.strip
|
59
|
+
self.entity_type_description = node.css('entityType entityDescription' ).text.strip
|
60
|
+
|
61
|
+
self.given_name = node.css('legalName givenName').text.strip
|
62
|
+
self.family_name = node.css('legalName familyName').text.strip
|
63
|
+
|
64
|
+
self.trading_name = node.css('mainTradingName organisationName' ).text.strip
|
65
|
+
self.state_code = node.css('mainBusinessPhysicalAddress stateCode' ).text.strip
|
66
|
+
self.postcode = node.css('mainBusinessPhysicalAddress postcode' ).text.strip
|
67
|
+
|
68
|
+
node.css('exception').each do |exception|
|
69
|
+
errors.add(exception.css('exceptionCode').text.strip, exception.css('exceptionDescription').text.strip)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def perform_abn_lookup
|
75
|
+
query = "searchString=#{lookup_number}&includeHistoricalDetails=Y&authenticationGuid=#{AbrLookup.guid}"
|
76
|
+
uri = AbrLookup.abn_lookup_uri.dup
|
77
|
+
uri.query = query
|
78
|
+
Net::HTTP.get_response(uri).body
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rack'
|
2
|
+
module AbrLookup
|
3
|
+
class Server
|
4
|
+
attr_reader :match_path
|
5
|
+
DEFAULT_PATH = /^\/abn_lookup(\..+)?$/
|
6
|
+
|
7
|
+
def initialize(app, opts={})
|
8
|
+
@app = app
|
9
|
+
@match_path = opts.fetch(:match_path, DEFAULT_PATH)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
req = Rack::Request.new env
|
14
|
+
if req.path =~ match_path
|
15
|
+
lookup = Lookup.new(req.params['abn']).lookup_abn!
|
16
|
+
body = lookup.to_json
|
17
|
+
status = status_from_lookup(lookup)
|
18
|
+
res = Rack::Response.new lookup.to_json, status, 'Content-Type' => 'application/json'
|
19
|
+
res.finish
|
20
|
+
else
|
21
|
+
@app.call(env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def status_from_lookup(lookup)
|
27
|
+
if lookup.errors.blank?
|
28
|
+
200
|
29
|
+
else
|
30
|
+
if lookup.errors['WebServices'] && lookup.errors['WebServices'].any?{ |err| err =~ /guid/im }
|
31
|
+
401
|
32
|
+
elsif lookup.errors['Search'] && lookup.errors['Search'].any?{ |err| err =~ /not.+valid/im }
|
33
|
+
404
|
34
|
+
else
|
35
|
+
400
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AbrLookup::Lookup do
|
4
|
+
it "should load with a business number to lookup" do
|
5
|
+
lookup = AbrLookup::Lookup.new '12345'
|
6
|
+
lookup.lookup_number.should == '12345'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should strip out non alpha numeric chars" do
|
10
|
+
lookup = AbrLookup::Lookup.new '123 4_ab5'
|
11
|
+
lookup.lookup_number.should == '1234ab5'
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "with lookup" do
|
15
|
+
it "should lookup the business number with the guid number" do
|
16
|
+
stub_abn_request('searchString' => '98765')
|
17
|
+
lookup = AbrLookup::Lookup.new '98765'
|
18
|
+
lookup.lookup_abn!
|
19
|
+
WebMock.should have_requested_abn('searchString' => '98765')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should parse a successful response" do
|
23
|
+
stub_abn_request('searchString' => '18406500889').to_return(:body => fixture('successful.xml'), :status => 200)
|
24
|
+
result = AbrLookup::Lookup.new('18406500889').lookup_abn!
|
25
|
+
result.abn.should == '18406500889'
|
26
|
+
result.effective_from.to_s.should == Date.parse('2002-12-01').to_s
|
27
|
+
result.effective_to.to_s.should == Date.parse('0001-01-01').to_s
|
28
|
+
result.entity_status.should == 'Active'
|
29
|
+
result.entity_type.should == 'IND'
|
30
|
+
result.entity_type_description.should == 'Individual/Sole Trader'
|
31
|
+
result.given_name.should == 'CHRISANTHY'
|
32
|
+
result.family_name.should == 'BARONE'
|
33
|
+
result.trading_name.should == 'CLARITY - Create Inner Space & Clarity'
|
34
|
+
result.state_code.should == 'SA'
|
35
|
+
result.postcode.should == '5067'
|
36
|
+
result.current.should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should provide a successful response as an attributes hash" do
|
40
|
+
stub_abn_request('searchString' => '18406500889').to_return(:body => fixture('successful.xml'), :status => 200)
|
41
|
+
result = AbrLookup::Lookup.new('18406500889').lookup_abn!
|
42
|
+
attrs = result.attributes
|
43
|
+
attrs[:abn].should == '18406500889'
|
44
|
+
attrs[:effective_from].to_s.should == Date.parse('2002-12-01').to_s
|
45
|
+
attrs[:effective_to].to_s.should == Date.parse('0001-01-01').to_s
|
46
|
+
attrs[:entity_status].should == 'Active'
|
47
|
+
attrs[:entity_type].should == 'IND'
|
48
|
+
attrs[:entity_type_description].should == 'Individual/Sole Trader'
|
49
|
+
attrs[:given_name].should == 'CHRISANTHY'
|
50
|
+
attrs[:family_name].should == 'BARONE'
|
51
|
+
attrs[:trading_name].should == 'CLARITY - Create Inner Space & Clarity'
|
52
|
+
attrs[:state_code].should == 'SA'
|
53
|
+
attrs[:postcode].should == '5067'
|
54
|
+
attrs[:current].should be_true
|
55
|
+
attrs.keys.should_not include(:errors, :exceptions)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should handle an incorrect abn" do
|
59
|
+
stub_abn_request('searchString' => '18406500889').to_return(:body => fixture('failed_abn.xml'), :status => 200)
|
60
|
+
result = AbrLookup::Lookup.new('18406500889').lookup_abn!
|
61
|
+
result.errors['Search'].should be_present
|
62
|
+
result.errors['Search'].should include('Search text is not a valid ABN or ACN')
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should not return anything but the errors and query string in the attributes" do
|
66
|
+
stub_abn_request('searchString' => '18406500889').to_return(:body => fixture('failed_abn.xml'), :status => 200)
|
67
|
+
result = AbrLookup::Lookup.new('18406500889').lookup_abn!
|
68
|
+
attrs = result.attributes
|
69
|
+
attrs.keys.size.should == 2
|
70
|
+
attrs.keys.should include(:errors, :lookup_number)
|
71
|
+
attrs[:errors].should include('Search text is not a valid ABN or ACN')
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should handle incorrect credentials" do
|
75
|
+
stub_abn_request('searchString' => '18406500889').to_return(:body => fixture('failed_guid.xml'), :status => 200)
|
76
|
+
result = AbrLookup::Lookup.new('18406500889').lookup_abn!
|
77
|
+
result.errors['WebServices'].should be_present
|
78
|
+
result.errors['WebServices'].should include('The GUID entered is not recognised as a Registered Party. : abcde')
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should not return anything but the errors and query string in the attributes with a failed guid" do
|
82
|
+
stub_abn_request('searchString' => '18406500889').to_return(:body => fixture('failed_guid.xml'), :status => 200)
|
83
|
+
result = AbrLookup::Lookup.new('18406500889').lookup_abn!
|
84
|
+
attrs = result.attributes
|
85
|
+
attrs.keys.size.should == 2
|
86
|
+
attrs.keys.should include(:errors, :lookup_number)
|
87
|
+
attrs[:errors].should include('The GUID entered is not recognised as a Registered Party. : abcde')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
require 'rack/test'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
describe AbrLookup::Server do
|
8
|
+
include Rack::Test::Methods
|
9
|
+
|
10
|
+
let(:app) do
|
11
|
+
_app_ = lambda{|e| Rack::Response.new('ok').finish }
|
12
|
+
Rack::Builder.new do
|
13
|
+
use AbrLookup::Server
|
14
|
+
run _app_
|
15
|
+
end.to_app
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should let the request pass through when the path doesn't match" do
|
19
|
+
res = get "/not_an_abn_lookup"
|
20
|
+
res.body.should == 'ok'
|
21
|
+
res.status.should == 200
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should match on the path and perform a lookup with the given param" do
|
25
|
+
stub_abn_request('searchString' => '1234').to_return(:body => fixture('successful.xml'), :status => 200)
|
26
|
+
res = get '/abn_lookup', :abn => '1234'
|
27
|
+
res.status.should == 200
|
28
|
+
result = JSON.parse(res.body)
|
29
|
+
result['abn'].should_not be_empty
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return a 401 if the guid is not correct" do
|
33
|
+
stub_abn_request('searchString' => '1234').to_return(:body => fixture('failed_guid.xml'), :status => 200)
|
34
|
+
res = get '/abn_lookup', :abn => '1234'
|
35
|
+
res.status.should == 401
|
36
|
+
result = JSON.parse(res.body)
|
37
|
+
result['errors'].should_not be_blank
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return a 404 if the abn is not found" do
|
41
|
+
stub_abn_request('searchString' => '1234').to_return(:body => fixture('failed_abn.xml'), :status => 200)
|
42
|
+
res = get '/abn_lookup', :abn => '1234'
|
43
|
+
res.status.should == 404
|
44
|
+
result = JSON.parse(res.body)
|
45
|
+
result['errors'].should_not be_blank
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AbrLookup do
|
4
|
+
describe "Config" do
|
5
|
+
after do
|
6
|
+
AbrLookup.config_path = nil
|
7
|
+
AbrLookup.configuration = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have the abn_lookup_uri" do
|
11
|
+
AbrLookup.abn_lookup_uri.to_s.should == 'http://abr.business.gov.au/ABRXMLSearchRPC/ABRXMLSearch.asmx/ABRSearchByABN'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should load the configuration from the default path" do
|
15
|
+
AbrLookup.configuration['guid'].should == 123
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should load the configuration from an alternative path" do
|
19
|
+
AbrLookup.config_path = 'config/alt.yml'
|
20
|
+
AbrLookup.configuration['guid'].should == 'alternative'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should load the configuration when set manually" do
|
24
|
+
AbrLookup.configuration = {'guid' => 'foo'}
|
25
|
+
AbrLookup.configuration.should == {'guid' => 'foo'}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<ABRPayloadSearchResults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://abr.business.gov.au/ABRXMLSearchRPC/literalTypes">
|
2
|
+
<request>
|
3
|
+
<identifierSearchRequest>
|
4
|
+
<authenticationGUID>abcde</authenticationGUID>
|
5
|
+
<identifierType>ABN</identifierType>
|
6
|
+
<identifierValue>98765</identifierValue>
|
7
|
+
<history>Y</history>
|
8
|
+
</identifierSearchRequest>
|
9
|
+
</request>
|
10
|
+
<response>
|
11
|
+
<dateRegisterLastUpdated>0001-01-01</dateRegisterLastUpdated>
|
12
|
+
<dateTimeRetrieved>2011-09-17T22:06:14.994085+10:00</dateTimeRetrieved>
|
13
|
+
<exception>
|
14
|
+
<exceptionDescription>Search text is not a valid ABN or ACN</exceptionDescription>
|
15
|
+
<exceptionCode>Search</exceptionCode>
|
16
|
+
</exception>
|
17
|
+
</response>
|
18
|
+
</ABRPayloadSearchResults>
|
19
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<ABRPayloadSearchResults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://abr.business.gov.au/ABRXMLSearchRPC/literalTypes">
|
3
|
+
<request>
|
4
|
+
<identifierSearchRequest>
|
5
|
+
<authenticationGUID>abcde</authenticationGUID>
|
6
|
+
<identifierType>ABN</identifierType>
|
7
|
+
<identifierValue>98765</identifierValue>
|
8
|
+
<history>Y</history>
|
9
|
+
</identifierSearchRequest>
|
10
|
+
</request>
|
11
|
+
<response>
|
12
|
+
<dateRegisterLastUpdated>0001-01-01</dateRegisterLastUpdated>
|
13
|
+
<dateTimeRetrieved>2011-09-17T12:49:21.0937904+10:00</dateTimeRetrieved>
|
14
|
+
<exception>
|
15
|
+
<exceptionDescription>
|
16
|
+
The GUID entered is not recognised as a Registered Party. : abcde
|
17
|
+
</exceptionDescription>
|
18
|
+
<exceptionCode>WebServices</exceptionCode>
|
19
|
+
</exception>
|
20
|
+
</response>
|
21
|
+
</ABRPayloadSearchResults>
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<ABRPayloadSearchResults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://abr.business.gov.au/ABRXMLSearchRPC/literalTypes">
|
3
|
+
<request>
|
4
|
+
<identifierSearchRequest>
|
5
|
+
<authenticationGUID>xxxxxxxxxxxxxxxx</authenticationGUID>
|
6
|
+
<identifierType>ABN</identifierType>
|
7
|
+
<identifierValue>18 406 500 889</identifierValue>
|
8
|
+
<history>N</history>
|
9
|
+
</identifierSearchRequest>
|
10
|
+
</request>
|
11
|
+
<response>
|
12
|
+
<usageStatement>This extract is based on information that was supplied by businesses to the
|
13
|
+
Registrar of the Australian Business Register. Neither the Registrar of the ABR
|
14
|
+
nor the Commonwealth guarantee that this information is accurate, up to date or
|
15
|
+
complete. You should consider verifying this information from other sources.</usageStatement>
|
16
|
+
<dateRegisterLastUpdated>2011-09-19</dateRegisterLastUpdated>
|
17
|
+
<dateTimeRetrieved>2011-09-19T15:12:07.0503404+10:00</dateTimeRetrieved>
|
18
|
+
<businessEntity>
|
19
|
+
<recordLastUpdatedDate>2010-09-17</recordLastUpdatedDate>
|
20
|
+
<ABN>
|
21
|
+
<identifierValue>18406500889</identifierValue>
|
22
|
+
<isCurrentIndicator>Y</isCurrentIndicator>
|
23
|
+
<replacedFrom>0001-01-01</replacedFrom>
|
24
|
+
</ABN>
|
25
|
+
<entityStatus>
|
26
|
+
<entityStatusCode>Active</entityStatusCode>
|
27
|
+
<effectiveFrom>2002-12-01</effectiveFrom>
|
28
|
+
<effectiveTo>0001-01-01</effectiveTo>
|
29
|
+
</entityStatus>
|
30
|
+
<ASICNumber />
|
31
|
+
<entityType>
|
32
|
+
<entityTypeCode>IND </entityTypeCode>
|
33
|
+
<entityDescription>Individual/Sole Trader</entityDescription>
|
34
|
+
</entityType>
|
35
|
+
<legalName>
|
36
|
+
<givenName>CHRISANTHY</givenName>
|
37
|
+
<otherGivenName />
|
38
|
+
<familyName>BARONE</familyName>
|
39
|
+
<effectiveFrom>2010-09-16</effectiveFrom>
|
40
|
+
<effectiveTo>0001-01-01</effectiveTo>
|
41
|
+
</legalName>
|
42
|
+
<mainTradingName>
|
43
|
+
<organisationName>CLARITY - Create Inner Space & Clarity</organisationName>
|
44
|
+
<effectiveFrom>2003-02-28</effectiveFrom>
|
45
|
+
</mainTradingName>
|
46
|
+
<mainBusinessPhysicalAddress>
|
47
|
+
<stateCode>SA</stateCode>
|
48
|
+
<postcode>5067</postcode>
|
49
|
+
<effectiveFrom>2002-12-01</effectiveFrom>
|
50
|
+
<effectiveTo>0001-01-01</effectiveTo>
|
51
|
+
</mainBusinessPhysicalAddress>
|
52
|
+
</businessEntity>
|
53
|
+
</response>
|
54
|
+
</ABRPayloadSearchResults>
|
55
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'abr_lookup'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
|
6
|
+
module AbrSpecHelpers
|
7
|
+
def stub_abn_request(params={})
|
8
|
+
stub = stub_request(:get, AbrLookup.abn_lookup_uri.to_s).with(:query => {'searchString' => '12345', 'includeHistoricalDetails' => 'Y', 'authenticationGuid' => AbrLookup.guid}.merge(params))
|
9
|
+
yield stub if block_given?
|
10
|
+
stub
|
11
|
+
end
|
12
|
+
|
13
|
+
def have_requested_abn(params={})
|
14
|
+
have_requested(:get, AbrLookup.abn_lookup_uri.to_s).with(:query => {'searchString' => '12345', 'includeHistoricalDetails' => 'Y', 'authenticationGuid' => AbrLookup.guid}.merge(params))
|
15
|
+
end
|
16
|
+
|
17
|
+
def fixture(name)
|
18
|
+
File.read(File.join('spec/fixtures', name.to_s))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
RSpec.configure do |c|
|
24
|
+
c.include AbrSpecHelpers
|
25
|
+
end
|
26
|
+
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: abr_lookup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Daniel Neighman
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-19 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: nokogiri
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: activemodel
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rack
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
description: An ABN / ACN lookup utility that includes middleware
|
63
|
+
email:
|
64
|
+
- has.sox@gmail.com
|
65
|
+
executables: []
|
66
|
+
|
67
|
+
extensions: []
|
68
|
+
|
69
|
+
extra_rdoc_files: []
|
70
|
+
|
71
|
+
files:
|
72
|
+
- .gitignore
|
73
|
+
- Gemfile
|
74
|
+
- LICENSE
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- abr_lookup.gemspec
|
78
|
+
- config/abr.yml
|
79
|
+
- config/alt.yml
|
80
|
+
- lib/abr_lookup.rb
|
81
|
+
- lib/abr_lookup/lookup.rb
|
82
|
+
- lib/abr_lookup/server.rb
|
83
|
+
- lib/abr_lookup/version.rb
|
84
|
+
- spec/abr_lookup/lookup_spec.rb
|
85
|
+
- spec/abr_lookup/server_spec.rb
|
86
|
+
- spec/abr_lookup_spec.rb
|
87
|
+
- spec/fixtures/failed_abn.xml
|
88
|
+
- spec/fixtures/failed_guid.xml
|
89
|
+
- spec/fixtures/successful.xml
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: ""
|
92
|
+
licenses: []
|
93
|
+
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project: abr_lookup
|
120
|
+
rubygems_version: 1.8.6
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: A simple ABN / ACN lookup utility
|
124
|
+
test_files:
|
125
|
+
- spec/abr_lookup/lookup_spec.rb
|
126
|
+
- spec/abr_lookup/server_spec.rb
|
127
|
+
- spec/abr_lookup_spec.rb
|
128
|
+
- spec/fixtures/failed_abn.xml
|
129
|
+
- spec/fixtures/failed_guid.xml
|
130
|
+
- spec/fixtures/successful.xml
|
131
|
+
- spec/spec_helper.rb
|