Skip to content

Commit 8316edc

Browse files
authored
Merge pull request #23 from samudary/v3/shopper-activity
V3 Shopper Activity methods
2 parents eb4112d + 49f0305 commit 8316edc

43 files changed

Lines changed: 1141 additions & 855 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
language: node_js
22
node_js:
3-
- "6"
4-
- "7"
3+
- "9"
4+
- "10"
5+
- "11"
6+
- "12"
57
before_script:
68
- "npm i -g jasmine eslint eslint-config-airbnb-base eslint-plugin-import sinon"
79
script:

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,48 @@ A complete Nodejs wrapper for the Drip REST API.
88

99
`npm install drip-nodejs --save`
1010

11+
## NOTE: Potential Breaking Changes for Version 3.0.0
12+
13+
Drip's documentation doesn't explicitly describe the required schema for each endpoint. In versions prior to 3 you would need to explicitly pass payloads with the required schema, which aren't obvious. In version 3 and later, I've attempted to make this a bit simpler. For example, batch endpoints will now only need you to pass an array of objects as:
14+
15+
```js
16+
payload = [
17+
{
18+
email: 'user@example.com',
19+
action: 'Purchased'
20+
},
21+
{
22+
email: 'user@example.com',
23+
action: 'Purchased'
24+
}
25+
]
26+
// client.recordBatchEvents(payload, ...)
27+
```
28+
29+
Prior to v3 changes you would need to do something like the following where the entire payload structure is defined:
30+
31+
```js
32+
payload = {
33+
batches: [
34+
{
35+
events: [
36+
{
37+
email: 'user@example.com',
38+
action: 'Purchased'
39+
},
40+
{
41+
email: 'user@example.com',
42+
action: 'Purchased'
43+
}
44+
]
45+
}
46+
]
47+
}
48+
// client.recordBatchEvents(payload, ...)
49+
```
50+
51+
This should help to get up and running simpler without much knowledge of the required schema. **However, existing users will need to take special note of these changes**.
52+
1153
## Authentication
1254

1355
For private use and integrations, use your API Token found [here](https://www.getdrip.com/user/edit). Create a new instance of the client library with:
@@ -32,7 +74,7 @@ The following methods are currently available on the client instance. You can fi
3274
| List all accounts | `client.listAccounts(callback)` |
3375
| Fetch an account | `client.fetchAccount(accountId, callback)` |
3476

35-
### Broadcats
77+
### Broadcasts
3678
| Action | Method |
3779
|--------------------------------------|------------------------------------------------------------------------------|
3880
| List broadcasts | `client.listBroadcasts(options = {}, callback)` |
@@ -86,6 +128,13 @@ The following methods are currently available on the client instance. You can fi
86128
| Record a batch of orders | `client.createUpdateBatchOrders(payload, callback)` |
87129
| Record a refund for an order | `client.createUpdateRefund(payload, callback)` |
88130

131+
### Shopper Activity
132+
| Action | Method |
133+
|--------------------------------------|------------------------------------------------------------------------------|
134+
| Create or update a cart for a customer | `client.createUpdateCartActivity(payload, callback)` |
135+
| Create or update an order for a customer | `client.createUpdateOrderActivity(payload, callback)` |
136+
| Create or update a product | `client.createUpdateProductActivity(payload, callback)` |
137+
89138
### Subscribers
90139
| Action | Method |
91140
|--------------------------------------|------------------------------------------------------------------------------|

lib/accounts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
* @returns {promise}
77
*/
88
listAccounts(callback) {
9-
return this.get('accounts', {}, callback);
9+
return this.get('v2/accounts', {}, callback);
1010
},
1111
/**
1212
* Fetch an account
@@ -16,6 +16,6 @@ module.exports = {
1616
* @returns {promise}
1717
*/
1818
fetchAccount(accountId, callback) {
19-
return this.get(`accounts/${accountId}`, {}, callback);
19+
return this.get(`v2/accounts/${accountId}`, {}, callback);
2020
}
2121
};

lib/broadcasts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
* @returns {promise}
99
*/
1010
listBroadcasts(options = {}, callback) {
11-
return this.get(`${this.accountId}/broadcasts/`, { qs: options }, callback);
11+
return this.get(`v2/${this.accountId}/broadcasts/`, { qs: options }, callback);
1212
},
1313
/**
1414
* Fetch a broadcast
@@ -18,6 +18,6 @@ module.exports = {
1818
* @returns {promise}
1919
*/
2020
fetchBroadcast(broadcastId, callback) {
21-
return this.get(`${this.accountId}/broadcasts/${broadcastId}`, {}, callback);
21+
return this.get(`v2/${this.accountId}/broadcasts/${broadcastId}`, {}, callback);
2222
}
2323
};

