Class: AbnLookup::SearchByAbn

Inherits:
Object
  • Object
show all
Defined in:
lib/abn_lookup/search_by_abn.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_stubObject

Returns the value of attribute default_stub.



6
7
8
# File 'lib/abn_lookup/search_by_abn.rb', line 6

def default_stub
  @default_stub
end

.stubsObject

Returns the value of attribute stubs.



6
7
8
# File 'lib/abn_lookup/search_by_abn.rb', line 6

def stubs
  @stubs
end

Class Method Details

.fetch(abn, options = {}) ⇒ Object

Raises:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/abn_lookup/search_by_abn.rb', line 8

def fetch(abn, options = {})
  stub = stubs[abn] || default_stub
  raise stub if stub.is_a?(Exception)
  return stub if stub

  parse = options.fetch(:parse, true)
  response = AbnLookup.connection.get("AbnDetails.aspx?abn=#{abn.gsub(/\s/, '')}")
  body  = response.body

  raise InvalidGuidError if body["Message"] == "The GUID entered is not recognised as a Registered Party"
  raise AbnNotFoundError if body["Abn"].empty? || body["Message"] == "No record found"

  parse ? Abn.parse(body) : body
end