-
Notifications
You must be signed in to change notification settings - Fork 41
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
Refactored relay webhooks library #171
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
09deb42
Updated relayWebhooks lib and tests
aydrian 67577a7
Updated relayWebhooks doc and examples
aydrian c387b4c
updated tests for payloads and cloneDeep
aydrian dec1eae
Swapped in new verbs, added jsdoc, updated tests
aydrian 1614d3c
removed callback from doc
aydrian 317800a
updated example link on doc
aydrian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,26 @@ | ||
# Relay Webhooks | ||
|
||
This library provides easy access to the [Relay Webhooks](https://www.sparkpost.com/api#/reference/relay-webhooks/) Resource. | ||
This library provides easy access to the [Relay Webhooks](https://developers.sparkpost.com/api/relay-webhooks) Resource. | ||
|
||
*Note: All methods return promises and accept an optional last argument callback. [Read about how we handle callbacks and promises](/docs/async.md).* | ||
|
||
## Methods | ||
* **all(options, callback)** | ||
* **list()**<br /> | ||
List all relay webhooks. | ||
* `callback` - executed after task is completed. **required** | ||
* standard `callback(err, data)` | ||
* `err` - any error that occurred | ||
* `data` - full response from request client | ||
* **find(webhookId, callback)** | ||
Retrieve details about a specified relay webhook by its id | ||
* `webhookId` - the id of the relay webhook you want to look up **required** | ||
* `callback` - see all function | ||
* **create(options, callback)** | ||
* **get(id)**<br /> | ||
Get details about a specified relay webhook by its id | ||
* `id` - the id of the relay webhook you want to look up **required** | ||
* **create(webhook)**<br /> | ||
Create a new relay webhook | ||
* `options.target` - url of the target to which to POST relay batches **required** | ||
* `options.domain` - inbound domain associated with this webhook **required** | ||
* `options.name` - user-friendly name | ||
* `options.authToken` - authentication token to present in the X-MessageSystems-Webhook-Token header of POST requests to target | ||
* `options.protocol` - inbound messaging protocol associated with this webhook | ||
* `callback` - see all function | ||
* **update(options, callback)** | ||
* `webhook` - an object of [relay webhook attributes](https://developers.sparkpost.com/api/relay-webhooks#header-relay-webhooks-object-properties) **required** | ||
* **update(id, webhook)**<br /> | ||
Update an existing relay webhook | ||
* `options.webhookId` - the id of the relay webhook you want to update **required** | ||
* `options.target` - url of the target to which to POST relay batches | ||
* `options.domain` - inbound domain associated with this webhook | ||
* `options.name` - user-friendly name | ||
* `options.authToken` - authentication token to present in the X-MessageSystems-Webhook-Token header of POST requests to target | ||
* `options.protocol` - inbound messaging protocol associated with this webhook | ||
* `callback` - see all function | ||
* **delete(webhookId, callback)** | ||
* `id` - the id of the relay webhook you want to update **required** | ||
* `webhook` - an object of [relay webhook attributes](https://developers.sparkpost.com/api/relay-webhooks#header-relay-webhooks-object-properties) **required** | ||
* **delete(id)**<br /> | ||
Delete an existing relay webhook | ||
* `webhookId` - the id of the webhook you want to delete **required** | ||
* `callback` - see all function | ||
* `id` - the id of the relay webhook you want to delete **required** | ||
|
||
## Examples | ||
|
||
```js | ||
var SparkPost = require('sparkpost'); | ||
var client = new SparkPost('YOUR_API_KEY'); | ||
|
||
client.relayWebhooks.all(function(err, data) { | ||
if(err) { | ||
console.log(err); | ||
return; | ||
} | ||
|
||
console.log(data); | ||
}); | ||
|
||
``` | ||
|
||
Check out all the examples provided [here](/examples/relayWebhooks). | ||
Visit our examples section to see all of [our relay webhook resource examples](/examples/relayWebhooks). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
var key = 'YOURAPIKEY' | ||
, SparkPost = require('sparkpost') | ||
, client = new SparkPost(key) | ||
, webhook = { | ||
name: 'Test Relay Webhook', | ||
target: 'http://client.test.com/test-webhook', | ||
match: { | ||
domain: 'inbound.example.com' | ||
} | ||
}; | ||
|
||
// Promise | ||
client.relayWebhooks.create(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); | ||
}); | ||
|
||
// Callback | ||
client.relayWebhooks.create(webhook, function(err, data) { | ||
if (err) { | ||
console.log('Whoops! Something went wrong'); | ||
console.log(err); | ||
} else { | ||
console.log('Congrats you can use our client library!'); | ||
console.log(data); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
var key = 'YOURAPIKEY' | ||
, SparkPost = require('sparkpost') | ||
, client = new SparkPost(key); | ||
|
||
// 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.delete('123456789', function(err, data) { | ||
if (err) { | ||
console.log('Whoops! Something went wrong'); | ||
console.log(err); | ||
} else { | ||
console.log('Congrats you can use our client library!'); | ||
console.log(data); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
var key = 'YOURAPIKEY' | ||
, SparkPost = require('sparkpost') | ||
, client = new SparkPost(key); | ||
|
||
// 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); | ||
}); | ||
|
||
// Callback | ||
client.relayWebhooks.get('123456789', function(err, data) { | ||
if (err) { | ||
console.log('Whoops! Something went wrong'); | ||
console.log(err); | ||
} else { | ||
console.log('Congrats you can use our client library!'); | ||
console.log(data); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
var key = 'YOURAPIKEY' | ||
, SparkPost = require('sparkpost') | ||
, client = new SparkPost(key); | ||
|
||
// 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.list(function(err, data) { | ||
if (err) { | ||
console.log('Whoops! Something went wrong'); | ||
console.log(err); | ||
} else { | ||
console.log('Congrats you can use our client library!'); | ||
console.log(data); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
var key = 'YOURAPIKEY' | ||
, SparkPost = require('sparkpost') | ||
, client = new SparkPost(key) | ||
, webhook = { | ||
target: 'http://client.test.com/test-webhook' | ||
}; | ||
|
||
// Promise | ||
client.relayWebhooks.update('123456789', 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); | ||
}); | ||
|
||
// Callback | ||
client.relayWebhooks.update('123456789', webhook, function(err, data) { | ||
if (err) { | ||
console.log('Whoops! Something went wrong'); | ||
console.log(err); | ||
} else { | ||
console.log('Congrats you can use our client library!'); | ||
console.log(data); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is match required for updates?