lib/campaigns.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
* @returns {promise}
99
*/
1010
listCampaigns(options = {}, callback) {
11-
return this.get(`${this.accountId}/campaigns/`, { qs: options }, callback);
11+
return this.get(`v2/${this.accountId}/campaigns/`, { qs: options }, callback);
1212
},
1313
/**
1414
* Fetch a campaign
@@ -18,7 +18,7 @@ module.exports = {
1818
* @returns {promise}
1919
*/
2020
fetchCampaign(campaignId, callback) {
21-
return this.get(`${this.accountId}/campaigns/${campaignId}`, {}, callback);
21+
return this.get(`v2/${this.accountId}/campaigns/${campaignId}`, {}, callback);
2222
},
2323
/**
2424
* Activate a campaign
@@ -28,7 +28,7 @@ module.exports = {
2828
* @returns {promise}
2929
*/
3030
activateCampaign(campaignId, callback) {
31-
return this.post(`${this.accountId}/campaigns/${campaignId}/activate`, {}, callback);
31+
return this.post(`v2/${this.accountId}/campaigns/${campaignId}/activate`, {}, callback);
3232
},
3333
/**
3434
* Pause a campaign
@@ -38,7 +38,7 @@ module.exports = {
3838
* @returns {promise}
3939
*/
4040
pauseCampaign(campaignId, callback) {
41-
return this.post(`${this.accountId}/campaigns/${campaignId}/pause`, {}, callback);
41+
return this.post(`v2/${this.accountId}/campaigns/${campaignId}/pause`, {}, callback);
4242
},
4343
/**
4444
* List all subscribers subscribed to a campaign
@@ -48,7 +48,7 @@ module.exports = {
4848
* @returns {promise}
4949
*/
5050
listAllSubscribesToCampaign(campaignId, callback) {
51-
return this.get(`${this.accountId}/campaigns/${campaignId}/subscribers`, {}, callback);
51+
return this.get(`v2/${this.accountId}/campaigns/${campaignId}/subscribers`, {}, callback);
5252
},
5353
/**
5454
* Subscribe someone to a campaign
@@ -59,6 +59,6 @@ module.exports = {
5959
* @returns {promise}
6060
*/
6161
subscribeToCampaign(campaignId, payload, callback) {
62-
return this.post(`${this.accountId}/campaigns/${campaignId}/subscribers`, { payload }, callback);
62+
return this.post(`v2/${this.accountId}/campaigns/${campaignId}/subscribers`, this.generateResource('subscribers', payload), callback);
6363
}
6464
};

lib/conversions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
* @returns {promise}
99
*/
1010
listConversions(options = {}, callback) {
11-
return this.get(`${this.accountId}/goals/`, { qs: options }, callback);
11+
return this.get(`v2/${this.accountId}/goals/`, { qs: options }, callback);
1212
},
1313
/**
1414
* Fetch a conversion
@@ -18,6 +18,6 @@ module.exports = {
1818
* @returns {promise}
1919
*/
2020
fetchConversion(conversionId, callback) {
21-
return this.get(`${this.accountId}/goals/${conversionId}`, {}, callback);
21+
return this.get(`v2/${this.accountId}/goals/${conversionId}`, {}, callback);
2222
}
2323
};

lib/custom_fields.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ module.exports = {
66
* @returns {promise}
77
*/
88
listAllCustomFields(callback) {
9-
return this.get(`${this.accountId}/custom_field_identifiers/`, {}, callback);
9+
return this.get(`v2/${this.accountId}/custom_field_identifiers/`, {}, callback);
1010
}
1111
};

lib/errors.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class MissingAttributeError extends Error {
2+
constructor(message) {
3+
super(message);
4+
5+
this.name = this.constructor.name;
6+
}
7+
}
8+
9+
module.exports = MissingAttributeError;

lib/events.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ module.exports = {
77
* @returns {promise}
88
*/
99
recordEvent(payload, callback) {
10-
return this.post(`${this.accountId}/events`, { payload }, callback);
10+
return this.post(`v2/${this.accountId}/events`, this.generateResource('events', payload), callback);
1111
},
1212
/**
1313
* Record a batch of events
1414
*
15-
* @param {object} payload - An object with event name and subscriber emails
15+
* @param {object} payload - An array of event objects with at least
16+
* an action and subscriber emails
1617
* @param {callback} callback - An optional callback
1718
* @returns {promise}
1819
*/
1920
recordBatchEvents(payload, callback) {
20-
return this.post(`${this.accountId}/events/batches`, { payload }, callback);
21+
return this.post(`v2/${this.accountId}/events/batches`, this.generateResource('batches', { events: payload }), callback);
2122
},
2223
/**
2324
* Fetch a list of all event actions
@@ -27,6 +28,6 @@ module.exports = {
2728
* @returns {promise}
2829
*/
2930
listEventActions(options = {}, callback) {
30-
return this.get(`${this.accountId}/event_actions/`, { qs: options }, callback);
31+
return this.get(`v2/${this.accountId}/event_actions/`, { qs: options }, callback);
3132
}
3233
};

lib/forms.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
* @returns {promise}
77
*/
88
listForms(callback) {
9-
return this.get(`${this.accountId}/forms`, {}, callback);
9+
return this.get(`v2/${this.accountId}/forms`, {}, callback);
1010
},
1111
/**
1212
* Fetch a form
@@ -16,6 +16,6 @@ module.exports = {
1616
* @returns {promise}
1717
*/
1818
fetchForm(formId, callback) {
19-
return this.get(`${this.accountId}/forms/${formId}`, {}, callback);
19+
return this.get(`v2/${this.accountId}/forms/${formId}`, {}, callback);
2020
}
2121
};

0 commit comments

Comments
 (0)