Skip to content

Commit

Permalink
request metadata in Trimble maps single search call (#1618)
Browse files Browse the repository at this point in the history
* adds metadata

add metadata option to single search for trimble maps api call

* modify fixtures

* Revert "modify fixtures"

This reverts commit 67334e3.

* copy metadata over to each location so data object would include that
adds test for that

* update fixtures

* add bang to add_metadata_to_locations method name
  • Loading branch information
arianseyeditfx authored Jun 26, 2023
1 parent be846b8 commit a692545
Show file tree
Hide file tree
Showing 8 changed files with 520 additions and 102 deletions.
12 changes: 11 additions & 1 deletion lib/geocoder/lookups/pc_miler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ def base_query_url(query)
def results(query)
return [] unless data = fetch_data(query)
if data['Locations']
add_metadata_to_locations!(data)
data['Locations']
else
[]
end
end

def add_metadata_to_locations!(data)
confidence = data['QueryConfidence']
data['Locations'].each do |location|
location['QueryConfidence'] = confidence
end
end

def query_url_params(query)
if query.reverse_geocode?
lat,lon = query.coordinates
Expand All @@ -51,7 +59,9 @@ def query_url_params(query)

{
authToken: configuration.api_key,
query: escaped_query
query: escaped_query,
# to add additional metadata to response such as QueryConfidence
include: 'Meta'
}.merge(super(query))
end

Expand Down
68 changes: 40 additions & 28 deletions lib/geocoder/results/pc_miler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,50 @@
module Geocoder::Result
class PcMiler < Base
# sample response:
# https://singlesearch.alk.com/NA/api/search?query=Duluth MN
# https://singlesearch.alk.com/na/api/search?authToken=<TOKEN>&include=Meta&query=Feasterville
#
# {
# {
# "Err": 0,
# "ErrString": "OK",
# "QueryConfidence": 1,
# "TimeInMilliseconds": 93,
# "GridDataVersion": "GRD_ALK.NA.2023.01.18.29.1.1",
# "CommitID": "pcmws-22.08.11.0-1778-g586da49bd1b: 05/30/2023 20:14",
# "Locations": [
# {
# "Address": {
# "StreetAddress": "",
# "LocalArea": "",
# "City": "Duluth",
# "State": "MN",
# "StateName": "Minnesota",
# "Zip": "55806",
# "County": "St. Louis",
# "Country": "US",
# "CountryFullName": "United States",
# "SPLC": null
# },
# "Coords": {
# "Lat": "46.776443",
# "Lon": "-92.110529"
# },
# "Region": 4,
# "POITypeID": 0,
# "PersistentPOIID": -1,
# "SiteID": -1,
# "ResultType": 3,
# "ShortString": "Duluth, MN, US, St. Louis 55806",
# "TimeZone": "GMT-5:00 CDT"
# }
# {
# "Address": {
# "StreetAddress": "",
# "LocalArea": "",
# "City": "Feasterville",
# "State": "PA",
# "StateName": "Pennsylvania",
# "Zip": "19053",
# "County": "Bucks",
# "Country": "US",
# "CountryFullName": "United States",
# "SPLC": null
# },
# "Coords": {
# "Lat": "40.150025",
# "Lon": "-75.002511"
# },
# "StreetCoords": {
# "Lat": "40.150098",
# "Lon": "-75.002827"
# },
# "Region": 4,
# "POITypeID": 0,
# "PersistentPOIID": -1,
# "SiteID": -1,
# "ResultType": 4,
# "ShortString": "Feasterville",
# "GridID": 37172748,
# "LinkID": 188,
# "Percent": 6291,
# "TimeZone": "GMT-4:00 EDT"
# }
# ]
# }
# }

def address(format=:unused)
[street, city, state, postal_code, country]
Expand Down
32 changes: 22 additions & 10 deletions test/fixtures/pc_miler_duluth_mn
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
{
"Err": 0,
"ErrString": "OK",
"QueryConfidence": 1,
"TimeInMilliseconds": 16,
"GridDataVersion": "GRD_ALK.NA.2023.01.18.29.1.1",
"CommitID": "pcmws-22.08.11.0-1778-g586da49bd1b: 05/30/2023 20:14",
"Locations": [
{
"Address": {
"City": "Duluth",
"Country": "US",
"CountryFullName": "United States",
"County": "St. Louis",
"StreetAddress": "",
"LocalArea": "",
"SPLC": null,
"City": "Duluth",
"State": "MN",
"StateName": "Minnesota",
"StreetAddress": "",
"Zip": "55806"
"Zip": "55806",
"County": "St. Louis",
"Country": "US",
"CountryFullName": "United States",
"SPLC": null
},
"Coords": {
"Lat": "46.776443",
"Lon": "-92.110529"
},
"StreetCoords": {
"Lat": "46.776536",
"Lon": "-92.110673"
},
"Region": 4,
"POITypeID": 0,
"PersistentPOIID": -1,
"Region": 4,
"SiteID": -1,
"ResultType": 3,
"ShortString": "Duluth, MN, US, St. Louis 55806",
"SiteID": -1,
"GridID": 16543728,
"LinkID": 39,
"Percent": 4307,
"TimeZone": "GMT-5:00 CDT"
}
]
}
}
70 changes: 41 additions & 29 deletions test/fixtures/pc_miler_madison_square_garden
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
{
"Err": 0,
"Locations": [
{
"Address": {
"StreetAddress": "4 Pennsylvania Plaza",
"LocalArea": "",
"City": "New York",
"State": "NY",
"StateName": "New York",
"Zip": "10001",
"County": "New York",
"Country": "US",
"CountryFullName": "United States",
"SPLC": null
},
"Coords": {
"Lat": "40.750712",
"Lon": "-73.994241"
},
"Region": 4,
"POITypeID": 116,
"PersistentPOIID": 198701,
"SiteID": -1,
"ResultType": 9,
"ShortString": "Madison Square Garden",
"TimeZone": "GMT-4:00 EDT"
}
]
}
"Err": 0,
"ErrString": "OK",
"QueryConfidence": 1,
"TimeInMilliseconds": 31,
"GridDataVersion": "GRD_ALK.NA.2023.01.18.29.1.1",
"CommitID": "pcmws-22.08.11.0-1778-g586da49bd1b: 05/30/2023 20:14",
"Locations": [
{
"Address": {
"StreetAddress": "4 Pennsylvania Plaza",
"LocalArea": "",
"City": "New York",
"State": "NY",
"StateName": "New York",
"Zip": "10001",
"County": "New York",
"Country": "US",
"CountryFullName": "United States",
"SPLC": null
},
"Coords": {
"Lat": "40.750712",
"Lon": "-73.994241"
},
"StreetCoords": {
"Lat": "40.750806",
"Lon": "-73.994472"
},
"Region": 4,
"POITypeID": 116,
"PersistentPOIID": 198701,
"SiteID": -1,
"ResultType": 9,
"ShortString": "Madison Square Garden",
"GridID": 19445260,
"LinkID": 565,
"Percent": 7364,
"TimeZone": "GMT-4:00 EDT"
}
]
}
32 changes: 22 additions & 10 deletions test/fixtures/pc_miler_reverse
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
{
"Err": 0,
"ErrString": "OK",
"QueryConfidence": 1,
"TimeInMilliseconds": 0,
"GridDataVersion": "GRD_ALK.NA.2023.01.18.29.1.1",
"CommitID": "pcmws-22.08.11.0-1778-g586da49bd1b: 05/30/2023 20:14",
"Locations": [
{
"Address": {
"City": "Alliance",
"Country": "US",
"CountryFullName": "United States",
"County": "Box Butte",
"StreetAddress": "2093 NE-87",
"LocalArea": "",
"SPLC": null,
"City": "Alliance",
"State": "NE",
"StateName": "Nebraska",
"StreetAddress": "2093 NE-87",
"Zip": "69301"
"Zip": "69301",
"County": "Box Butte",
"Country": "US",
"CountryFullName": "United States",
"SPLC": null
},
"Coords": {
"Lat": "42.14228",
"Lon": "-102.85796"
},
"StreetCoords": {
"Lat": "42.142238",
"Lon": "-102.859302"
},
"Region": 4,
"POITypeID": 0,
"PersistentPOIID": -1,
"Region": 4,
"SiteID": -1,
"ResultType": 14,
"ShortString": "2093 NE-87, Alliance, NE, US, Box Butte 69301",
"SiteID": -1,
"GridID": 666788,
"LinkID": 1334,
"Percent": 4865,
"TimeZone": "GMT-6:00 MDT"
}
]
}
}
Loading

0 comments on commit a692545

Please sign in to comment.