abn_lookup 0.1.2 → 0.1.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: 297535cb3f55808625b9ed723d9e122a77f3d0019310e9f5d42500b39c5a95a0
4
- data.tar.gz: 6996911798a81c9d4d4069dc988dfbe096bc5fcb83b0916349980186999879bf
3
+ metadata.gz: 88b2f5ee46fcac8095fabc91f3204768760578a2282aa95b767c630fdac42acb
4
+ data.tar.gz: c269d4d2a27ce0cd230d7184cd010609d489d0f1d1e3aa953f215631ea077467
5
5
  SHA512:
6
- metadata.gz: 3bf0ff6407bcc51d224c5923177d7c77358134b042bad00a782505ecf7e747b11f2d07b1dba9736c0dc6571adfb1e8a1ad778a4687663c4c33c4a69483bd47e8
7
- data.tar.gz: 7908f8607bf11ba12e5f1ef6952b07638ac6456afd799925a2e5adba7b805e11482aefe78dde62a7b08bc98a61ef70399da27b322145645cf67381b3924f43e3
6
+ metadata.gz: 8c279bacccf4c10a39c04fa639e4096c7ea20753bd4f800a4b1f5b5b2948ebedc7d4f8b26013dc28f369be8a1354ed21906d2a35d17ffa38a6413d591d41e647
7
+ data.tar.gz: c1725dce55ba5c6bfe86e69a50172449d6e7911d8de29dc1c52691feeb40225618ca437b090c9a42d3b67b33bf8c8184bc458f40e9af54fa13f649555ae9b0aa
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # AbnLookup
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ ABN Lookup is the free public view of the Australian Business Register (ABR). It provides access to publicly available information supplied by businesses when they register for an Australian Business Number (ABN).
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/abn_lookup`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ This gem provide a easy way to consume the JSON api.
6
6
 
7
7
  ## Installation
8
8
 
@@ -16,8 +16,129 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
16
 
17
17
  ## Usage
18
18
 
19
- TODO: Write usage instructions here
20
-
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
20
+
21
+ ```ruby
22
+ AbnLookup.guid = "your_GUID_key"
23
+ ```
24
+
25
+ This is a global configuration, all api calls will use this configuration.
26
+
27
+ If you are using Ruby On Rails you can put this in initializer folder.
28
+ ### Search by ABN
29
+
30
+ ```ruby
31
+ AbnLookup.search_by_abn("26008672179")
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",
40
+ "BusinessName"=>
41
+ ["Dynamic Pods",
42
+ "Dynamic Steel Frame",
43
+ "TOOL KIT DEPOT",
44
+ "CRAFTRIGHT",
45
+ "ONYA PRO",
46
+ "PROJECT GEAR",
47
+ "PROJECT TOOLS",
48
+ "Benchmark Tools",
49
+ "ONYA Tools",
50
+ "GARDENBASICS",
51
+ "ADELAIDE TOOLS",
52
+ "Adelaide Trade Tools",
53
+ "Discount Power Tools (S.A.)",
54
+ "Electric Power Tool Services",
55
+ "Oaklands Mower Centre",
56
+ "Oaklands Road Mower Centre",
57
+ "Tools not Toys",
58
+ "CLEVER LIVING CO",
59
+ "BUNNINGS KITCHEN COLLECTIVE",
60
+ "THE KITCHEN COLLECTIVE CO",
61
+ "home@gladesville",
62
+ "Gladesville Homemaker Centre",
63
+ "Bunnings Outdoors",
64
+ "big prawn",
65
+ "BUNNINGS TRADE",
66
+ "BUNNINGS",
67
+ "NARELLAN HOMEMAKER CENTRE",
68
+ "BUNNINGS WAREHOUSE",
69
+ "HARDWARE CAFE"],
70
+ "EntityName"=>"BUNNINGS GROUP LIMITED",
71
+ "EntityTypeCode"=>"PUB",
72
+ "EntityTypeName"=>"Australian Public Company",
73
+ "Gst"=>"2000-07-01",
74
+ "Message"=>""}
75
+ ```
76
+ ### Search by ACN
77
+
78
+ ```ruby
79
+ AbnLookup.search_by_acn("008672179")
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",
88
+ "BusinessName"=>
89
+ ["Dynamic Pods",
90
+ "Dynamic Steel Frame",
91
+ "TOOL KIT DEPOT",
92
+ "CRAFTRIGHT",
93
+ "ONYA PRO",
94
+ "PROJECT GEAR",
95
+ "PROJECT TOOLS",
96
+ "Benchmark Tools",
97
+ "ONYA Tools",
98
+ "GARDENBASICS",
99
+ "ADELAIDE TOOLS",
100
+ "Adelaide Trade Tools",
101
+ "Discount Power Tools (S.A.)",
102
+ "Electric Power Tool Services",
103
+ "Oaklands Mower Centre",
104
+ "Oaklands Road Mower Centre",
105
+ "Tools not Toys",
106
+ "CLEVER LIVING CO",
107
+ "BUNNINGS KITCHEN COLLECTIVE",
108
+ "THE KITCHEN COLLECTIVE CO",
109
+ "home@gladesville",
110
+ "Gladesville Homemaker Centre",
111
+ "Bunnings Outdoors",
112
+ "big prawn",
113
+ "BUNNINGS TRADE",
114
+ "BUNNINGS",
115
+ "NARELLAN HOMEMAKER CENTRE",
116
+ "BUNNINGS WAREHOUSE",
117
+ "HARDWARE CAFE"],
118
+ "EntityName"=>"BUNNINGS GROUP LIMITED",
119
+ "EntityTypeCode"=>"PUB",
120
+ "EntityTypeName"=>"Australian Public Company",
121
+ "Gst"=>"2000-07-01",
122
+ "Message"=>""}
123
+ ```
124
+ ### Search by Name
125
+
126
+ ```ruby
127
+ AbnLookup.search_by_name("Dynamic Pods", max_result = 10)
128
+
129
+ => {"Message"=>"",
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"}]}
141
+ ```
21
142
  ## Development
22
143
 
23
144
  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,29 @@
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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbnLookup
4
+ class AbnNotFoundError < StandardError
5
+ def initialize(msg = 'ABN not found')
6
+ super
7
+ end
8
+ end
9
+ end
@@ -3,6 +3,7 @@
3
3
  require "faraday"
4
4
  require_relative "callback_parser"
5
5
  require_relative "add_parameter"
6
+ require_relative "invalid_guid_error"
6
7
 
7
8
  module AbnLookup
8
9
  class Client
@@ -14,6 +15,8 @@ module AbnLookup
14
15
 
15
16
  def initialize(adapter: Faraday.default_adapter)
16
17
  @adapter = adapter
18
+
19
+ raise AbnLookup::InvalidGuidError, 'GUID not configued.' if AbnLookup.guid.nil?
17
20
  end
18
21
 
19
22
  def connection
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbnLookup
4
+ class InvalidGuidError < StandardError
5
+ def initialize(msg = 'InvalidGuidError: GUID is invalid')
6
+ super
7
+ end
8
+ end
9
+ end
@@ -3,8 +3,13 @@
3
3
  module AbnLookup
4
4
  class SearchByAbn
5
5
  def self.fetch(abn)
6
- response = AbnLookup.connection.get("AbnDetails.aspx?abn=#{abn}")
7
- response.body
6
+ response = AbnLookup.connection.get("AbnDetails.aspx?abn=#{abn.gsub(/\s/, '')}")
7
+ body = response.body
8
+
9
+ raise InvalidGuidError if body["Message"] == "The GUID entered is not recognised as a Registered Party"
10
+ raise AbnNotFoundError if body["Abn"].empty?
11
+
12
+ AbnFormatter.formatter(body)
8
13
  end
9
14
  end
10
15
  end
@@ -3,8 +3,13 @@
3
3
  module AbnLookup
4
4
  class SearchByAcn
5
5
  def self.fetch(acn)
6
- response = AbnLookup.connection.get("AcnDetails.aspx?acn=#{acn}")
6
+ response = AbnLookup.connection.get("AcnDetails.aspx?acn=#{acn.gsub(/\s/, '')}")
7
7
  response.body
8
+
9
+ raise InvalidGuidError if body["Message"] == "The GUID entered is not recognised as a Registered Party"
10
+ raise AbnNotFoundError if body["Abn"].empty?
11
+
12
+ AbnFormatter.formatter(body)
8
13
  end
9
14
  end
10
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AbnLookup
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/abn_lookup.rb CHANGED
@@ -6,6 +6,9 @@ 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"
10
+ require "abn_lookup/abn_not_found_error"
11
+ require "abn_lookup/invalid_guid_error"
9
12
 
10
13
  require "faraday"
11
14
  require "faraday_middleware"
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.1.2
4
+ version: 0.1.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-05-29 00:00:00.000000000 Z
11
+ date: 2024-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -52,10 +52,13 @@ files:
52
52
  - README.md
53
53
  - Rakefile
54
54
  - lib/abn_lookup.rb
55
+ - lib/abn_lookup/abn_formatter.rb
56
+ - lib/abn_lookup/abn_not_found_error.rb
55
57
  - lib/abn_lookup/add_parameter.rb
56
58
  - lib/abn_lookup/callback_parser.rb
57
59
  - lib/abn_lookup/client.rb
58
60
  - lib/abn_lookup/configuration.rb
61
+ - lib/abn_lookup/invalid_guid_error.rb
59
62
  - lib/abn_lookup/search_by_abn.rb
60
63
  - lib/abn_lookup/search_by_acn.rb
61
64
  - lib/abn_lookup/search_by_name.rb