Class: GdsApi::Imminence

Inherits:
Base
  • Object
show all
Defined in:
lib/gds_api/imminence.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#adapter_name, #client, #create_client, #initialize, #url_for_slug

Constructor Details

This class inherits a constructor from GdsApi::Base

Class Method Details

.parse_place_hash(place_hash) ⇒ Object



14
15
16
17
18
19
# File 'lib/gds_api/imminence.rb', line 14

def self.parse_place_hash(place_hash)
  location = self.extract_location_hash(place_hash["location"])
  address = self.extract_address_hash(place_hash)

  place_hash.merge(location).merge(address)
end

Instance Method Details

#api_url(type, lat, lon, limit = 5) ⇒ Object



5
6
7
# File 'lib/gds_api/imminence.rb', line 5

def api_url(type, lat, lon, limit=5)
  "#{@endpoint}/places/#{type}.json?limit=#{limit}&lat=#{lat}&lng=#{lon}"
end

#business_support_schemes(facets_hash) ⇒ Object



25
26
27
28
29
# File 'lib/gds_api/imminence.rb', line 25

def business_support_schemes(facets_hash)
  query = facets_hash.keys.sort.map { |k| "#{k.to_s}=#{facets_hash[k]}" }.join("&")
  query = "?#{query}" unless query.empty?
  get_json!("#{@endpoint}/business_support_schemes.json#{query}")
end

#places(type, lat, lon, limit = 5) ⇒ Object



9
10
11
12
# File 'lib/gds_api/imminence.rb', line 9

def places(type, lat, lon, limit=5)
  places = get_json(api_url(type, lat, lon, limit)) || []
  places.map { |p| self.class.parse_place_hash(p) }
end

#places_kml(type) ⇒ Object



21
22
23
# File 'lib/gds_api/imminence.rb', line 21

def places_kml(type)
  get_raw("#{@endpoint}/places/#{type}.kml")
end