GoogleMaps¶
-
class
GoogleMaps(opts)¶ An address search provider for Google Maps.
Arguments: - opts.api_url (string) – The URL of the Google Maps geocode API. Defaults to ‘http://maps.googleapis.com/maps/api/geocode/json‘.
- opts.extract_address_label (function) – Function that extracts a human-friendly label from a GoogleMaps
API result. See
GoogleMaps.extract_address_label()for the function signature and default implementation. - opts.extract_address_data (function) – Function that extracts data to store on a contact from a GoogleMaps
API result. See
GoogleMaps.extract_address_data()for the function signature and default implementation.
-
static
extract_address(result)¶ Takes a result from the Google Maps API and returns a
AddressResult()for it.Arguments: - result (object) – A raw GoogleMaps result.
Returns: An
Addressresult().Calls
GoogleMaps.extract_address_label()andGoogleMaps.extract_address_data()for the label and data respectively.
-
static
extract_address_data(result)¶ Extracts address data to store on a contact when an address is selected. See
LocationState.store_contact_data()for a description of how this data is stored.Returns the object:
{ formatted_address: result.formatted_address }
May be overriden using the
extract_address_dataclass option.Arguments: - result (object) – A location result from the Google Maps API.
Returns object: An object of key-value pairs to store in contact data.
-
static
extract_address_label(result)¶ Returns the value of
result.formatted_addressas a human-friendly display name for a Google Maps location result.May be overriden using the
extract_address_labelclass option.Arguments: - result (object) – A location result from the Google Maps API.
Return string: The label to display for this result.
-
static
init()¶ Initialization function invoked during state initialization.
Arguments: - im (InteractionMachine) – The state’s
InteractionMachine()instance.
- im (InteractionMachine) – The state’s
-
static
search(query_text)¶ Return an ordered list of locations matching the query via a promise that is fulfilled when the search results are ready.
Returns an empty list if an error occurs while accessing the GoogleMaps API.
Arguments: - query_text (string) – The search query.
Returns: A promise that yields the list of search results.
-
fixture(opts)¶ Returns an HTTP resource fixture for a GoogleMaps location query.
Arguments: - opts.query (string) – The address that is to be queried. Required.
- opts.address_list (array of strings) – A list of
formatted_address``es that should be sent in the response. If response_data is included, this will be ignored. Defaults to ``[]. - opts.request_url (string) – URL for the HTTP request. Defaults to
"http://maps.googleapis.com/maps/api/geocode/json". - opts.response_data (object) –
An that object that represents the response from the Google Maps API. This overrides the response data generated from
opts.address_list. Example response data:{ status: "OK", results: [ { formatted_address: "1 Baker Street", }, { formatted_address: "2 Baker Street", }, ], }
Usage:
tester .setup(function(api) { api.http.fixtures.add( GoogleMaps.fixture({ request: "New Street", address_list: [ "New Street 1", "New Street 2", ], }); ); });