Class: GdsApi::LocationsApi

Inherits:
Base
  • Object
show all
Defined in:
lib/gds_api/locations_api.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

#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