Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added DELETE endpoint (https://dev.twitch.tv/docs/api/moderation/#del… #342

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Api/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ describe('Api', () => {
expect(actualOpts).toMatchObject({ method: 'put' })
})

test('delete should call fetch with method=delete', async () => {
const api = new Api(options)

const endpoint = 'ENDPOINT'
await api.delete(endpoint, fetchOptions)

const [, actualOpts] = fetchUtil.mock.calls[0]

expect(actualOpts).toMatchObject({ method: 'delete' })
})

test('should throw on failure', async () => {
expect.assertions(2)

Expand Down
9 changes: 8 additions & 1 deletion src/Api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ApiOptions, ApiReadyStates, ApiFetchOptions } from './api-types'
*
* By default, the API client makes requests to the
* [Helix API](https://dev.twitch.tv/docs/api), and exposes [[Api.get]],
* [[Api.post]] and [[Api.put]] methods. Query and body parameters are provided
* [[Api.post]], [[Api.put]] and [[Api.delete]] methods. Query and body parameters are provided
* via `options.search` and `options.body` properties, respectively.
*
* ### Examples
Expand Down Expand Up @@ -154,6 +154,13 @@ class Api {
return this._handleFetch<T>(endpoint, { ...options, method: 'put' })
}

/**
* DELETE endpoint.
*/
delete<T = any>(endpoint: string, options?: ApiFetchOptions) {
return this._handleFetch<T>(endpoint, { ...options, method: 'delete' })
}

private _getAuthenticationHeaders(): RequestInit['headers'] {
const { clientId, token } = this._options

Expand Down