From 440680aa827c6a09e7ea899df9f7567f24f3907b Mon Sep 17 00:00:00 2001 From: Tanishq Kancharla Date: Tue, 13 Jul 2021 22:50:40 -0400 Subject: [PATCH 1/3] Added topics to random photo query --- src/helpers/query.ts | 3 +++ src/methods/photos/index.ts | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/helpers/query.ts b/src/helpers/query.ts index 379b679..7c752b2 100644 --- a/src/helpers/query.ts +++ b/src/helpers/query.ts @@ -5,6 +5,9 @@ import { isDefined } from './typescript'; export const getCollections = (collectionIds?: string[]) => isDefined(collectionIds) ? { collections: collectionIds.join() } : {}; +export const getTopics = (topicIds?: string[]) => + isDefined(topicIds) ? { topics: topicIds.join() } : {}; + export const getFeedParams = ({ page, perPage, orderBy }: PaginationParams) => compactDefined({ per_page: perPage, diff --git a/src/methods/photos/index.ts b/src/methods/photos/index.ts index 7314464..96a3a9a 100644 --- a/src/methods/photos/index.ts +++ b/src/methods/photos/index.ts @@ -51,6 +51,16 @@ export const getStats = (() => { }); })(); +export interface RandomParams { + collectionIds?: string[]; + topicIds?: string[]; + featured?: boolean; + username?: string; + query?: string; + contentFilter?: 'low' | 'high'; + count?: number; +} + export const getRandom = (() => { const getPathname = () => `${PHOTOS_PATH_PREFIX}/random`; return makeEndpoint({ @@ -59,20 +69,15 @@ export const getRandom = (() => { ({ collectionIds, contentFilter, + topicIds, ...queryParams - }: { - collectionIds?: string[]; - featured?: boolean; - username?: string; - query?: string; - contentFilter?: 'low' | 'high'; - count?: number; - } & OrientationParam = {}) => ({ + }: RandomParams & OrientationParam = {}) => ({ pathname: getPathname(), query: compactDefined({ ...queryParams, content_filter: contentFilter, ...Query.getCollections(collectionIds), + ...Query.getTopics(topicIds), }), headers: { /** From d788e47b7163e4f63000b8fccf526c27387882d0 Mon Sep 17 00:00:00 2001 From: Tanishq Kancharla Date: Tue, 13 Jul 2021 22:54:03 -0400 Subject: [PATCH 2/3] Added Orientation Params to Random Params --- src/methods/photos/index.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/methods/photos/index.ts b/src/methods/photos/index.ts index 96a3a9a..d1d79df 100644 --- a/src/methods/photos/index.ts +++ b/src/methods/photos/index.ts @@ -51,7 +51,7 @@ export const getStats = (() => { }); })(); -export interface RandomParams { +export type RandomParams = { collectionIds?: string[]; topicIds?: string[]; featured?: boolean; @@ -59,19 +59,14 @@ export interface RandomParams { query?: string; contentFilter?: 'low' | 'high'; count?: number; -} +} & OrientationParam; export const getRandom = (() => { const getPathname = () => `${PHOTOS_PATH_PREFIX}/random`; return makeEndpoint({ getPathname, handleRequest: createRequestHandler( - ({ - collectionIds, - contentFilter, - topicIds, - ...queryParams - }: RandomParams & OrientationParam = {}) => ({ + ({ collectionIds, contentFilter, topicIds, ...queryParams }: RandomParams = {}) => ({ pathname: getPathname(), query: compactDefined({ ...queryParams, From 4e89783e11564b25063bcf18163bd05ac32c76c8 Mon Sep 17 00:00:00 2001 From: Tanishq Kancharla Date: Wed, 14 Jul 2021 22:15:50 -0400 Subject: [PATCH 3/3] Updated docs --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4b4160..f59fbbf 100644 --- a/README.md +++ b/README.md @@ -387,7 +387,8 @@ Retrieve a single random photo, given optional filters. [See endpoint docs 🚀] | **`query`** | _string_ | Optional | | **`username`** | _string_ | Optional | | **`featured`** | _boolean_ | Optional | -| **`collectionIds`** | _Array_ | Optional | +| **`collectionIds`** | _Array_ | Optional | +| **`topicIds`** | _Array_ | Optional | | **`count`** | _string_ | Optional | **Example** @@ -399,6 +400,7 @@ unsplash.photos.getRandom({ }); unsplash.photos.getRandom({ collectionIds: ['abc123'], + topicIds: ['def456'], featured: true, username: 'naoufal', query: 'dog',