Class: Abn::Client
- Inherits:
-
Object
- Object
- Abn::Client
- Defined in:
- lib/abn/client.rb
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
-
#search(abn) ⇒ Hash
Performs an ABR search for the ABN setup upon initialization.
-
#search_by_acn(acn) ⇒ Hash
Performs an ABR search for the ABN setup upon initialization.
-
#search_by_name(name, states = ["NSW"], postcode = "ALL") ⇒ Array
Searches the ABR registry by name.
- #valid? ⇒ Boolean
Constructor Details
#initialize(guid = nil, options = {}) ⇒ ABNSearch
Setup a new instance of the ABN search class.
12 13 14 15 16 17 18 19 |
# File 'lib/abn/client.rb', line 12 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.
4 5 6 |
# File 'lib/abn/client.rb', line 4 def @client_options end |
#errors ⇒ Object
Returns the value of attribute errors.
4 5 6 |
# File 'lib/abn/client.rb', line 4 def errors @errors end |
#guid ⇒ Object
Returns the value of attribute guid.
4 5 6 |
# File 'lib/abn/client.rb', line 4 def guid @guid end |
#proxy ⇒ Object
Returns the value of attribute proxy.
4 5 6 |
# File 'lib/abn/client.rb', line 4 def proxy @proxy end |
Instance Method Details
#parse_search_result(result) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/abn/client.rb', line 105 def parse_search_result(result) entity = Abn::Entity.new entity.acn = result[:asic_number] rescue nil entity.abn = result[:abn][:identifier_value] rescue nil entity.entity_type = result[:entity_type][:entity_description] rescue nil entity.status = result[:entity_status][:entity_status_code] rescue nil entity.main_name = result[:main_name][:organisation_name] rescue nil entity.trading_name = result[:main_trading_name][:organisation_name] rescue nil entity.legal_name = "#{result[:legal_name][:given_name]} #{result[:legal_name][:family_name]}" rescue nil entity.legal_name2 = result[:full_name] rescue nil entity.other_trading_name = result[:other_trading_name][:organisation_name] rescue nil entity.active_from_date = result[:entity_status][:effective_from] rescue nil entity.address_state_code = result[:main_business_physical_address][:state_code] rescue nil entity.address_post_code = result[:main_business_physical_address][:postcode] rescue nil entity.address_from_date = result[:main_business_physical_address][:effective_from] rescue nil entity.last_updated = result[:record_last_updated_date] rescue nil entity.gst_from_date = result[:goods_and_services_tax][:effective_from] rescue nil entity.name = entity.best_name return entity.instance_values end |
#search(abn) ⇒ Hash
Performs an ABR search for the ABN setup upon initialization
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/abn/client.rb', line 43 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: 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_acn(acn) ⇒ Hash
Performs an ABR search for the ABN setup upon initialization
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/abn/client.rb', line 25 def search_by_acn(acn) self.errors << "No ACN provided." && return if acn.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_asic, message: { authenticationGuid: self.guid, searchString: acn.gsub(" ", ""), includeHistoricalDetails: "N" }) result = response.body[:abr_search_by_asic_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") ⇒ Array
Searches the ABR registry by name. Simply pass in the search term and which state(s) to search in.
63 64 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 101 102 103 |
# File 'lib/abn/client.rb', line 63 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) result_list = response.body[:abr_search_by_name_response][:abr_payload_search_results][:response][:search_results_list] if result_list.blank? return [] else 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 end rescue => ex self.errors << ex.to_s end end |
#valid? ⇒ Boolean
126 127 128 |
# File 'lib/abn/client.rb', line 126 def valid? self.errors.size == 0 end |