abn_search 0.0.2 → 0.0.3

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abnsearch (0.0.1)
4
+ abn_search (0.0.2)
5
5
  nokogiri
6
6
 
7
7
  GEM
@@ -13,4 +13,4 @@ PLATFORMS
13
13
  ruby
14
14
 
15
15
  DEPENDENCIES
16
- abnsearch!
16
+ abn_search!
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "abn_search"
6
- s.version = '0.0.2'
6
+ s.version = '0.0.3'
7
7
  s.authors = ["James Martin"]
8
8
  s.email = ["james@visualconnect.net"]
9
9
  s.homepage = "https://github.com/jamsi/abn_search"
@@ -15,6 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
-
18
+
19
19
  s.add_dependency("nokogiri")
20
20
  end
@@ -2,28 +2,29 @@ require 'nokogiri'
2
2
  require 'open-uri'
3
3
 
4
4
  class ABNSearch
5
-
5
+
6
6
  module Version
7
- VERSION = "0.0.2"
7
+ VERSION = "0.0.3"
8
8
  end
9
-
9
+
10
10
  attr_accessor :name, :abn, :entity_type, :errors, :guid
11
-
11
+
12
12
  def initialize(abn=nil, guid=nil)
13
13
  self.errors = []
14
14
  self.abn = abn unless abn.nil?
15
15
  self.guid = guid unless guid.nil?
16
+ self.name = "n/a"
16
17
  self.search
17
18
  end
18
19
 
19
- def search
20
+ def search
20
21
  self.errors << "No ABN provided." && return if self.abn.nil?
21
22
  self.errors << "No GUID provided. Please obtain one at - http://www.abr.business.gov.au/Webservices.aspx" && return if self.guid.nil?
22
-
23
- @WSDL_URL = 'http://abr.business.gov.au/ABRXMLSearch/AbrXmlSearch.asmx/ABRSearchByABN?'
23
+
24
+ @WSDL_URL = 'http://abr.business.gov.au/ABRXMLSearch/AbrXmlSearch.asmx/ABRSearchByABN?'
24
25
  url = @WSDL_URL + "searchString=#{self.abn}&includeHistoricalDetails=n&authenticationGuid=#{self.guid}"
25
26
  doc = Nokogiri::HTML(open(url))
26
-
27
+
27
28
  # Fetch attributes we require
28
29
  base_path = '//html/body/abrpayloadsearchresults/response/businessentity'
29
30
  entity_type = doc.xpath(base_path + '/entitytype')
@@ -31,30 +32,30 @@ class ABNSearch
31
32
  trading_name = doc.xpath(base_path + '/maintradingname/organisationname')
32
33
  main_name = doc.xpath(base_path + '/mainname/organisationname')
33
34
  expires = doc.xpath(base_path + '/entitystatus/entitystatuscode')
34
-
35
+
35
36
  # Did we find a valid ABN?
36
37
  if abn[0].nil?
37
38
  self.errors << "Invalid ABN number."
38
39
  return
39
40
  end
40
-
41
+
41
42
  # Is the busines still valid?
42
43
  if expires && expires[0].content.include?("Cancelled")
43
44
  self.errors << "Business ABN #{self.abn} has expired."
44
45
  return
45
46
  end
46
-
47
+
47
48
  # Set ABN business attributes
48
49
  self.entity_type = entity_type[0].content unless entity_type[0].nil?
49
-
50
+
50
51
  # Set the business name. Sometimes there's no trading name .. but a "main name".
51
52
  if trading_name[0].nil?
52
- self.name = main_name[0].content
53
- else
54
- self.name = trading_name[0].content
53
+ self.name = main_name[0].content if !main_name.empty?
54
+ else
55
+ self.name = trading_name[0].content if !trading_name.empty?
55
56
  end
56
57
  end
57
-
58
+
58
59
  def valid?
59
60
  self.errors.size == 0
60
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abn_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-13 00:00:00.000000000Z
12
+ date: 2012-01-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &2153391800 !ruby/object:Gem::Requirement
16
+ requirement: &2157861680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153391800
24
+ version_requirements: *2157861680
25
25
  description: A simple ABN search library for validating and obtaining ABN details
26
26
  from the Australian Business Register.
27
27
  email:
@@ -61,3 +61,4 @@ signing_key:
61
61
  specification_version: 3
62
62
  summary: ABNSearch library for Australian businesses.
63
63
  test_files: []
64
+ has_rdoc: