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', 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..d1d79df 100644 --- a/src/methods/photos/index.ts +++ b/src/methods/photos/index.ts @@ -51,28 +51,28 @@ export const getStats = (() => { }); })(); +export type RandomParams = { + collectionIds?: string[]; + topicIds?: string[]; + featured?: boolean; + username?: string; + query?: string; + contentFilter?: 'low' | 'high'; + count?: number; +} & OrientationParam; + export const getRandom = (() => { const getPathname = () => `${PHOTOS_PATH_PREFIX}/random`; return makeEndpoint({ getPathname, handleRequest: createRequestHandler( - ({ - collectionIds, - contentFilter, - ...queryParams - }: { - collectionIds?: string[]; - featured?: boolean; - username?: string; - query?: string; - contentFilter?: 'low' | 'high'; - count?: number; - } & OrientationParam = {}) => ({ + ({ collectionIds, contentFilter, topicIds, ...queryParams }: RandomParams = {}) => ({ pathname: getPathname(), query: compactDefined({ ...queryParams, content_filter: contentFilter, ...Query.getCollections(collectionIds), + ...Query.getTopics(topicIds), }), headers: { /**