Skip to content

Commit

Permalink
Merge dec1eae into b11ccff
Browse files Browse the repository at this point in the history
  • Loading branch information
aydrian committed Sep 6, 2016
2 parents b11ccff + dec1eae commit 6228826
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 319 deletions.
57 changes: 14 additions & 43 deletions docs/resources/relayWebhooks.md
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([callback])**<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[, callback])**<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[, callback])**<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[, callback])**<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[, callback])**<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).
34 changes: 34 additions & 0 deletions examples/relayWebhooks/create.js
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);
}
});
19 changes: 0 additions & 19 deletions examples/relayWebhooks/create_relayWebhook.js

This file was deleted.

27 changes: 27 additions & 0 deletions examples/relayWebhooks/delete.js
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);
}
});
15 changes: 0 additions & 15 deletions examples/relayWebhooks/delete_relayWebhook.js

This file was deleted.

15 changes: 0 additions & 15 deletions examples/relayWebhooks/find_relayWebhook.js

This file was deleted.

27 changes: 27 additions & 0 deletions examples/relayWebhooks/get.js
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);
}
});
14 changes: 0 additions & 14 deletions examples/relayWebhooks/get_all_relayWebhooks.js

This file was deleted.

27 changes: 27 additions & 0 deletions examples/relayWebhooks/list.js
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);
}
});
30 changes: 30 additions & 0 deletions examples/relayWebhooks/update.js
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);
}
});
18 changes: 0 additions & 18 deletions examples/relayWebhooks/update_relayWebhook.js

This file was deleted.

Loading

0 comments on commit 6228826

Please sign in to comment.