Class: GdsApi::LocationsApi
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#coordinates_for_postcode(postcode) ⇒ Hash
Get the average coordinates for a postcode.
-
#local_custodian_code_for_postcode(postcode) ⇒ Array
Get a list of local custodian codes for a postcode.
-
#results_for_postcode(postcode) ⇒ Hash
Get all results for a postcode.
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
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
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”=>
[{"address"=>"29, DEAN ROAD, HAMPTON, TW12 1AQ",
"latitude"=>51.4303819,
"longitude"=>-0.3745976,
"local_custodian_code"=>5810}, ETC...
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 |