abn_lookup 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 276141b6aaae5383c076b6b2ab7a17536a56e38c296fab584e6ed27873c94ef7
4
- data.tar.gz: ab311bca6af0587a06811776a387898d4d40d082d5c89891784b071fe343f79c
3
+ metadata.gz: 2433d9b12d5cabd5307e7232ec143f466c0e5113e23ed588e9ccc66ccc5ccfe3
4
+ data.tar.gz: 873a9755fc6cbb0d3f0085e59f66896fd3fdc28a1d22b2c1ddb00894bbdd4a05
5
5
  SHA512:
6
- metadata.gz: 696b8cf8190be707c30acd77ddf990d1ca17197f32514304488b457ef7511651b6487f265ccf30af2d2f04858309f774c720776f381d4680b330b57a90ef2e3d
7
- data.tar.gz: 74f09efa50d894a986dd906dd601151f0f51d73103e4824f08a245a679b820c92de84cdefbcf3916a262c6a1e5d54c2c122198356dd4818cf61d12d0d5406304
6
+ metadata.gz: fd2a23982b225238acafe47f68d220e0bbc004205e5dc4e828e9389325d87376753b1f6069e813a82e1f6dae1456be9e6319590a0e50ee7b70435ebc9d2cb091
7
+ data.tar.gz: 18f28222b17398787ce99cf2765e0f67cff0429160cb9cac853b8e6fdf73f8ce1c561a9e3f71a27ec56d2cc6fcd873a0e349379cc765a46547d257e26217ac5a
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,24 @@
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)
9
+ stub = stubs[abn] || default_stub
10
+ return stub if stub
11
11
 
12
- Abn.parse(body)
12
+ response = AbnLookup.connection.get("AbnDetails.aspx?abn=#{abn.gsub(/\s/, '')}")
13
+ body = response.body
14
+
15
+ raise InvalidGuidError if body["Message"] == "The GUID entered is not recognised as a Registered Party"
16
+ raise AbnNotFoundError if body["Abn"].empty?
17
+
18
+ Abn.parse(body)
19
+ end
13
20
  end
21
+
22
+ @stubs = {}
23
+ @default_stub = nil
14
24
  end
15
25
  end
@@ -2,14 +2,24 @@
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)
9
+ stub = stubs[acn] || default_stub
10
+ return stub if stub
11
11
 
12
- Abn.parse(body)
12
+ response = AbnLookup.connection.get("AcnDetails.aspx?acn=#{acn.gsub(/\s/, '')}")
13
+ body = response.body
14
+
15
+ raise InvalidGuidError if body["Message"] == "The GUID entered is not recognised as a Registered Party"
16
+ raise AbnNotFoundError if body["Abn"].empty?
17
+
18
+ Abn.parse(body)
19
+ end
13
20
  end
21
+
22
+ @stubs = {}
23
+ @default_stub = nil
14
24
  end
15
25
  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.2"
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"
metadata CHANGED
@@ -1,7 +1,7 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lairton Mendes
@@ -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: