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

Commit

Permalink
Merge pull request #181 from moonrise-tk/master
Browse files Browse the repository at this point in the history
Adding topics to getRandom
  • Loading branch information
OliverJAsh authored Jul 15, 2021
2 parents d53654a + 4e89783 commit 23f561f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
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

0 comments on commit 23f561f

Please sign in to comment.