Class: GdsApi::PlacesManager

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

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#client, #create_client, #get_list, #initialize, #url_for_slug

Constructor Details

This class inherits a constructor from GdsApi::Base

Instance Method Details

#api_url(type, params) ⇒ Object



4
5
6
7
8
# File 'lib/gds_api/places_manager.rb', line 4

def api_url(type, params)
  vals = %i[limit lat lng postcode local_authority_slug].select { |p| params.include? p }
  querystring = URI.encode_www_form(vals.map { |p| [p, params[p]] })
  "#{@endpoint}/places/#{type}.json?#{querystring}"
end

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



10
11
12
13
# File 'lib/gds_api/places_manager.rb', line 10

def places(type, lat, lon, limit = 5)
  url = api_url(type, lat:, lng: lon, limit:)
  get_json(url)
end

#places_for_postcode(type, postcode, limit = 5, local_authority_slug = nil) ⇒ Object



15
16
17
18
19
20
# File 'lib/gds_api/places_manager.rb', line 15

def places_for_postcode(type, postcode, limit = 5, local_authority_slug = nil)
  options = { postcode:, limit: }
  options.merge!(local_authority_slug:) if local_authority_slug
  url = api_url(type, options)
  get_json(url) || []
end

#places_kml(type) ⇒ Object



22
23
24
# File 'lib/gds_api/places_manager.rb', line 22

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