Skip to content
This repository has been archived by the owner on Dec 30, 2021. It is now read-only.

Commit

Permalink
feat: add favoriteImage
Browse files Browse the repository at this point in the history
  • Loading branch information
kaimallea committed Mar 28, 2021
1 parent 5a767c7 commit 251a970
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,13 @@ client.updateImage([
},
]);
```

Favorite an image:

```ts
import { ImgurClient } from 'imgur';

const client = new ImgurClient({ accessToken: process.env.ACCESS_TOKEN });

client.favoriteImage('someImageHash');
```
5 changes: 5 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import got, { ExtendOptions, Got } from 'got';
import { getAuthorizationHeader, Credentials } from './helpers';
import {
deleteImage,
favoriteImage,
getImage,
upload,
updateImage,
Expand Down Expand Up @@ -54,6 +55,10 @@ export class ImgurClient extends EventEmitter {
return deleteImage(this, imageHash);
}

favoriteImage(imageHash: string) {
return favoriteImage(this, imageHash);
}

async getImage(imageHash: string) {
return getImage(this, imageHash);
}
Expand Down
15 changes: 15 additions & 0 deletions src/image/favoriteImage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ImgurClient } from '../client';
import { favoriteImage } from './favoriteImage';

test('favorite works successfully', async () => {
const accessToken = 'abc123';
const client = new ImgurClient({ accessToken });
const response = await favoriteImage(client, 'CEddrgP');
expect(response).toMatchInlineSnapshot(`
Object {
"data": "favorited",
"status": 200,
"success": true,
}
`);
});
15 changes: 15 additions & 0 deletions src/image/favoriteImage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ImgurClient } from '../client';
import { IMAGE_ENDPOINT } from '../helpers';

type FavoriteResponse = {
data: 'favorited';
success: true;
status: 200;
};

export async function favoriteImage(client: ImgurClient, imageHash: string) {
const url = `${IMAGE_ENDPOINT}/${imageHash}/favorite`;
return (await client
.request(url, { method: 'POST' })
.json()) as FavoriteResponse;
}
1 change: 1 addition & 0 deletions src/image/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './deleteImage';
export * from './favoriteImage';
export * from './getImage';
export * from './updateImage';
export * from './upload';

0 comments on commit 251a970

Please sign in to comment.