Skip to content

Commit

Permalink
add DELETE /webhooks/{id} endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostrider-05 committed Oct 18, 2024
1 parent 5a5cb50 commit 34a12a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/rest/v2/oauth2/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export const DefaultRestOptions: RESTOptions = {
}

export enum RequestMethod {
Delete = 'DELETE',
Get = 'GET',
Patch = 'PATCH',
Post = 'POST',
Expand Down Expand Up @@ -346,6 +347,10 @@ export class RestClient {
clearInterval(this.requestInterval)
}

public async delete<T> (path: string, options?: RequestOptions) {
return await this.request<T>({ ...options, method: RequestMethod.Delete, path })
}

public async get<T> (path: string, options?: RequestOptions) {
return await this.request<T>({ ...options, method: RequestMethod.Get, path })
}
Expand Down
1 change: 1 addition & 0 deletions src/rest/v2/oauth2/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const Oauth2Routes = {
* Routes for:
*
* - PATCH `/webhooks/{webhookId}`
* - DELETE `/webhooks/{webhookId}`
* @param webhookId The id of the webhook
*/
webhook (webhookId: string) {
Expand Down
18 changes: 17 additions & 1 deletion src/rest/v2/webhooks/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type Webhook,
} from '../../../schemas/v2'

import { Oauth2Routes } from '../oauth2'
import { Oauth2Routes, RequestMethod } from '../oauth2'
import { createQuery, type BasePatreonQueryType, type GetResponsePayload } from '../query'

import type { Oauth2RouteOptions } from '../clients/baseMethods'
Expand Down Expand Up @@ -139,6 +139,22 @@ export class WebhookClient {
}) as unknown as APIPostWebhookResponse | undefined
}

/**
* Delete a webhook created by this client
* @param webhookId The webhook id
* @param options Request options
* @returns the webhooks managed by this client
*/
public async deleteWebhook(
webhookId: string,
options?: Oauth2WebhookRouteOptions,
): Promise<void> {
await this.oauth.fetch(Oauth2Routes.webhook(webhookId), createQuery(new URLSearchParams()), {
...(options ?? {}),
method: RequestMethod.Delete,
})
}

/**
* Check if the webhook should be unpaused as events have failed to send.
*
Expand Down

0 comments on commit 34a12a6

Please sign in to comment.