Skip to content

Commit

Permalink
Standardized action verbs on remaining libraries (#184)
Browse files Browse the repository at this point in the history
* Removed toApiFormat

* Updated subaccount examples

* Refactored transmissions library

* Refactered Message Events resource

* fixes based on feedback

* Added back code to handle arrays for messageEvents

* Fixed messageEvents examples
  • Loading branch information
aydrian committed Nov 1, 2016
1 parent 21bd332 commit 6557288
Show file tree
Hide file tree
Showing 26 changed files with 243 additions and 230 deletions.
50 changes: 7 additions & 43 deletions docs/resources/messageEvents.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
# Message Events

This library provides easy access to the [Message Events](https://www.sparkpost.com/api#/reference/message-events/) resource.
This library provides easy access to the [Message Events](https://developers.sparkpost.com/api/message-events) 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
* **search(params, callback)**
* **search([params, callback])**<br />
Search for message events using the given parameters (NOTE: all params are optional):
* `params.bounce_classes` - list of [bounce classes](https://support.sparkpost.com/customer/portal/articles/1929896)
* `params.campaign_ids` - campaign IDs
* `params.events` - event types
* `params.friendly_froms` - 'friendly' from addressess
* `params.from` - time lower bound (see below for date/time format details)
* `params.message_ids` - message IDs
* `params.page` - results page number
* `params.per_page` - number of results per page
* `params.reason` - bounce reason with '%' wildcards (see below for example)
* `params.recipients` - recipient email addresses
* `params.template_ids` - template IDs
* `params.timezone` - timezone for `from` and `to` params ([reference](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones))
* `params.to` - time upper bound (see below for date/time format details)
* `params.transmission_ids` - transmission IDs
* `params` - a hash of [Message Events URI Parameters](https://developers.sparkpost.com/api/message-events.html#message-events-message-events-get)

## Date/Time Parameter Format

The `from` and `to` search parameters accept datestamps of the form:
The `from` and `to` search parameters accept date stamps of the form:

`YYYY-MM-DDTHH:MM`

Expand All @@ -32,29 +21,4 @@ Note: timestamps are expressed in the timezone specified by the `timezone` param

## Examples

This example code retrieves up to 5 'invalid recipient' bounce events from the first 2 days of 2016.

```js
var SparkPost = require('sparkpost');
var client = new SparkPost('YOUR_API_KEY');
var searchParams = {
from: '2016-01-01T00:00',
to: '2016-01-02T23:59',
page: 1,
per_page: 5,
events: ['bounce', 'out_of_band'],
bounce_classes: [10]
};

client.messageEvents.search(searchParams, function(err, res) {
if(err) {
console.log(err);
return;
}

console.log(data);
});

```

Check out all the examples provided [here](/examples/messageEvents).
Visit our examples section to see all of [our message events resource examples](/examples/messageEvents).
58 changes: 8 additions & 50 deletions docs/resources/transmissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,24 @@

This library provides easy access to the [Transmissions](https://developers.sparkpost.com/api/transmissions) 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]) &rarr; `{Promise}`**<br />
* **list(options[, callback])**<br />
List an overview of all transmissions in the account
* `options.campaign_id` - id of the campaign used by the transmission
* `options.template_id` - id of the template used by the transmission
* `callback` - executed after task is completed if provided*
* standard `callback(err, data)`
* `err` - any error that occurred
* `data` - results returned by the api
* **find(id[, callback]) &rarr; `{Promise}`**<br />
* **get(id[, callback])**<br />
Retrieve the details about a transmission by its ID
* `id` - id of the transmission you want to look up **required**
* `callback` - see all function
* **send(transmission[, callback]) &rarr; `{Promise}`**<br />
* **send(transmission[, options, callback])**<br />
Sends a message by creating a new transmission
* `transmission` - an object of [transmission attributes](https://developers.sparkpost.com/api/transmissions#header-transmission-attributes)
* `transmission.num_rcpt_errors` - maximum number of recipient errors returned
* `callback` - see all function

*callback is optional because all methods return a Promise.

## Getting Started: Your First Mailing

```javascript
var SparkPost = require('sparkpost')
, client = new SparkPost('YOUR API KEY')
, options = {
campaign_id: 'first-mailing',
content: {
from: 'you@your-company.com',
subject: 'First SDK Mailing',
html: '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
text: 'Congratulations, {{name}}!! You just sent your very first mailing!'
},
substitution_data: {name: 'YOUR FIRST NAME'},
recipients: [{ address: { name: 'YOUR FULL NAME', email: 'YOUR EMAIL ADDRESS' } }]
};
* `options.num_rcpt_errors` - maximum number of recipient errors returned

client.transmissions.send(options)
.then(data => {
console.log('Woohoo! You just sent your first mailing!');
console.log(data);
})
.catch(err => {
console.log('Whoops! Something went wrong');
console.log(err);
});
## Examples

// Using a callback
client.transmissions.send(options, function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log('Woohoo! You just sent your first mailing!');
console.log(data);
}
});
```
Check out all the examples provided [here](/examples/transmissions).
Visit our examples section to see all of [our transmissions resource examples](/examples/transmissions).

## Tips and Tricks
* If you specify a stored recipient list and inline recipients in a Transmission, you will receive an error.
Expand Down
15 changes: 0 additions & 15 deletions examples/messageEvents/all_messageEvents.js

This file was deleted.

22 changes: 17 additions & 5 deletions examples/messageEvents/search_campaignClicks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@ var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key)
, searchParams = {
events: 'click',
campaign_ids: 'monday_mailshot'
};
events: 'click',
campaign_ids: 'monday_mailshot'
};

// Promise
client.messageEvents.search(searchParams)
.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.messageEvents.search(searchParams, function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log(data);
console.log('Congrats you can use our client library!');
console.log(data);
}
});

29 changes: 29 additions & 0 deletions examples/messageEvents/search_default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key);

// Returns 1000 events for the last hour

// Promise
client.messageEvents.search({})
.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.messageEvents.search({}, 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: 21 additions & 9 deletions examples/messageEvents/search_messageEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@ var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key)
, searchParams = {
from: '2016-01-01T00:00',
to: '2016-01-02T23:59',
page: 1,
per_page: 5,
events: ['bounce', 'out_of_band'],
bounce_classes: [10]
};
from: '2016-01-01T00:00',
to: '2016-01-02T23:59',
page: 1,
per_page: 5,
events: ['bounce', 'out_of_band'],
bounce_classes: [10]
};

// Promise
client.messageEvents.search(searchParams)
.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.messageEvents.search(searchParams, function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log(data);
console.log('Congrats you can use our client library!');
console.log(data);
}
});

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var key = 'YOURAPIKEY'
]
};

