abn_lookup 0.2.0 → 0.2.2

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: 17c443ef9e5e1f5a64ceb9f5023c6b63c7d5a8e9ac961ce036f69437e121c610
4
- data.tar.gz: a0a8d4179f01dc7334d109f9369205e60933dbaa35c7cab65f67ad93383a8a01
3
+ metadata.gz: 2433d9b12d5cabd5307e7232ec143f466c0e5113e23ed588e9ccc66ccc5ccfe3
4
+ data.tar.gz: 873a9755fc6cbb0d3f0085e59f66896fd3fdc28a1d22b2c1ddb00894bbdd4a05
5
5
  SHA512:
6
- metadata.gz: d82d72f531b739b24c986bde8c2917ebe1415253410f8144ac765af36bc3a1ce011dd992f8956b0b4461f84c869c0683969bc7309ae465c0d31eb3924d3c8cfb
7
- data.tar.gz: b8b2bff6356f5e9cf3843b894b51892e181d4fb940ba90e5f562f6a911e10a9eddafef1e7bf08f172330824034ccbeb4dd10bb2fd4a00bebdcfb5043cc083ef7
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.
@@ -0,0 +1,31 @@
1
+ module AbnLookup
2
+ class Abn
3
+ attr_accessor :abn, :abn_status, :abn_status_effective_from, :acn, :address_date,
4
+ :address_postcode, :address_state, :business_name, :entity_name,
5
+ :entity_type_code, :entity_type_name, :gst, :message
6
+
7
+ def active?
8
+ abn_status == "Active"
9
+ end
10
+
11
+ def inspect
12
+ "#<#{self.class.name}:0x#{object_id} @abn=\"#{abn}\" @acn=\"#{acn}\" @active=#{active?} @gst=\"#{gst}\" @entity_name=\"#{entity_name}\">"
13
+ end
14
+
15
+ def self.parse(data)
16
+ abn = Abn.new
17
+
18
+ # Transforming PascalCase to snake_case
19
+ snake_case = data.each_with_object({}) do |(key, value), new_hash|
20
+ new_key = key.to_s.gsub(/([A-Z])/, '_\1').downcase
21
+ new_hash[new_key.sub(/^_/, '').to_sym] = value
22
+ end
23
+
24
+ snake_case.each do |key, value|
25
+ abn.send("#{key}=", value) if abn.respond_to?("#{key}=")
26
+ end
27
+
28
+ abn
29
+ end
30
+ end
31
+ end
@@ -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
- AbnFormatter.formatter(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
- AbnFormatter.formatter(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.0"
4
+ VERSION = "0.2.2"
5
5
  end
data/lib/abn_lookup.rb CHANGED
@@ -6,9 +6,10 @@ require "abn_lookup/client"
6
6
  require "abn_lookup/search_by_abn"
7
7
  require "abn_lookup/search_by_acn"
8
8
  require "abn_lookup/search_by_name"
9
- require "abn_lookup/abn_formatter"
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.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lairton Mendes
@@ -52,7 +52,7 @@ files:
52
52
  - README.md
53
53
  - Rakefile
54
54
  - lib/abn_lookup.rb
55
- - lib/abn_lookup/abn_formatter.rb
55
+ - lib/abn_lookup/abn.rb
56
56
  - lib/abn_lookup/abn_not_found_error.rb
57
57
  - lib/abn_lookup/add_parameter.rb
58
58
  - lib/abn_lookup/callback_parser.rb
@@ -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:
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AbnLookup
4
- class AbnFormatter
5
- def self.formatter(body)
6
- hash = {
7
- abn: body["Abn"],
8
- abn_status: body["AbnStatus"],
9
- abn_status_effective_from: body["AbnStatusEffectiveFrom"],
10
- acn: body["Acn"],
11
- address_date: body["AddressDate"],
12
- address_postcode: body["AddressPostcode"],
13
- address_state: body["AddressState"],
14
- business_name: body["BusinessName"],
15
- entity_name: body["EntityName"],
16
- entity_type_code: body["EntityTypeCode"],
17
- entity_type_name: body["EntityTypeName"],
18
- gst: body["Gst"],
19
- message: body["Message"]
20
- }
21
-
22
- # build Struct
23
- abn = Struct.new(*hash.keys)
24
-
25
- # converting hash to struct
26
- abn.new(*hash.values)
27
- end
28
- end
29
- end