Repository: googlemaps/google-maps-services-js (ts)

Issue:
Geocode to accept param "place_id"
The Geocoding endpoint does support querying by placeId.

Feature request: Update library to allow usage of `place_id` as a param.

current support exists only for the following params `address`, `bounds`, `language`, `region`, `components`.

Pull request:
feat: add place_id to geocode
Add place_id param to GeocodeRequest.

Fixes #408  🦕


Patch:
diff --git a/src/geocode/geocode.ts b/src/geocode/geocode.ts
index 23b9b1e59..55464bf41 100644
--- a/src/geocode/geocode.ts
+++ b/src/geocode/geocode.ts
@@ -40,6 +40,10 @@ export interface GeocodeComponents {
 
 export interface GeocodeRequest extends Partial<AxiosRequestConfig> {
   params: {
+    /**
+     * The place_id that you want to geocode. You can retrieve this information from Places API for example.
+     */
+    place_id?: string;
     /**
      * The street address that you want to geocode, in the format used by the national postal service of the country concerned.
      * Additional address elements such as business names and unit, suite or floor numbers should be avoided.
diff --git a/src/places/photo.ts b/src/places/photo.ts
index 09d5cbd3b..70474cd1e 100644
--- a/src/places/photo.ts
+++ b/src/places/photo.ts
@@ -40,6 +40,7 @@ export interface PlacePhotoRequest extends Partial<AxiosRequestConfig> {
      */
     maxheight?: number;
     } & RequestParams;
+  responseType: 'arraybuffer' | 'blob' | 'stream';
 }
 
 /**
@@ -59,13 +60,18 @@ export interface PlacePhotoResponse extends AxiosResponse {}
 export const defaultUrl = "https://maps.googleapis.com/maps/api/place/photo";
 
 export function placePhoto(
-  { params, method = "get", url = defaultUrl, ...config }: PlacePhotoRequest,
+  { params, method = "get", url = defaultUrl, responseType, ...config }: PlacePhotoRequest,
   axiosInstance: AxiosInstance = defaultAxiosInstance
 ): Promise<PlacePhotoResponse> {
+  if (!responseType) {
+    responseType = 'arraybuffer'
+  }
+
   return axiosInstance({
     params,
     method,
     url,
+    responseType,
     ...config
   }) as Promise<PlacePhotoResponse>;
 }


Test patch:
diff --git a/e2e/places/photo.test.ts b/e2e/places/photo.test.ts
index 56ec4ed62..1fddd2c45 100644
--- a/e2e/places/photo.test.ts
+++ b/e2e/places/photo.test.ts
@@ -15,7 +15,6 @@
  */
 
 import { placePhoto } from "../../src/places/photo";
-import { PlaceInputType } from "../../src/common";
 
 test("photo should return correct result", async () => {
   const params = {
@@ -23,9 +22,9 @@ test("photo should return correct result", async () => {
       "CnRtAAAATLZNl354RwP_9UKbQ_5Psy40texXePv4oAlgP4qNEkdIrkyse7rPXYGd9D_Uj1rVsQdWT4oRz4QrYAJNpFX7rzqqMlZw2h2E2y5IKMUZ7ouD_SlcHxYq1yL4KbKUv3qtWgTK0A6QbGh87GB3sscrHRIQiG2RrmU_jF4tENr9wGS_YxoUSSDrYjWmrNfeEHSGSc3FyhNLlBU",
     maxwidth: 100,
     maxheight: 100,
-    key: process.env.GOOGLE_MAPS_API_KEY
+    key: process.env.GOOGLE_MAPS_API_KEY,
   };
-  const r = await placePhoto({ params: params });
+  const r = await placePhoto({ params: params, responseType: "arraybuffer" });
 
   expect(r.status).toEqual(200);
   expect(r.headers["content-type"]).toEqual("image/jpeg");
diff --git a/src/places/photo.test.ts b/src/places/photo.test.ts
index 682318529..a79a535b2 100644
--- a/src/places/photo.test.ts
+++ b/src/places/photo.test.ts
@@ -15,7 +15,7 @@
  */
 
 import axios from "axios";
-import { placePhoto, defaultUrl } from "./photo";
+import { placePhoto, defaultUrl, PlacePhotoRequest } from "./photo";
 
 jest.mock("axios");
 
@@ -27,13 +27,27 @@ afterEach(() => {
 
 test("photo should call axios correctly", () => {
   const params = { photoreference: "notaphotoreference", key: "foo" };
+  const responseType = 'arraybuffer';
+  placePhoto({ params, responseType }, mockedAxios);
 
-  placePhoto({ params: params }, mockedAxios);
+  expect(mockedAxios).toHaveBeenCalledTimes(1);
+  expect(mockedAxios).toHaveBeenCalledWith({
+    method: "get",
+    params,
+    responseType,
+    url: defaultUrl,
+  });
+});
+
+test("photo should set default responseType", () => {
+  const params = { photoreference: "notaphotoreference", key: "foo" };
+  placePhoto({ params } as PlacePhotoRequest, mockedAxios);
 
   expect(mockedAxios).toHaveBeenCalledTimes(1);
   expect(mockedAxios).toHaveBeenCalledWith({
     method: "get",
-    params: params,
-    url: defaultUrl
+    params,
+    responseType: "arraybuffer",
+    url: defaultUrl,
   });
 });