-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter-ads-api.js
More file actions
49 lines (43 loc) · 1.54 KB
/
twitter-ads-api.js
File metadata and controls
49 lines (43 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var _TwitterAdsAPI = Npm.require('twitter-ads');
// Expose main instance to check against
TwitterAdsAPIInstance = _TwitterAdsAPI;
TwitterAdsAPI = function TwitterAdsAPI(options) {
var twitterAdsClient = new _TwitterAdsAPI(options),
baseToWrap = ['get', 'put', 'post', 'delete'],
tonToWrap = ['tonUpload', 'tonDownload'];
baseToWrap.forEach(function(k) {
twitterAdsClient['_' + k] = twitterAdsClient[k].bind(twitterAdsClient);
twitterAdsClient[k] = Meteor.wrapAsync(function(url, params, body, cb) {
if (typeof params === 'function') {
cb = params;
params = {};
body = undefined;
}
if (typeof body === 'function') {
cb = body;
body = undefined;
}
if (k === 'put' || k === 'post') {
twitterAdsClient['_' + k](url, params, body, function(err, twitterResp, twitterBody) {
if (err) return cb(err);
return cb(null, {twitterResp, twitterBody});
});
} else {
twitterAdsClient['_' + k](url, params, function(err, twitterResp, twitterBody) {
if (err) return cb(err);
return cb(null, {twitterResp, twitterBody});
});
}
});
});
tonToWrap.forEach(function(k) {
twitterAdsClient['_' + k] = twitterAdsClient[k].bind(twitterAdsClient);
twitterAdsClient[k] = Meteor.wrapAsync(function(params, cb) {
twitterAdsClient['_' + k](params, function(err, result) {
if (err) return cb(err);
return cb(null, result);
});
});
});
return twitterAdsClient;
};