From 854765bce388216773e69f0a93d48aa1ea8ca44d Mon Sep 17 00:00:00 2001 From: Akinmade Bond Date: Sat, 18 Mar 2017 14:08:05 +0100 Subject: [PATCH] update relayWebhooks --- sparkpost/index.d.ts | 37 ++++++++++++++++-- sparkpost/sparkpost-tests.ts | 74 ++++++++++++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 8 deletions(-) diff --git a/sparkpost/index.d.ts b/sparkpost/index.d.ts index a47d1504bd..9e380f4476 100644 --- a/sparkpost/index.d.ts +++ b/sparkpost/index.d.ts @@ -175,31 +175,60 @@ declare class SparkPost { * List all your relay webhooks. * @param callback The request callback with RelayWebhook results array */ - all(callback: SparkPost.ResultsCallback): void; + list(callback: SparkPost.ResultsCallback): void; + /** + * List all your relay webhooks. + * @returns Promise The RelayWebhook results array + */ + list(): SparkPost.ResultsPromise; /** * Delete a relay webhook by specifying the webhook ID in the URI path. * @param relayWebhookId The webhook id * @param callback The request callback with RelayWebhook results */ - find(relayWebhookId: string, callback: SparkPost.ResultsCallback): void; + get(relayWebhookId: string, callback: SparkPost.ResultsCallback): void; + /** + * Delete a relay webhook by specifying the webhook ID in the URI path. + * @param relayWebhookId The webhook id + * @returns Promise The RelayWebhook results + */ + get(relayWebhookId: string): SparkPost.ResultsPromise; /** * Create a relay webhook by providing a relay webhooks object as the POST request body. * @param options The create options * @param callback The request callback with webhook id results */ create(options: SparkPost.RelayWebhook, callback: SparkPost.ResultsCallback<{ id: string }>): void; + /** + * Create a relay webhook by providing a relay webhooks object as the POST request body. + * @param options The create options + * @returns Promise The webhook id results + */ + create(options: SparkPost.RelayWebhook): SparkPost.ResultsPromise<{ id: string }>; /** * Update a relay webhook by specifying the webhook ID in the URI path. * @param options The update options * @param callback The request callback with webhook id results */ - update(options: SparkPost.UpdateRelayWebhook & { relayWebhookId: string }, callback: SparkPost.ResultsCallback<{ id: string }>): void; + update(id: string, options: SparkPost.UpdateRelayWebhook, callback: SparkPost.ResultsCallback<{ id: string }>): void; + /** + * Update a relay webhook by specifying the webhook ID in the URI path. + * @param options The update options + * @returns Promise The webhook id results + */ + update(id: string, options: SparkPost.UpdateRelayWebhook): SparkPost.ResultsPromise<{ id: string }>; /** * Delete a relay webhook by specifying the webhook ID in the URI path. * @param relayWebhookId The webhook id * @param callback The request callback */ delete(relayWebhookId: string, callback: SparkPost.Callback): void; + /** + * Delete a relay webhook by specifying the webhook ID in the URI path. + * @param relayWebhookId The webhook id + * @returns Promise void + */ + delete(relayWebhookId: string): Promise; }; sendingDomains: { /** @@ -688,7 +717,7 @@ declare namespace SparkPost { /** User-friendly name no example: Inbound Customer Replies */ name?: string; /** URL of the target to which to POST relay batches */ - target?: string; + target: string; /** Authentication token to present in the X-MessageSystems-Webhook-Token header of POST requests to target */ auth_token?: string; /** Restrict which inbound messages will be relayed to the target */ diff --git a/sparkpost/sparkpost-tests.ts b/sparkpost/sparkpost-tests.ts index e7e9145cb8..667b5c89aa 100644 --- a/sparkpost/sparkpost-tests.ts +++ b/sparkpost/sparkpost-tests.ts @@ -380,6 +380,7 @@ client.recipientLists.update('EXISTING_TEST_ID', { console.log(err); }); +// Callback client.relayWebhooks.create({ name: "Test Relay Webhook", target: "http://client.test.com/test-webhook", @@ -395,6 +396,24 @@ client.relayWebhooks.create({ } }); +// Promise +client.relayWebhooks.create({ + name: 'Test Relay Webhook', + target: 'http://client.test.com/test-webhook', + match: { + domain: 'inbound.example.com' + } +}) + .then(data => { + console.log('Congrats you can use our client library!'); + console.log(data); + }) + .catch(err => { + console.log('Whoops! Something went wrong'); + console.log(err); +}); + +// Callback client.relayWebhooks.delete("123456789", function(err, res) { if (err) { console.log(err); @@ -404,7 +423,19 @@ client.relayWebhooks.delete("123456789", function(err, res) { } }); -client.relayWebhooks.find("123456789", function(err, res) { +// Promise +client.relayWebhooks.delete('123456789') + .then(data => { + console.log('Congrats you can use our client library!'); + console.log(data); + }) + .catch(err => { + console.log('Whoops! Something went wrong'); + console.log(err); +}); + +// Callback +client.relayWebhooks.get('123456789', function(err, res) { if (err) { console.log(err); } else { @@ -413,7 +444,18 @@ client.relayWebhooks.find("123456789", function(err, res) { } }); -client.relayWebhooks.all(function(err, res) { +// Promise +client.relayWebhooks.get('123456789') + .then(data => { + console.log('Congrats you can use our client library!'); + console.log(data); + }) + .catch(err => { + console.log('Whoops! Something went wrong'); + console.log(err); +}); + +client.relayWebhooks.list(function(err, res) { if (err) { console.log(err); } else { @@ -422,8 +464,19 @@ client.relayWebhooks.all(function(err, res) { } }); -client.relayWebhooks.update({ - relayWebhookId: "123456789", +// Promise +client.relayWebhooks.list() + .then(data => { + console.log('Congrats you can use our client library!'); + console.log(data); + }) + .catch(err => { + console.log('Whoops! Something went wrong'); + console.log(err); +}); + +// Callback +client.relayWebhooks.update('123456789', { target: "http://client.test.com/test-webhook" }, function(err, res) { if (err) { @@ -434,6 +487,19 @@ client.relayWebhooks.update({ } }); +// Promise +client.relayWebhooks.update('123456789', { + target: 'http://client.test.com/test-webhook' +}) + .then(data => { + console.log('Congrats you can use our client library!'); + console.log(data); + }) + .catch(err => { + console.log('Whoops! Something went wrong'); + console.log(err); +}); + client.sendingDomains.create({ domain: "example1.com", dkim: {