Class: GdsApi::LocationsApi

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

Instance Method Summary collapse

Instance Method Details

#coordinates_for_postcode(postcode) ⇒ Hash

Get the average coordinates for a postcode

Parameters:

  • postcode (String, nil)

    The postcode for which the coordinates are requested

Returns:

  • (Hash)

    The average coordinates (two fields, "latitude" and "longitude") for a specific postcode



23
24
25
26
27
# File 'lib/gds_api/locations_api.rb', line 23

def coordinates_for_postcode(postcode)
  response = get_json("#{endpoint}/v1/locations?postcode=#{postcode}")

  { "latitude" => response["average_latitude"], "longitude" => response["average_longitude"] } unless response["results"].nil?
end

#local_custodian_code_for_postcode(postcode) ⇒ Array

Get a list of local custodian codes for a postcode

Parameters:

  • postcode (String, nil)

    The postcode for which the custodian codes are requested

Returns:

  • (Array)

    All local custodian codes for a specific postcode



10
11
12
13
14
15
16
# File 'lib/gds_api/locations_api.rb', line 10

def local_custodian_code_for_postcode(postcode)
  response = get_json("#{endpoint}/v1/locations?postcode=#{postcode}")

  return [] if response["results"].nil?

  response["results"].map { |r| r["local_custodian_code"] }.uniq
end

#results_for_postcode(postcode) ⇒ Hash

Get all results for a postcode

and longitude, and an array of results for individual addresses with lat/long/lcc, eg: { "average_latitude"=>51.43122412857143, "average_longitude"=>-0.37395367142857144, "results"=> [DEAN ROAD, HAMPTON, TW12 1AQ", "latitude"=>51.4303819, "longitude"=>-0.3745976, "local_custodian_code"=>5810, ETC...

Parameters:

  • postcode (String, nil)

    The postcode for which results are requested

Returns:

  • (Hash)

    The fulls results as returned from Locations API, with the average latitude



43
44
45
# File 'lib/gds_api/locations_api.rb', line 43

def results_for_postcode(postcode)
  get_json("#{endpoint}/v1/locations?postcode=#{postcode}")
end