Skip to content
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 6 commits into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 15 additions & 44 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()**<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).
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'
Copy link

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?

};

// 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