abn_lookup 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 276141b6aaae5383c076b6b2ab7a17536a56e38c296fab584e6ed27873c94ef7
4
- data.tar.gz: ab311bca6af0587a06811776a387898d4d40d082d5c89891784b071fe343f79c
3
+ metadata.gz: 16decb392208f999b3723e09636178b22b321a748c898ff99a527c92acdffcf4
4
+ data.tar.gz: 4b1026420192d43e40322deb6b6d6364885cc37600b684036966b229fec5383d
5
5
  SHA512:
6
- metadata.gz: 696b8cf8190be707c30acd77ddf990d1ca17197f32514304488b457ef7511651b6487f265ccf30af2d2f04858309f774c720776f381d4680b330b57a90ef2e3d
7
- data.tar.gz: 74f09efa50d894a986dd906dd601151f0f51d73103e4824f08a245a679b820c92de84cdefbcf3916a262c6a1e5d54c2c122198356dd4818cf61d12d0d5406304
6
+ metadata.gz: a76b10768152aab4128cec7ebbbd660bda45ba8943cad6d7f64f60e5a7258e8edf27352b805a964098b2cf9a577444ff9e3d1e47a5728beeaf4c748eb21c2c0f
7
+ data.tar.gz: 1731b48946798a19b11b9ecd77d5784df31e0bfbd9d663dd6f8b2f2cadc555505731696093f5be2d1e368edfe318cd250be7fcae6288cfb62ca3048123781ec8
data/README.md CHANGED
@@ -16,7 +16,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
16
 
17
17
  ## Usage
18
18
 
