Skip to content

Commit 49f0305

Browse files
committed
Correct payload structure, tests and update README
1 parent 1f4942b commit 49f0305

4 files changed

Lines changed: 51 additions & 8 deletions

File tree

README.md

Lines changed: 43 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)` |

lib/events.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ module.exports = {
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(`v2/${this.accountId}/events/batches`, this.generateResource('events', 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

spec/lib/events_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ describe('Events with Promise', () => {
8181
it('should record a batch of events', (done) => {
8282
expect(typeof client.recordBatchEvents).toEqual('function');
8383

84-
client.recordBatchEvents({ email: 'test@example.com', action: 'Purchased' })
84+
client.recordBatchEvents([{ email: 'test@example.com', action: 'Purchased' }])
8585
.then((response) => {
8686
expect(response.statusCode).toBe(200);
8787
expect(client.request.callCount).toBe(1);
8888
})
8989
.catch(failTest);
9090
done();
9191

92-
expect(client.post).toHaveBeenCalledWith('v2/9999999/events/batches', { events: [{ email: 'test@example.com', action: 'Purchased' }] }, undefined);
92+
expect(client.post).toHaveBeenCalledWith('v2/9999999/events/batches', { batches: [{ events: [{ email: 'test@example.com', action: 'Purchased' }] }] }, undefined);
9393
});
9494

9595
it('should fetch a list of event actions', (done) => {

spec/lib/shopper_activity_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe('Shopper Activity with Promise', () => {
150150
.catch(failTest);
151151
done();
152152

153-
expect(client.post).toHaveBeenCalledWith('v3/9999999/shopper_activity/cart', { payload }, undefined);
153+
expect(client.post).toHaveBeenCalledWith('v3/9999999/shopper_activity/cart', payload, undefined);
154154
});
155155

156156
it('should create an order activity and call request with POST', (done) => {
@@ -165,7 +165,7 @@ describe('Shopper Activity with Promise', () => {
165165
.catch(failTest);
166166
done();
167167

168-
expect(client.post).toHaveBeenCalledWith('v3/9999999/shopper_activity/order', { payload }, undefined);
168+
expect(client.post).toHaveBeenCalledWith('v3/9999999/shopper_activity/order', payload, undefined);
169169
});
170170

171171
it('should create a product activity and call request with POST', (done) => {
@@ -184,6 +184,6 @@ describe('Shopper Activity with Promise', () => {
184184
.catch(failTest);
185185
done();
186186

187-
expect(client.post).toHaveBeenCalledWith('v3/9999999/shopper_activity/product', { payload }, undefined);
187+
expect(client.post).toHaveBeenCalledWith('v3/9999999/shopper_activity/product', payload, undefined);
188188
});
189189
});

0 commit comments

Comments
 (0)