// Promise
client.subaccounts.create(subaccount)
.then(data => {
console.log('Congrats you can use our client library!');
Expand All @@ -22,7 +23,7 @@ client.subaccounts.create(subaccount)
console.log(err);
});

// Using a callback
// Callback
client.subaccounts.create(subaccount, function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key);

// Promise
client.subaccounts.get('123')
.then(data => {
console.log('Congrats you can use our client library!');
Expand All @@ -14,7 +15,7 @@ client.subaccounts.get('123')
console.log(err);
});

// Using a callback
// Callback
client.subaccounts.get('123', function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key);

// Promise
client.subaccounts.list()
.then(data => {
console.log('Congrats you can use our client library!');
Expand All @@ -14,7 +15,7 @@ client.subaccounts.list()
console.log(err);
});

// Using a callback
// Callback
client.subaccounts.list(function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var key = 'YOURAPIKEY'
status: 'suspended'
};

// Promise
client.subaccounts.update('123', subaccount)
.then(data => {
console.log('Congrats you can use our client library!');
Expand All @@ -18,7 +19,7 @@ client.subaccounts.update('123', subaccount)
console.log(err);
});

// Using a callback
// Callback
client.subaccounts.update('123', subaccount, function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key);

client.transmissions.find('YOUR-TRANsMISSION-KEY')
// Promise
client.transmissions.get('YOUR-TRANSMISSION-KEY')
.then(data => {
console.log('Congrats you can use our client library!');
console.log(data);
Expand All @@ -14,8 +15,8 @@ client.transmissions.find('YOUR-TRANsMISSION-KEY')
console.log(err);
});

// Using a callback
client.transmissions.find('YOUR-TRANSMISSION-KEY', function(err, data) {
// Callback
client.transmissions.get('YOUR-TRANSMISSION-KEY', function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key);

client.transmissions.all()
// Promise
client.transmissions.list()
.then(data => {
console.log(data);
console.log('Congrats you can use our client library!');
Expand All @@ -13,8 +14,8 @@ client.transmissions.all()
console.log(err);
});

// Using a callback
client.transmissions.all(function(err, data) {
// Callback
client.transmissions.list(function(err, data) {
if (err) {
console.log(err);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var key = 'YOURAPIKEY'
campaign_id: 'my_campaign'
};

client.transmissions.all(options)
client.transmissions.list(options)
.then(data => {
console.log('Congrats you can use our client library!');
console.log(data);
Expand All @@ -18,7 +18,7 @@ client.transmissions.all(options)
});

// Using a callback
client.transmissions.all(options, function(err, data) {
client.transmissions.list(options, function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
Expand Down
Loading

0 comments on commit 6557288

Please sign in to comment.