// Copyright 2022 Luca Casonato. All rights reserved. MIT license. /** * Places Insights API Client for Deno * =================================== * * Places Insights API. * * Docs: https://g3doc.corp.google.com/geo/platform/area_insights/README.md?cl=head * Source: https://googleapis.deno.dev/v1/areainsights:v1.ts */ import { auth, CredentialsClient, GoogleAuth, request } from "/_/base@v1/mod.ts"; export { auth, GoogleAuth }; export type { CredentialsClient }; /** * Places Insights API. */ export class areaInsights { #client: CredentialsClient | undefined; #baseUrl: string; constructor(client?: CredentialsClient, baseUrl: string = "https://areainsights.googleapis.com/") { this.#client = client; this.#baseUrl = baseUrl; } /** * Compute Insights RPC This method lets you retrieve insights about areas * using a variaty of filter such as: area, place type, operating status, * price level and ratings. Currently "count" and "places" insights are * supported. With "count" insights you can answer questions such as "How many * restaurant are located in California that are operational, are inexpensive * and have an average rating of at least 4 stars" (see `insight` enum for * more details). With "places" insights, you can determine which places match * the requested filter. Clients can then use those place resource names to * fetch more details about each individual place using the Places API. * */ async v1ComputeInsights(req: ComputeInsightsRequest): Promise { const url = new URL(`${this.#baseUrl}v1:computeInsights`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return deserializeComputeInsightsResponse(data); } } /** * A circle is defined by a center point and radius in meters. */ export interface Circle { /** * The latitude and longitude of the center of the circle. */ latLng?: LatLng; /** * The Place resource name of the center of the circle. Only point places are * supported. */ place?: string; /** * Optional. The radius of the circle in meters */ radius?: number; } /** * Request for the ComputeInsights RPC. */ export interface ComputeInsightsRequest { /** * Required. Insight filter. */ filter?: Filter; /** * Required. Insights to compute. Currently only INSIGHT_COUNT and * INSIGHT_PLACES are supported. */ insights?: | "INSIGHT_UNSPECIFIED" | "INSIGHT_COUNT" | "INSIGHT_PLACES"[]; } /** * Response for the ComputeInsights RPC. */ export interface ComputeInsightsResponse { /** * Result for Insights.INSIGHT_COUNT. */ count?: bigint; /** * Result for Insights.INSIGHT_PLACES. */ placeInsights?: PlaceInsight[]; } function serializeComputeInsightsResponse(data: any): ComputeInsightsResponse { return { ...data, count: data["count"] !== undefined ? String(data["count"]) : undefined, }; } function deserializeComputeInsightsResponse(data: any): ComputeInsightsResponse { return { ...data, count: data["count"] !== undefined ? BigInt(data["count"]) : undefined, }; } /** * Custom Area. */ export interface CustomArea { /** * Required. The custom area represented as a polygon */ polygon?: Polygon; } /** * Filters for the ComputeInsights RPC. */ export interface Filter { /** * Required. Restricts results to places which are located in the area * specified by location filters. */ locationFilter?: LocationFilter; /** * Optional. Restricts results to places whose operating status is included * on this list. If operating_status is not set, OPERATING_STATUS_OPERATIONAL * is used as default. */ operatingStatus?: | "OPERATING_STATUS_UNSPECIFIED" | "OPERATING_STATUS_OPERATIONAL" | "OPERATING_STATUS_PERMANENTLY_CLOSED" | "OPERATING_STATUS_TEMPORARILY_CLOSED"[]; /** * Optional. Restricts results to places whose price level is included on * this list. If price_level is not set, all price levels are included in the * results. */ priceLevels?: | "PRICE_LEVEL_UNSPECIFIED" | "PRICE_LEVEL_FREE" | "PRICE_LEVEL_INEXPENSIVE" | "PRICE_LEVEL_MODERATE" | "PRICE_LEVEL_EXPENSIVE" | "PRICE_LEVEL_VERY_EXPENSIVE"[]; /** * Optional. Restricts results to places whose average user ratings are in * the range specified by rating_filter. If rating_filter is not set, all * ratings are included in the result. */ ratingFilter?: RatingFilter; /** * Required. Place type filters. */ typeFilter?: TypeFilter; } /** * An object that represents a latitude/longitude pair. This is expressed as a * pair of doubles to represent degrees latitude and degrees longitude. Unless * specified otherwise, this object must conform to the WGS84 standard. Values * must be within normalized ranges. */ export interface LatLng { /** * The latitude in degrees. It must be in the range [-90.0, +90.0]. */ latitude?: number; /** * The longitude in degrees. It must be in the range [-180.0, +180.0]. */ longitude?: number; } /** * Location filters. Specifies the area of interest for the insight. */ export interface LocationFilter { /** * Area as a circle. */ circle?: Circle; /** * Custom area specified by a polygon. */ customArea?: CustomArea; /** * Area as region. */ region?: Region; } /** * Holds information about a place */ export interface PlaceInsight { /** * The unique identifier of the place. This resource name can be used to * retrieve details about the place using the [Places * API](https://developers.google.com/maps/documentation/places/web-service/reference/rest/v1/places/get). */ place?: string; } /** * A polygon is represented by a series of connected coordinates in an * counterclockwise ordered sequence. The coordinates form a closed loop and * define a filled region. The first and last coordinates are equivalent, and * they must contain identical values. The format is a simplified version of * GeoJSON polygons (we only support one counterclockwise exterior ring). */ export interface Polygon { /** * Optional. The coordinates that define the polygon. */ coordinates?: LatLng[]; } /** * Average user rating filters. */ export interface RatingFilter { /** * Optional. Restricts results to places whose average user rating is * strictly less than or equal to max_rating. Values must be between 1.0 and * 5.0. */ maxRating?: number; /** * Optional. Restricts results to places whose average user rating is greater * than or equal to min_rating. Values must be between 1.0 and 5.0. */ minRating?: number; } /** * A region is a geographic boundary such as: cities, postal codes, counties, * states, etc. */ export interface Region { /** * The unique identifier of a specific geographic region. */ place?: string; } /** * Place type filters. Only Place types from [Table * a](https://developers.google.com/maps/documentation/places/web-service/place-types#table-a) * are supported. A place can only have a single primary type associated with * it. For example, the primary type might be "mexican_restaurant" or * "steak_house". Use included_primary_types and excluded_primary_types to * filter the results on a place's primary type. A place can also have multiple * type values associated with it. For example a restaurant might have the * following types: "seafood_restaurant", "restaurant", "food", * "point_of_interest", "establishment". Use included_types and excluded_types * to filter the results on the list of types associated with a place. If a * search is specified with multiple type restrictions, only places that satisfy * all of the restrictions are returned. For example, if you specify * {"included_types": ["restaurant"], "excluded_primary_types": * ["steak_house"]}, the returned places provide "restaurant" related services * but do not operate primarily as a "steak_house". If there are any conflicting * types, i.e. a type appears in both included_types and excluded_types types or * included_primary_types and excluded_primary_types, an INVALID_ARGUMENT error * is returned. One of included_types or included_primary_types must be set. */ export interface TypeFilter { /** * Optional. Excluded primary Place types. */ excludedPrimaryTypes?: string[]; /** * Optional. Excluded Place types. */ excludedTypes?: string[]; /** * Optional. Included primary Place types. */ includedPrimaryTypes?: string[]; /** * Optional. Included Place types. */ includedTypes?: string[]; }