Class: ABNSearch
- Inherits:
-
Object
- Object
- ABNSearch
- Defined in:
- lib/abn_search.rb
Defined Under Namespace
Modules: Version
Instance Attribute Summary collapse
-
#client_options ⇒ Object
Returns the value of attribute client_options.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#guid ⇒ Object
Returns the value of attribute guid.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
Instance Method Summary collapse
-
#initialize(guid = nil, options = {}) ⇒ ABNSearch
constructor
Setup a new instance of the ABN search class.
-
#parse_search_result(result) ⇒ Object
Parses results for a search by ABN.
-
#search(abn) ⇒ ABNSearch
Performs an ABR search for the ABN setup upon initialization.
-
#search_by_name(name, states = ['NSW'], postcode = 'ALL') ⇒ Object
Searches the ABR registry by name.
- #valid? ⇒ Boolean
Constructor Details
#initialize(guid = nil, options = {}) ⇒ ABNSearch
Setup a new instance of the ABN search class.
32 33 34 35 36 37 38 39 |
# File 'lib/abn_search.rb', line 32 def initialize(guid=nil, = {}) self.errors = [] self.guid = guid unless guid.nil? self.proxy = [:proxy] || nil self. = {} self. = { :wsdl => "http://www.abn.business.gov.au/abrxmlsearch/ABRXMLSearch.asmx?WSDL" } self..merge!({ :proxy => self.proxy }) unless self.proxy.nil? end |
Instance Attribute Details
#client_options ⇒ Object
Returns the value of attribute client_options.
23 24 25 |
# File 'lib/abn_search.rb', line 23 def @client_options end |
#errors ⇒ Object
Returns the value of attribute errors.
23 24 25 |
# File 'lib/abn_search.rb', line 23 def errors @errors end |
#guid ⇒ Object
Returns the value of attribute guid.
23 24 25 |
# File 'lib/abn_search.rb', line 23 def guid @guid end |
#proxy ⇒ Object
Returns the value of attribute proxy.
23 24 25 |
# File 'lib/abn_search.rb', line 23 def proxy @proxy end |
Instance Method Details
#parse_search_result(result) ⇒ Object
Parses results for a search by ABN
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/abn_search.rb', line 103 def parse_search_result(result) result = { abn: result[:abn][:identifier_value], entity_type: result[:entity_type].blank? ? "" : result[:entity_type][:entity_description], status: result[:entity_status].blank? ? "" : result[:entity_status][:entity_status_code], main_name: result[:main_name].blank? ? "" : result[:main_name][:organisation_name], trading_name: result[:main_trading_name].blank? ? "" : result[:main_trading_name][:organisation_name], legal_name: result[:legal_name].blank? ? "" : "#{result[:legal_name][:given_name]} #{result[:legal_name][:family_name]}", other_trading_name: result[:other_trading_name].blank? ? "" : result[:other_trading_name][:organisation_name] } # Work out what we should return as a name if !result[:trading_name].blank? result[:name] = result[:trading_name] elsif !result[:main_name].blank? result[:name] = result[:main_name] elsif !result[:other_trading_name].blank? result[:name] = result[:other_trading_name] else result[:name] = result[:legal_name] end return result end |
#search(abn) ⇒ ABNSearch
Performs an ABR search for the ABN setup upon initialization
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/abn_search.rb', line 45 def search(abn) self.errors << "No ABN provided." && return if abn.nil? self.errors << "No GUID provided. Please obtain one at - http://www.abr.business.gov.au/Webservices.aspx" && return if self.guid.nil? begin client = Savon.client(self.) response = client.call(:abr_search_by_abn, message: { authenticationGuid: self.guid, searchString: abn.gsub(" ", ""), includeHistoricalDetails: "N" }) result = response.body[:abr_search_by_abn_response][:abr_payload_search_results][:response][:business_entity] return parse_search_result(result) rescue => ex self.errors << ex.to_s end end |
#search_by_name(name, states = ['NSW'], postcode = 'ALL') ⇒ Object
Searches the ABR registry by name. Simply pass in the search term and which state(s) to search in.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/abn_search.rb', line 65 def search_by_name(name, states=['NSW'], postcode='ALL') begin client = Savon.client(self.) request = { externalNameSearch: { authenticationGuid: self.guid, name: name, filters: { nameType: { tradingName: 'Y', legalName: 'Y' }, postcode: postcode, "stateCode" => { 'QLD' => states.include?('QLD') ? "Y" : "N", 'NT' => states.include?('NT') ? "Y" : "N", 'SA' => states.include?('SA') ? "Y" : "N", 'WA' => states.include?('WA') ? "Y" : "N", 'VIC' => states.include?('VIC') ? "Y" : "N", 'ACT' => states.include?('ACT') ? "Y" : "N", 'TAS' => states.include?('TAS') ? "Y" : "N", 'NSW' => states.include?('NSW') ? "Y" : "N" } } }, authenticationGuid: self.guid } response = client.call(:abr_search_by_name, message: request) results = response.body[:abr_search_by_name_response][:abr_payload_search_results][:response][:search_results_list][:search_results_record] return [parse_search_result(results)] if !results.is_a?(Array) return results.map do |r| parse_search_result(r) end rescue => ex self.errors << ex.to_s end end |
#valid? ⇒ Boolean
128 129 130 |
# File 'lib/abn_search.rb', line 128 def valid? self.errors.size == 0 end |