Skip to content

Commit

Permalink
chore: add examples to docs for webhooks apis (#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruuuuuuuce authored Dec 8, 2023
1 parent a6ae541 commit 0115ae6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 34 deletions.
45 changes: 45 additions & 0 deletions examples/nodejs/cache/doc-example-files/doc-examples-js-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ import {
LeaderboardOrder,
LeaderboardRemoveElements,
LeaderboardUpsert,
ListWebhooks,
DeleteWebhook,
PutWebhook,
} from '@gomomento/sdk';

function retrieveApiKeyFromYourSecretsManager(): string {
Expand Down Expand Up @@ -1042,6 +1045,43 @@ async function example_API_TopicSubscribe(topicClient: TopicClient) {
}
}

async function example_API_ListWebhooks(topicClient: TopicClient) {
const result = await topicClient.listWebhooks('test-cache');
if (result instanceof ListWebhooks.Success) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
console.log(`listed webhooks: ${result.getWebhooks()}`);
} else if (result instanceof ListWebhooks.Error) {
throw new Error(
`An error occurred while attempting to list webhooks for cache 'test-cache': ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_DeleteWebhook(topicClient: TopicClient) {
const result = await topicClient.deleteWebhook('test-cache', 'a webhook');
if (result instanceof DeleteWebhook.Success) {
console.log('successfully deleted webhook');
} else if (result instanceof ListWebhooks.Error) {
throw new Error(
`An error occurred while attempting to delete webhook 'a webhook' inside of cache 'test-cache': ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_PutWebhook(topicClient: TopicClient) {
const result = await topicClient.putWebhook('test-cache', 'examples webhook', {
topicName: 'a topic',
destination: 'https://www.thisisawebhookurl.com/v1/webhook',
});
if (result instanceof PutWebhook.Success) {
console.log('successfully created webhook');
} else if (result instanceof PutWebhook.Error) {
throw new Error(
`An error occurred while attempting to create a webhook 'examples webhook' inside of cache 'test-cache': ${result.errorCode()}: ${result.toString()}`
);
}
}

function example_API_InstantiateLeaderboardClient() {
new PreviewLeaderboardClient({
configuration: LeaderboardConfigurations.Laptop.v1(),
Expand Down Expand Up @@ -1368,6 +1408,11 @@ async function main() {
await example_API_TopicPublish(topicClient);
await example_API_TopicSubscribe(topicClient);

// Webhooks
await example_API_ListWebhooks(topicClient);
await example_API_DeleteWebhook(topicClient);
await example_API_PutWebhook(topicClient);

example_API_InstantiateLeaderboardClient();
const leaderboardClient = new PreviewLeaderboardClient({
configuration: LeaderboardConfigurations.Laptop.v1(),
Expand Down
66 changes: 33 additions & 33 deletions examples/nodejs/cache/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/nodejs/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"typescript": "4.4.3"
},
"dependencies": {
"@gomomento/sdk": "^1.45.7"
"@gomomento/sdk": "1.53.0"
},
"engines": {
"node": ">=10.4.0"
Expand Down

0 comments on commit 0115ae6

Please sign in to comment.