-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated templates lib and tests * Updated templates doc and examples * updated tests for payloads and cloneDeep * template refactoring for standardized verbs * Added optional options object to template update * eslint fixes * jsdoc updates * fixed webhook imports
- Loading branch information
Showing
20 changed files
with
481 additions
and
358 deletions.
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,49 +1,34 @@ | ||
# Templates | ||
|
||
This library provides easy access to the [Templates](https://www.sparkpost.com/api#/reference/templates/) Resource. | ||
This library provides easy access to the [Templates](https://developers.sparkpost.com/api/templates) 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(callback)** | ||
* **list()**<br /> | ||
List a summary of all templates. | ||
* `callback` - executed after task is completed. **required** | ||
* standard `callback(err, data)` | ||
* `err` - any error that occurred | ||
* `data` - full response from request client | ||
* **find(options, callback)** | ||
Retrieve details about a specified template by its id | ||
* **get(id[, options])**<br /> | ||
Get details about a specified template by its id | ||
* `options.id` - the id of the template you want to look up **required** | ||
* `options.draft` - specifies a draft or published template | ||
* `callback` - see all function | ||
* **create(options, callback)** | ||
* **create(template)**<br /> | ||
Create a new template | ||
* `options.template` - a template object **required** | ||
* `callback` - see all function | ||
* **delete(id, callback)** | ||
* `template` - an object of [template attributes](https://developers.sparkpost.com/api/templates#header-template-attributes) **required** | ||
* **update(id, template[, options])**<br /> | ||
Update an existing template | ||
* `id` - the id of the template you want to update **required** | ||
* `template` - an object of [template attributes](https://developers.sparkpost.com/api/templates#header-template-attributes) **required** | ||
* `options.update_published` - If true, directly overwrite the existing published template. If false, create a new draft. | ||
* **delete(id)**<br /> | ||
Delete an existing template | ||
* `id` - the id of the template you want to delete **required** | ||
* `callback` - see all function | ||
* **preview(options, callback)** | ||
* **preview(id[, options])**<br /> | ||
Preview the most recent version of an existing template by id | ||
* `options.id` - the id of the template you want to look up **required** | ||
* `options.data` - Object of substitution data | ||
* `id` - the id of the template you want to look up **required** | ||
* `options.substitution_data` - Object of substitution data | ||
* `options.draft` - specifies a draft or published template | ||
* `callback` - see all function | ||
|
||
## Examples | ||
|
||
```js | ||
var SparkPost = require('sparkpost'); | ||
var client = new SparkPost('YOUR_API_KEY'); | ||
|
||
client.templates.all(function(err, data) { | ||
if(err) { | ||
console.log(err); | ||
return; | ||
} | ||
|
||
console.log(data); | ||
}); | ||
|
||
``` | ||
|
||
Check out all the examples provided [here](/examples/templates). | ||
Visit our examples section to see all of [our template resource examples](/examples/templates). |
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,36 @@ | ||
'use strict'; | ||
|
||
var key = 'YOURAPIKEY' | ||
, SparkPost = require('sparkpost') | ||
, client = new SparkPost(key) | ||
, template = { | ||
id: 'TEST_ID', | ||
name: 'Test Template', | ||
content: { | ||
from: '[email protected]', | ||
subject: 'Test email template!', | ||
html: '<b>This is a test email template!</b>' | ||
} | ||
}; | ||
|
||
// Promise | ||
client.templates.create(template) | ||
.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.templates.create(template, 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.templates.delete('TEST_ID') | ||
.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.templates.delete('TEST_ID', 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.templates.get('TEST_ID') | ||
.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.templates.get('TEST_ID', 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,30 @@ | ||
'use strict'; | ||
|
||
var key = 'YOURAPIKEY' | ||
, SparkPost = require('sparkpost') | ||
, client = new SparkPost(key) | ||
, options = { | ||
draft: true | ||
}; | ||
|
||
// Promise | ||
client.templates.get('TEST_ID', options) | ||
.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.templates.get('TEST_ID', options, 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.templates.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.templates.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) | ||
, options = { | ||
id: 'TEST_ID', | ||
substitution_data: {} | ||
}; | ||
|
||
client.templates.preview(options) | ||
.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); | ||
}); | ||
|
||
// Using a callback | ||
client.templates.preview(options, 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,34 @@ | ||
'use strict'; | ||
|
||
var key = 'YOURAPIKEY' | ||
, SparkPost = require('sparkpost') | ||
, client = new SparkPost(key) | ||
, template = { | ||
content: { | ||
from: '[email protected]', | ||
subject: 'Updated Test email template!', | ||
html: '<b>This is a test email template! Updated!</b>' | ||
} | ||
}; | ||
|
||
// Promise | ||
client.templates.update('TEST_ID', template) | ||
.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.templates.update('TEST_ID', template, 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); | ||
} | ||
}); |
Oops, something went wrong.