Class: Ratis::LocationTypeAhead

Inherits:
Object
  • Object
show all
Defined in:
lib/ratis/location_type_ahead.rb

Class Method Summary collapse

Class Method Details

.where(conditions = {}) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ratis/location_type_ahead.rb', line 5

def self.where(conditions={})
  search_text = conditions.delete(:search)
  raise ArgumentError.new('You must provide some search text') unless search_text

  Ratis.all_conditions_used? conditions

  response = Request.get 'Locationtypeahead', { 'Search' => search_text.downcase }

  return "" unless response.success?

  response_code = response.to_hash[:locationtypeahead_response][:responsecode]
  locations     = response.to_array :locationtypeahead_response, :items, :item

  locations.map do |location_hash|
    Ratis::LocationTypeAheadItem.new(location_hash.merge(responsecode: response_code))
  end
end