Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Adding topics to getRandom #181

Merged
merged 3 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>_ | Optional |
| **`collectionIds`** | _Array<string>_ | Optional |
| **`topicIds`** | _Array<string>_ | Optional |
| **`count`** | _string_ | Optional |

**Example**
Expand All @@ -399,6 +400,7 @@ unsplash.photos.getRandom({
});
unsplash.photos.getRandom({
collectionIds: ['abc123'],
topicIds: ['def456'],
featured: true,
username: 'naoufal',
query: 'dog',
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions src/methods/photos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
/**
Expand Down