Skip to content

Commit

Permalink
wrap in Bluebird promises,
Browse files Browse the repository at this point in the history
return the response body
  • Loading branch information
officert committed Jun 13, 2017
1 parent 274269d commit ba015be
Show file tree
Hide file tree
Showing 29 changed files with 269 additions and 154 deletions.
64 changes: 43 additions & 21 deletions lib/client/events.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Promise = require('bluebird');
const v204 = require('./v204');
const _ = require('lodash');

Expand All @@ -12,7 +13,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -26,7 +28,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -40,7 +43,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -54,7 +58,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -68,7 +73,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -82,7 +88,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -96,7 +103,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -110,7 +118,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -124,7 +133,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -138,7 +148,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -152,7 +163,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -166,7 +178,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -180,7 +193,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -194,7 +208,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -208,7 +223,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -222,7 +238,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -236,7 +253,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -250,7 +268,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -264,7 +283,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -278,7 +298,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
},
/**
* @param {Object} [data]
Expand All @@ -292,7 +313,8 @@ function getEventsApi(key) {
$api_key: key
});

return v204.post('/events', data);
return Promise.resolve(v204.post('/events', data))
.then(response => response.body);
}
};
}
Expand Down
12 changes: 8 additions & 4 deletions lib/client/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@ function getLabelsApi(key) {
$api_key: key
});

return v204.post(`/users/${userId}/labels`, data);
return Promise.resolve(v204.post(`/users/${userId}/labels`, data))
.then(response => response.body);
},
/**
* @param {Object} [data]
* https://siftscience.com/developers/docs/curl/labels-api/unlabel-user
*/
deleteByUserId(userId, data = {}) {
deleteByUserId(userId, params = {}) {
if (!userId) return Promise.reject(new Error('userId is required'));

_.extend(data, {
_.extend(params, {
$api_key: key
});

return v204.delete(`/users/${userId}/labels`, data);
return Promise.resolve(v204.delete(`/users/${userId}/labels`, {
params
}))
.then(response => response.body);
}
};
}
Expand Down
8 changes: 4 additions & 4 deletions lib/client/v204/httpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ class HttpClient {
post(path, body = {}, params) {
if (!path) return Promise.reject(new Error('path is required'));

return this._client.post(path, body, params ? {
return this._client.post(path, body, (params ? {
params
} : null);
} : null));
}

delete(path, params) {
if (!path) return Promise.reject(new Error('path is required'));

return this._client.delete(path, params ? {
return this._client.delete(path, (params ? {
params
} : null);
} : null));
}
}

Expand Down
12 changes: 8 additions & 4 deletions tests/siftScience/client/events/addItemToCart-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ describe('siftScience', () => {
describe('when called with nothing', () => {
let postStub;

let response = {};
let response = {
body: {}
};

before('stub v204.post()', () => {
postStub = sandbox.stub(v204, 'post')
Expand All @@ -43,7 +45,7 @@ describe('siftScience', () => {
return siftScienceClient.events.addItemToCart()
.then(result => {
should.exist(result);
result.should.deepEqual(response);
result.should.deepEqual(response.body);

postStub.callCount.should.equal(1);
postStub.args[0][0].should.equal('/events');
Expand All @@ -61,7 +63,9 @@ describe('siftScience', () => {
};
let postStub;

let response = {};
let response = {
body: {}
};

before('stub v204.post()', () => {
postStub = sandbox.stub(v204, 'post')
Expand All @@ -72,7 +76,7 @@ describe('siftScience', () => {
return siftScienceClient.events.addItemToCart(data)
.then(result => {
should.exist(result);
result.should.deepEqual(response);
result.should.deepEqual(response.body);

postStub.callCount.should.equal(1);
postStub.args[0][0].should.equal('/events');
Expand Down
12 changes: 8 additions & 4 deletions tests/siftScience/client/events/addPromotion-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ describe('siftScience', () => {
describe('when called with nothing', () => {
let postStub;

let response = {};
let response = {
body: {}
};

before('stub v204.post()', () => {
postStub = sandbox.stub(v204, 'post')
Expand All @@ -43,7 +45,7 @@ describe('siftScience', () => {
return siftScienceClient.events.addPromotion()
.then(result => {
should.exist(result);
result.should.deepEqual(response);
result.should.deepEqual(response.body);

postStub.callCount.should.equal(1);
postStub.args[0][0].should.equal('/events');
Expand All @@ -61,7 +63,9 @@ describe('siftScience', () => {
};
let postStub;

let response = {};
let response = {
body: {}
};

before('stub v204.post()', () => {
postStub = sandbox.stub(v204, 'post')
Expand All @@ -72,7 +76,7 @@ describe('siftScience', () => {
return siftScienceClient.events.addPromotion(data)
.then(result => {
should.exist(result);
result.should.deepEqual(response);
result.should.deepEqual(response.body);

postStub.callCount.should.equal(1);
postStub.args[0][0].should.equal('/events');
Expand Down
12 changes: 8 additions & 4 deletions tests/siftScience/client/events/chargeback-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ describe('siftScience', () => {
describe('when called with nothing', () => {
let postStub;

let response = {};
let response = {
body: {}
};

before('stub v204.post()', () => {
postStub = sandbox.stub(v204, 'post')
Expand All @@ -43,7 +45,7 @@ describe('siftScience', () => {
return siftScienceClient.events.chargeback()
.then(result => {
should.exist(result);
result.should.deepEqual(response);
result.should.deepEqual(response.body);

postStub.callCount.should.equal(1);
postStub.args[0][0].should.equal('/events');
Expand All @@ -61,7 +63,9 @@ describe('siftScience', () => {
};
let postStub;

let response = {};
let response = {
body: {}
};

before('stub v204.post()', () => {
postStub = sandbox.stub(v204, 'post')
Expand All @@ -72,7 +76,7 @@ describe('siftScience', () => {
return siftScienceClient.events.chargeback(data)
.then(result => {
should.exist(result);
result.should.deepEqual(response);
result.should.deepEqual(response.body);

postStub.callCount.should.equal(1);
postStub.args[0][0].should.equal('/events');
Expand Down
Loading

0 comments on commit ba015be

Please sign in to comment.