Comparing version 0.4.8 to 0.5.0
@@ -13,3 +13,3 @@ var request = require('./request'); | ||
api.exportDownloadPackage = function (args) { | ||
return this.request('GET', '/etc/creativeExchange/export/api.package.zip', args, 'text'); | ||
return this.request('DOWNLOAD', '/etc/creativeExchange/export/api.package.zip', args); | ||
}; | ||
@@ -38,3 +38,3 @@ | ||
api.importDownloadPackage = function (args) { | ||
return this.request('GET', '/etc/creativeExchange/import/api.package.zip', args, 'text'); | ||
return this.request('DOWNLOAD', '/etc/creativeExchange/import/api.package.zip', args); | ||
}; | ||
@@ -41,0 +41,0 @@ |
@@ -16,3 +16,3 @@ var api = require('./api'); | ||
CrEx.prototype.request = function(method, url, args, ret) { | ||
CrEx.prototype.request = function(method, url, args) { | ||
var req = null; | ||
@@ -34,5 +34,8 @@ url = this.getUrl() + url; | ||
break; | ||
case 'DOWNLOAD': | ||
req = request.doDownload; | ||
break; | ||
} | ||
return req(url, args, ret); | ||
return req(url, args); | ||
}; | ||
@@ -39,0 +42,0 @@ |
var request = require('superagent'); | ||
var nodeBinaryParser = function (res, done) { | ||
res.setEncoding('binary'); | ||
res.text = ''; | ||
res.setEncoding('binary'); | ||
res.on('data', function (chunk) { | ||
@@ -10,7 +10,7 @@ res.text += chunk; | ||
res.on('end', function () { | ||
done(); | ||
done(null, new Buffer(res.text, 'binary')); | ||
}); | ||
}; | ||
var doGet = function (url, args, ret) { | ||
var doGet = function (url, args) { | ||
return new Promise(function (resolve, reject) { | ||
@@ -20,11 +20,6 @@ var r = request | ||
.query(args) | ||
.buffer(true); | ||
if (ret === 'text') { | ||
r.parse(nodeBinaryParser); | ||
} | ||
r.end(function (err, res) { | ||
.buffer(true) | ||
.end(function (err, res) { | ||
if (err) reject(err); | ||
resolve(ret === 'text' ? res.text : res.body); | ||
resolve(res.body); | ||
}); | ||
@@ -71,2 +66,16 @@ }); | ||
var doDownload = function(url, args) { | ||
return new Promise(function (resolve, reject) { | ||
request | ||
.get(url) | ||
.query(args) | ||
.buffer(true) | ||
.parse(nodeBinaryParser) | ||
.end(function (err, res) { | ||
if (err) reject(err); | ||
resolve(res.body); | ||
}); | ||
}); | ||
} | ||
module.exports = { | ||
@@ -76,3 +85,4 @@ doGet: doGet, | ||
doDelete: doDelete, | ||
doUpload: doUpload | ||
doUpload: doUpload, | ||
doDownload: doDownload | ||
}; |
{ | ||
"name": "crex", | ||
"version": "0.4.8", | ||
"version": "0.5.0", | ||
"description": "Creative Exchange SDK for Javascript", | ||
@@ -5,0 +5,0 @@ "author": "Mateusz Luczak <mateusz.luczak@outlook.com>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17277
380