19
- First step is configure you GUID key. You can request a GUID key [here](https://abr.business.gov.au/Tools/WebServices) in contact us session
19
+ First step is configure your GUID key. You can request a GUID key [here](https://abr.business.gov.au/Tools/WebServices) in contact us session
20
20
 
21
21
  ```ruby
22
22
  AbnLookup.guid = "your_GUID_key"
@@ -30,13 +30,13 @@ If you are using Ruby On Rails you can put this in initializer folder.
30
30
  ```ruby
31
31
  AbnLookup.search_by_abn("26008672179")
32
32
 
33
- => {"Abn"=>"26008672179",
34
- "AbnStatus"=>"Active",
35
- "AbnStatusEffectiveFrom"=>"1999-11-01",
36
- "Acn"=>"008672179",
37
- "AddressDate"=>"2022-01-13",
38
- "AddressPostcode"=>"3121",
39
- "AddressState"=>"VIC",
33
+ => {"Abn" => "26008672179",
34
+ "AbnStatus" => "Active",
35
+ "AbnStatusEffectiveFrom" => "1999-11-01",
36
+ "Acn" => "008672179",
37
+ "AddressDate" => "2022-01-13",
38
+ "AddressPostcode" => "3121",
39
+ "AddressState" => "VIC",
40
40
  "BusinessName"=>
41
41
  ["Dynamic Pods",
42
42
  "Dynamic Steel Frame",
@@ -67,24 +67,24 @@ AbnLookup.search_by_abn("26008672179")
67
67
  "NARELLAN HOMEMAKER CENTRE",
68
68
  "BUNNINGS WAREHOUSE",
69
69
  "HARDWARE CAFE"],
70
- "EntityName"=>"BUNNINGS GROUP LIMITED",
71
- "EntityTypeCode"=>"PUB",
72
- "EntityTypeName"=>"Australian Public Company",
73
- "Gst"=>"2000-07-01",
74
- "Message"=>""}
70
+ "EntityName" => "BUNNINGS GROUP LIMITED",
71
+ "EntityTypeCode" => "PUB",
72
+ "EntityTypeName" => "Australian Public Company",
73
+ "Gst" => "2000-07-01",
74
+ "Message" => ""}
75
75
  ```
76
76
  ### Search by ACN
77
77
 
78
78
  ```ruby
79
79
  AbnLookup.search_by_acn("008672179")
80
80
 
81
- => {"Abn"=>"26008672179",
82
- "AbnStatus"=>"Active",
83
- "AbnStatusEffectiveFrom"=>"1999-11-01",
84
- "Acn"=>"008672179",
85
- "AddressDate"=>"2022-01-13",
86
- "AddressPostcode"=>"3121",
87
- "AddressState"=>"VIC",
81
+ => {"Abn" => "26008672179",
82
+ "AbnStatus" => "Active",
83
+ "AbnStatusEffectiveFrom" => "1999-11-01",
84
+ "Acn" => "008672179",
85
+ "AddressDate" => "2022-01-13",
86
+ "AddressPostcode" => "3121",
87
+ "AddressState" => "VIC",
88
88
  "BusinessName"=>
89
89
  ["Dynamic Pods",
90
90
  "Dynamic Steel Frame",
@@ -115,30 +115,108 @@ AbnLookup.search_by_acn("008672179")
115
115
  "NARELLAN HOMEMAKER CENTRE",
116
116
  "BUNNINGS WAREHOUSE",
117
117
  "HARDWARE CAFE"],
118
- "EntityName"=>"BUNNINGS GROUP LIMITED",
119
- "EntityTypeCode"=>"PUB",
120
- "EntityTypeName"=>"Australian Public Company",
121
- "Gst"=>"2000-07-01",
122
- "Message"=>""}
118
+ "EntityName" => "BUNNINGS GROUP LIMITED",
119
+ "EntityTypeCode" => "PUB",
120
+ "EntityTypeName" => "Australian Public Company",
121
+ "Gst" => "2000-07-01",
122
+ "Message" => ""}
123
123
  ```
124
124
  ### Search by Name
125
125
 
126
126
  ```ruby
127
127
  AbnLookup.search_by_name("Dynamic Pods", max_result = 10)
128
128
 
129
- => {"Message"=>"",
129
+ => {"Message" => "",
130
130
  "Names"=>
131
- [{"Abn"=>"89619123287", "AbnStatus"=>"0000000001", "IsCurrent"=>true, "Name"=>"Dynamic Pods", "NameType"=>"Business Name", "Postcode"=>"3111", "Score"=>100, "State"=>"VIC"},
132
- {"Abn"=>"26008672179", "AbnStatus"=>"0000000001", "IsCurrent"=>true, "Name"=>"Dynamic Pods", "NameType"=>"Business Name", "Postcode"=>"3121", "Score"=>100, "State"=>"VIC"},
133
- {"Abn"=>"89619123287", "AbnStatus"=>"0000000001", "IsCurrent"=>true, "Name"=>"DYNAMIC PODS PTY LTD", "NameType"=>"Entity Name", "Postcode"=>"3111", "Score"=>99, "State"=>"VIC"},
134
- {"Abn"=>"47051861468", "AbnStatus"=>"0000000002", "IsCurrent"=>true, "Name"=>"@ DYNAMIC PTY LTD", "NameType"=>"Entity Name", "Postcode"=>"2000", "Score"=>94, "State"=>"NSW"},
135
- {"Abn"=>"91451385418", "AbnStatus"=>"0000000002", "IsCurrent"=>true, "Name"=>"DYNAMIC", "NameType"=>"Trading Name", "Postcode"=>"4105", "Score"=>94, "State"=>"QLD"},
136
- {"Abn"=>"55666163917", "AbnStatus"=>"0000000001", "IsCurrent"=>true, "Name"=>"DYNAMIC CO PTY LTD", "NameType"=>"Entity Name", "Postcode"=>"4035", "Score"=>94, "State"=>"QLD"},
137
- {"Abn"=>"47294848908", "AbnStatus"=>"0000000002", "IsCurrent"=>true, "Name"=>"DYNAMIC PTY LTD", "NameType"=>"Trading Name", "Postcode"=>"3204", "Score"=>94, "State"=>"VIC"},
138
- {"Abn"=>"63006924349", "AbnStatus"=>"0000000002", "IsCurrent"=>true, "Name"=>"DYNAMIC PTY. LTD.", "NameType"=>"Entity Name", "Postcode"=>"3059", "Score"=>94, "State"=>"VIC"},
139
- {"Abn"=>"84622042537", "AbnStatus"=>"0000000002", "IsCurrent"=>true, "Name"=>"DYnamic", "NameType"=>"Trading Name", "Postcode"=>"2000", "Score"=>94, "State"=>"NSW"},
140
- {"Abn"=>"55274753082", "AbnStatus"=>"0000000001", "IsCurrent"=>true, "Name"=>"Dynamic", "NameType"=>"Other Name", "Postcode"=>"5085", "Score"=>94, "State"=>"SA"}]}
131
+ [{"Abn" => "89619123287", "AbnStatus" => "0000000001", "IsCurrent"=>true, "Name" => "Dynamic Pods", "NameType" => "Business Name", "Postcode" => "3111", "Score"=>100, "State" => "VIC"},
132
+ {"Abn" => "26008672179", "AbnStatus" => "0000000001", "IsCurrent"=>true, "Name" => "Dynamic Pods", "NameType" => "Business Name", "Postcode" => "3121", "Score"=>100, "State" => "VIC"},
133
+ {"Abn" => "89619123287", "AbnStatus" => "0000000001", "IsCurrent"=>true, "Name" => "DYNAMIC PODS PTY LTD", "NameType" => "Entity Name", "Postcode" => "3111", "Score"=>99, "State" => "VIC"},
134
+ {"Abn" => "47051861468", "AbnStatus" => "0000000002", "IsCurrent"=>true, "Name" => "@ DYNAMIC PTY LTD", "NameType" => "Entity Name", "Postcode" => "2000", "Score"=>94, "State" => "NSW"},
135
+ {"Abn" => "91451385418", "AbnStatus" => "0000000002", "IsCurrent"=>true, "Name" => "DYNAMIC", "NameType" => "Trading Name", "Postcode" => "4105", "Score"=>94, "State" => "QLD"},
136
+ {"Abn" => "55666163917", "AbnStatus" => "0000000001", "IsCurrent"=>true, "Name" => "DYNAMIC CO PTY LTD", "NameType" => "Entity Name", "Postcode" => "4035", "Score"=>94, "State" => "QLD"},
137
+ {"Abn" => "47294848908", "AbnStatus" => "0000000002", "IsCurrent"=>true, "Name" => "DYNAMIC PTY LTD", "NameType" => "Trading Name", "Postcode" => "3204", "Score"=>94, "State" => "VIC"},
138
+ {"Abn" => "63006924349", "AbnStatus" => "0000000002", "IsCurrent"=>true, "Name" => "DYNAMIC PTY. LTD.", "NameType" => "Entity Name", "Postcode" => "3059", "Score"=>94, "State" => "VIC"},
139
+ {"Abn" => "84622042537", "AbnStatus" => "0000000002", "IsCurrent"=>true, "Name" => "DYnamic", "NameType" => "Trading Name", "Postcode" => "2000", "Score"=>94, "State" => "NSW"},
140
+ {"Abn" => "55274753082", "AbnStatus" => "0000000001", "IsCurrent"=>true, "Name" => "Dynamic", "NameType" => "Other Name", "Postcode" => "5085", "Score"=>94, "State" => "SA"}]}
141
141
  ```
142
+
143
+ ## Testing
144
+ When writing tests for an app using AbnLookup may be is a good ideia to avoid network calls and have return consistent, configurable results. To do this:
145
+
146
+
147
+ **Adding a stub to search_by_abn:**
148
+
149
+ ```ruby
150
+
151
+ AbnLookup::Test.stub_search_by_abn("26008672179",
152
+ AbnLookup::Abn.parse(
153
+ {
154
+ "Abn" => "26008672179",
155
+ "AbnStatus" => "Active",
156
+ "AbnStatusEffectiveFrom" => "1999-11-01",
157
+ "Acn" => "008672179",
158
+ "AddressDate" => "2022-01-13",
159
+ "AddressPostcode" => "3121",
160
+ "AddressState" => "VIC",
161
+ "BusinessName"=> [
162
+ "Dynamic Pods",
163
+ "Dynamic Steel Frame",
164
+ "TOOL KIT DEPOT",
165
+ ],
166
+ "EntityName" => "BUNNINGS GROUP LIMITED",
167
+ "EntityTypeCode" => "PUB",
168
+ "EntityTypeName" => "Australian Public Company",
169
+ "Gst" => "2000-07-01",
170
+ "Message" => ""
171
+ }
172
+ )
173
+ )
174
+
175
+ AbnLookup.search_by_abn("26008672179")
176
+
177
+ => #<AbnLookup::Abn:0x3570940 @abn="26008672179" @acn="008672179" @active="true" @gst="2000-07-01" @entity_name="BUNNINGS GROUP LIMITED">
178
+
179
+
180
+ ```
181
+
182
+
183
+ **Adding a stub to search_by_acn:**
184
+
185
+
186
+
187
+ ```ruby
188
+
189
+ AbnLookup::Test.stub_search_by_acn("008672179",
190
+ AbnLookup::Abn.parse(
191
+ {
192
+ "Abn" => "26008672179",
193
+ "AbnStatus" => "Active",
194
+ "AbnStatusEffectiveFrom" => "1999-11-01",
195
+ "Acn" => "008672179",
196
+ "AddressDate" => "2022-01-13",
197
+ "AddressPostcode" => "3121",
198
+ "AddressState" => "VIC",
199
+ "BusinessName"=>[
200
+ "Dynamic Pods",
201
+ "Dynamic Steel Frame",
202
+ "TOOL KIT DEPOT"
203
+ ],
204
+ "EntityName" => "BUNNINGS GROUP LIMITED",
205
+ "EntityTypeCode" => "PUB",
206
+ "EntityTypeName" => "Australian Public Company",
207
+ "Gst" => "2000-07-01",
208
+ "Message" => ""
209
+ }
210
+ )
211
+ )
212
+
213
+ AbnLookup.search_by_acn("008672179")
214
+
215
+ => #<AbnLookup::Abn:0x3570940 @abn="26008672179" @acn="008672179" @active="true" @gst="2000-07-01" @entity_name="BUNNINGS GROUP LIMITED">
216
+
217
+
218
+ ```
219
+
142
220
  ## Development
143
221
 
144
222
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -9,7 +9,7 @@ module AbnLookup
9
9
  end
10
10
 
11
11
  def inspect
12
- "#<#{self.class.name}:0x#{object_id} @abn=\"#{abn}\" @acn=\"#{acn}\" @active=\"#{active?}\" @gst=\"#{gst}\" @entity_name=\"#{entity_name}}\""
12
+ "#<#{self.class.name}:0x#{object_id} @abn=\"#{abn}\" @acn=\"#{acn}\" @active=#{active?} @gst=\"#{gst}\" @entity_name=\"#{entity_name}\">"
13
13
  end
14
14
 
15
15
  def self.parse(data)
@@ -2,14 +2,25 @@
2
2
 
3
3
  module AbnLookup
4
4
  class SearchByAbn
5
- def self.fetch(abn)
6
- response = AbnLookup.connection.get("AbnDetails.aspx?abn=#{abn.gsub(/\s/, '')}")
7
- body = response.body
5
+ class << self
6
+ attr_accessor :stubs, :default_stub
8
7
 
9
- raise InvalidGuidError if body["Message"] == "The GUID entered is not recognised as a Registered Party"
10
- raise AbnNotFoundError if body["Abn"].empty?
8
+ def fetch(abn, options = {})
9
+ stub = stubs[abn] || default_stub
10
+ return stub if stub
11
11
 
12
- Abn.parse(body)
12
+ parse = options.fetch(:parse, true)
13
+ response = AbnLookup.connection.get("AbnDetails.aspx?abn=#{abn.gsub(/\s/, '')}")
14
+ body = response.body
15
+
16
+ raise InvalidGuidError if body["Message"] == "The GUID entered is not recognised as a Registered Party"
17
+ raise AbnNotFoundError if body["Abn"].empty? || body["Message"] == "No record found"
18
+
19
+ parse ? Abn.parse(body) : body
20
+ end
13
21
  end
22
+
23
+ @stubs = {}
24
+ @default_stub = nil
14
25
  end
15
26
  end
@@ -2,14 +2,25 @@
2
2
 
3
3
  module AbnLookup
4
4
  class SearchByAcn
5
- def self.fetch(acn)
6
- response = AbnLookup.connection.get("AcnDetails.aspx?acn=#{acn.gsub(/\s/, '')}")
7
- response.body
5
+ class << self
6
+ attr_accessor :stubs, :default_stub
8
7
 
9
- raise InvalidGuidError if body["Message"] == "The GUID entered is not recognised as a Registered Party"
10
- raise AbnNotFoundError if body["Abn"].empty?
8
+ def fetch(acn, options = {})
9
+ stub = stubs[acn] || default_stub
10
+ return stub if stub
11
11
 
12
- Abn.parse(body)
12
+ parse = options.fetch(:parse, true)
13
+ response = AbnLookup.connection.get("AcnDetails.aspx?acn=#{acn.gsub(/\s/, '')}")
14
+ body = response.body
15
+
16
+ raise InvalidGuidError if body["Message"] == "The GUID entered is not recognised as a Registered Party"
17
+ raise AbnNotFoundError if body["Abn"].empty? || body["Message"] == "No record found"
18
+
19
+ parse ? Abn.parse(body) : body
20
+ end
13
21
  end
22
+
23
+ @stubs = {}
24
+ @default_stub = nil
14
25
  end
15
26
  end
@@ -0,0 +1,27 @@
1
+ module AbnLookup
2
+ module Test
3
+ def self.stub_search_by_abn(abn, result)
4
+ SearchByAbn.stubs[abn] = result
5
+ end
6
+
7
+ def self.stub_search_by_acn(acn, result)
8
+ SearchByAcn.stubs[acn] = result
9
+ end
10
+
11
+ def self.stub_search_by_name(name, result)
12
+ SearchByName.stubs[name] = result
13
+ end
14
+
15
+ def self.clear_stubs
16
+ SearchByAbn.stubs.clear
17
+ SearchByAcn.stubs.clear
18
+ SearchByName.stubs.clear
19
+ end
20
+
21
+ def self.set_default_stub(result)
22
+ SearchByAbn.default_stub = result
23
+ SearchByAcn.default_stub = result
24
+ SearchByName.default_stub = result
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AbnLookup
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
data/lib/abn_lookup.rb CHANGED
@@ -9,6 +9,7 @@ require "abn_lookup/search_by_name"
9
9
  require "abn_lookup/abn"
10
10
  require "abn_lookup/abn_not_found_error"
11
11
  require "abn_lookup/invalid_guid_error"
12
+ require "abn_lookup/test"
12
13
 
13
14
  require "faraday"
14
15
  require "faraday_middleware"
@@ -25,11 +26,11 @@ module AbnLookup
25
26
 
26
27
  def_delegators :@config, :guid, :guid=
27
28
 
28
- def search_by_abn(abn)
29
- SearchByAbn.fetch(abn)
29
+ def search_by_abn(abn, options = {})
30
+ SearchByAbn.fetch(abn, options)
30
31
  end
31
32
 
32
- def search_by_acn(acn)
33
+ def search_by_acn(acn, options = {})
33
34
  SearchByAcn.fetch(acn)
34
35
  end
35
36
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abn_lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lairton Mendes
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-03 00:00:00.000000000 Z
11
+ date: 2024-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -62,6 +62,7 @@ files:
62
62
  - lib/abn_lookup/search_by_abn.rb
63
63
  - lib/abn_lookup/search_by_acn.rb
64
64
  - lib/abn_lookup/search_by_name.rb
65
+ - lib/abn_lookup/test.rb
65
66
  - lib/abn_lookup/version.rb
66
67
  - sig/abn_lookup.rbs
67
68
  homepage: