Skip to content

Commit 6557288

Browse files
authored
Standardized action verbs on remaining libraries (#184)
* 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
1 parent 21bd332 commit 6557288

26 files changed

+243
-230
lines changed

docs/resources/messageEvents.md

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
11
# Message Events
22

3-
This library provides easy access to the [Message Events](https://www.sparkpost.com/api#/reference/message-events/) resource.
3+
This library provides easy access to the [Message Events](https://developers.sparkpost.com/api/message-events) resource.
4+
5+
*Note: All methods return promises and accept an optional last argument callback. [Read about how we handle callbacks and promises](/docs/async.md).*
46

57
## Methods
6-
* **search(params, callback)**
8+
* **search([params, callback])**<br />
79
Search for message events using the given parameters (NOTE: all params are optional):
8-
* `params.bounce_classes` - list of [bounce classes](https://support.sparkpost.com/customer/portal/articles/1929896)
9-
* `params.campaign_ids` - campaign IDs
10-
* `params.events` - event types
11-
* `params.friendly_froms` - 'friendly' from addressess
12-
* `params.from` - time lower bound (see below for date/time format details)
13-
* `params.message_ids` - message IDs
14-
* `params.page` - results page number
15-
* `params.per_page` - number of results per page
16-
* `params.reason` - bounce reason with '%' wildcards (see below for example)
17-
* `params.recipients` - recipient email addresses
18-
* `params.template_ids` - template IDs
19-
* `params.timezone` - timezone for `from` and `to` params ([reference](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones))
20-
* `params.to` - time upper bound (see below for date/time format details)
21-
* `params.transmission_ids` - transmission IDs
10+
* `params` - a hash of [Message Events URI Parameters](https://developers.sparkpost.com/api/message-events.html#message-events-message-events-get)
2211

2312
## Date/Time Parameter Format
2413

25-
The `from` and `to` search parameters accept datestamps of the form:
14+
The `from` and `to` search parameters accept date stamps of the form:
2615

2716
`YYYY-MM-DDTHH:MM`
2817

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

3322
## Examples
3423

35-
This example code retrieves up to 5 'invalid recipient' bounce events from the first 2 days of 2016.
36-
37-
```js
38-
var SparkPost = require('sparkpost');
39-
var client = new SparkPost('YOUR_API_KEY');
40-
var searchParams = {
41-
from: '2016-01-01T00:00',
42-
to: '2016-01-02T23:59',
43-
page: 1,
44-
per_page: 5,
45-
events: ['bounce', 'out_of_band'],
46-
bounce_classes: [10]
47-
};
48-
49-
client.messageEvents.search(searchParams, function(err, res) {
50-
if(err) {
51-
console.log(err);
52-
return;
53-
}
54-
55-
console.log(data);
56-
});
57-
58-
```
59-
60-
Check out all the examples provided [here](/examples/messageEvents).
24+
Visit our examples section to see all of [our message events resource examples](/examples/messageEvents).

docs/resources/transmissions.md

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,24 @@
22

33
This library provides easy access to the [Transmissions](https://developers.sparkpost.com/api/transmissions) Resource.
44

5+
*Note: All methods return promises and accept an optional last argument callback. [Read about how we handle callbacks and promises](/docs/async.md).*
6+
57
## Methods
6-
* **all(options[, callback]) &rarr; `{Promise}`**<br />
8+
* **list(options[, callback])**<br />
79
List an overview of all transmissions in the account
810
* `options.campaign_id` - id of the campaign used by the transmission
911
* `options.template_id` - id of the template used by the transmission
10-
* `callback` - executed after task is completed if provided*
11-
* standard `callback(err, data)`
12-
* `err` - any error that occurred
13-
* `data` - results returned by the api
14-
* **find(id[, callback]) &rarr; `{Promise}`**<br />
12+
* **get(id[, callback])**<br />
1513
Retrieve the details about a transmission by its ID
1614
* `id` - id of the transmission you want to look up **required**
17-
* `callback` - see all function
18-
* **send(transmission[, callback]) &rarr; `{Promise}`**<br />
15+
* **send(transmission[, options, callback])**<br />
1916
Sends a message by creating a new transmission
2017
* `transmission` - an object of [transmission attributes](https://developers.sparkpost.com/api/transmissions#header-transmission-attributes)
21-
* `transmission.num_rcpt_errors` - maximum number of recipient errors returned
22-
* `callback` - see all function
23-
24-
*callback is optional because all methods return a Promise.
25-
26-
## Getting Started: Your First Mailing
27-
28-
```javascript
29-
var SparkPost = require('sparkpost')
30-
, client = new SparkPost('YOUR API KEY')
31-
, options = {
32-
campaign_id: 'first-mailing',
33-
content: {
34-
from: 'you@your-company.com',
35-
subject: 'First SDK Mailing',
36-
html: '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
37-
text: 'Congratulations, {{name}}!! You just sent your very first mailing!'
38-
},
39-
substitution_data: {name: 'YOUR FIRST NAME'},
40-
recipients: [{ address: { name: 'YOUR FULL NAME', email: 'YOUR EMAIL ADDRESS' } }]
41-
};
18+
* `options.num_rcpt_errors` - maximum number of recipient errors returned
4219

43-
client.transmissions.send(options)
44-
.then(data => {
45-
console.log('Woohoo! You just sent your first mailing!');
46-
console.log(data);
47-
})
48-
.catch(err => {
49-
console.log('Whoops! Something went wrong');
50-
console.log(err);
51-
});
20+
## Examples
5221

53-
// Using a callback
54-
client.transmissions.send(options, function(err, data) {
55-
if (err) {
56-
console.log('Whoops! Something went wrong');
57-
console.log(err);
58-
} else {
59-
console.log('Woohoo! You just sent your first mailing!');
60-
console.log(data);
61-
}
62-
});
63-
```
64-
Check out all the examples provided [here](/examples/transmissions).
22+
Visit our examples section to see all of [our transmissions resource examples](/examples/transmissions).
6523

6624
## Tips and Tricks
6725
* If you specify a stored recipient list and inline recipients in a Transmission, you will receive an error.

examples/messageEvents/all_messageEvents.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/messageEvents/search_campaignClicks.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,28 @@ var key = 'YOURAPIKEY'
44
, SparkPost = require('sparkpost')
55
, client = new SparkPost(key)
66
, searchParams = {
7-
events: 'click',
8-
campaign_ids: 'monday_mailshot'
9-
};
7+
events: 'click',
8+
campaign_ids: 'monday_mailshot'
9+
};
1010

11+
// Promise
12+
client.messageEvents.search(searchParams)
13+
.then(data => {
14+
console.log('Congrats you can use our client library!');
15+
console.log(data);
16+
})
17+
.catch(err => {
18+
console.log('Whoops! Something went wrong');
19+
console.log(err);
20+
});
21+
22+
// Callback
1123
client.messageEvents.search(searchParams, function(err, data) {
1224
if (err) {
25+
console.log('Whoops! Something went wrong');
1326
console.log(err);
1427
} else {
15-
console.log(data);
1628
console.log('Congrats you can use our client library!');
29+
console.log(data);
1730
}
1831
});
19-
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
var key = 'YOURAPIKEY'
4+
, SparkPost = require('sparkpost')
5+
, client = new SparkPost(key);
6+
7+
// Returns 1000 events for the last hour
8+
9+
// Promise
10+
client.messageEvents.search({})
11+
.then(data => {
12+
console.log('Congrats you can use our client library!');
13+
console.log(data);
14+
})
15+
.catch(err => {
16+
console.log('Whoops! Something went wrong');
17+
console.log(err);
18+
});
19+
20+
// Callback
21+
client.messageEvents.search({}, function(err, data) {
22+
if (err) {
23+
console.log('Whoops! Something went wrong');
24+
console.log(err);
25+
} else {
26+
console.log('Congrats you can use our client library!');
27+
console.log(data);
28+
}
29+
});

examples/messageEvents/search_messageEvents.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,32 @@ var key = 'YOURAPIKEY'
44
, SparkPost = require('sparkpost')
55
, client = new SparkPost(key)
66
, searchParams = {
7-
from: '2016-01-01T00:00',
8-
to: '2016-01-02T23:59',
9-
page: 1,
10-
per_page: 5,
11-
events: ['bounce', 'out_of_band'],
12-
bounce_classes: [10]
13-
};
7+
from: '2016-01-01T00:00',
8+
to: '2016-01-02T23:59',
9+
page: 1,
10+
per_page: 5,
11+
events: ['bounce', 'out_of_band'],
12+
bounce_classes: [10]
13+
};
1414

15+
// Promise
16+
client.messageEvents.search(searchParams)
17+
.then(data => {
18+
console.log('Congrats you can use our client library!');
19+
console.log(data);
20+
})
21+
.catch(err => {
22+
console.log('Whoops! Something went wrong');
23+
console.log(err);
24+
});
25+
26+
// Callback
1527
client.messageEvents.search(searchParams, function(err, data) {
1628
if (err) {
29+
console.log('Whoops! Something went wrong');
1730
console.log(err);
1831
} else {
19-
console.log(data);
2032
console.log('Congrats you can use our client library!');
33+
console.log(data);
2134
}
2235
});
23-

examples/subaccounts/create_subaccount.js renamed to examples/subaccounts/create.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var key = 'YOURAPIKEY'
1212
]
1313
};
1414

15+
// Promise
1516
client.subaccounts.create(subaccount)
1617
.then(data => {
1718
console.log('Congrats you can use our client library!');
@@ -22,7 +23,7 @@ client.subaccounts.create(subaccount)
2223
console.log(err);
2324
});
2425

25-
// Using a callback
26+
// Callback
2627
client.subaccounts.create(subaccount, function(err, data) {
2728
if (err) {
2829
console.log('Whoops! Something went wrong');

examples/subaccounts/get_subaccount.js renamed to examples/subaccounts/get.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var key = 'YOURAPIKEY'
44
, SparkPost = require('sparkpost')
55
, client = new SparkPost(key);
66

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

17-
// Using a callback
18+
// Callback
1819
client.subaccounts.get('123', function(err, data) {
1920
if (err) {
2021
console.log('Whoops! Something went wrong');

examples/subaccounts/list_subaccounts.js renamed to examples/subaccounts/list.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var key = 'YOURAPIKEY'
44
, SparkPost = require('sparkpost')
55
, client = new SparkPost(key);
66

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

17-
// Using a callback
18+
// Callback
1819
client.subaccounts.list(function(err, data) {
1920
if (err) {
2021
console.log('Whoops! Something went wrong');

examples/subaccounts/update_subaccount.js renamed to examples/subaccounts/update.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var key = 'YOURAPIKEY'
88
status: 'suspended'
99
};
1010

11+
// Promise
1112
client.subaccounts.update('123', subaccount)
1213
.then(data => {
1314
console.log('Congrats you can use our client library!');
@@ -18,7 +19,7 @@ client.subaccounts.update('123', subaccount)
1819
console.log(err);
1920
});
2021

21-
// Using a callback
22+
// Callback
2223
client.subaccounts.update('123', subaccount, function(err, data) {
2324
if (err) {
2425
console.log('Whoops! Something went wrong');

0 commit comments

Comments
 (0)