Comparing version 1.3.1 to 1.4.0
@@ -71,53 +71,53 @@ "use strict"; | ||
api.login_url = function(params) { | ||
api.login_url = function(params, host) { | ||
//console.log("params: ", params); | ||
if (!params) { params = {}; } | ||
if (!host) { host = this.server.host; } | ||
this._sign(params); | ||
var path = '/signin/partner/?' + querystring.stringify(params); | ||
return "http://" + this.server.host + path; | ||
return "http://" + host + path; | ||
}; | ||
this._sign = function(params) { | ||
api.sign_params = function(params) { | ||
params.api_ts = Math.round((new Date()).getTime() / 1000); | ||
params.api_key = this.server.api_key; | ||
params.api_ts = Math.round((new Date()).getTime() / 1000); | ||
params.api_key = this.server.api_key; | ||
// remove any api_sig parameter that might have snuck in here. | ||
delete params.api_sig; | ||
// remove any api_sig parameter that might have snuck in here. | ||
delete params.api_sig; | ||
var keys = _.keys(params).sort(), | ||
parameters = ''; | ||
var parameters = ""; | ||
var keys = _.keys(params).sort(); | ||
_.each(keys, function(k) { | ||
if (typeof params[k] === 'undefined') { | ||
delete params[k]; | ||
_.each(keys, function(k) { | ||
if (params[k] === null || typeof params[k] === 'undefined') { | ||
delete params[k]; | ||
} else { | ||
var v = params[k]; | ||
// for file uploads | ||
if (typeof v === 'object') { | ||
if (v.filename) { | ||
v = v.filename; | ||
} else { | ||
console.error("Don't know how to sign with key/object", k, v); | ||
} | ||
else { | ||
var v = params[k]; | ||
// for file uploads | ||
if (typeof v === 'object') { | ||
if (v.filename) { | ||
v = v.filename; | ||
} | ||
else { | ||
console.error("Don't know how to sign with key/object", k, v); | ||
} | ||
} | ||
parameters = parameters + ( parameters ? "" : "") + k + v; | ||
} | ||
}); | ||
} | ||
parameters += k + v; | ||
} | ||
}); | ||
params.api_sig = hmac_sha256( | ||
encode_utf8(parameters), | ||
this.server.api_secret | ||
); | ||
return _.extend( | ||
{ api_sig: hmac_sha256( encode_utf8(parameters), this.server.api_secret ) }, | ||
params | ||
); | ||
}; | ||
// modifies the params structure in place, so not returning anything | ||
} | ||
var _handle_response = function(cb) { | ||
return function(res) { | ||
var data; | ||
//console.log('STATUS: ' + res.statusCode); | ||
//console.log('HEADERS: ' + JSON.stringify(res.headers)); | ||
if (api.debug) { | ||
console.log('STATUS: ' + res.statusCode); | ||
console.log('HEADERS: ' + JSON.stringify(res.headers)); | ||
} | ||
res.setEncoding('utf8'); | ||
@@ -137,3 +137,5 @@ var api_response = ""; | ||
try { | ||
data = JSON.parse(api_response); | ||
data = /\b(?:application|text)\/(?:json|javascript)\b/.test(res.header('content-type')) | ||
? JSON.parse(api_response) | ||
: new String(api_response); | ||
} | ||
@@ -161,3 +163,3 @@ catch(err) { | ||
if (!params) { params = {}; } | ||
this._sign(params); | ||
params = this.sign_params(params); | ||
@@ -193,3 +195,3 @@ if (api.debug) { console.log("api request:", method, params); } | ||
params = _.clone(params); | ||
this._sign(params); | ||
params = this.sign_params(params); | ||
@@ -233,3 +235,3 @@ var req = http.request( | ||
has_files = true; | ||
p[k] = rest.file( v.path, null, null, null, 'image/png' ); | ||
p[k] = rest.file( v.path, null, v.size, null, 'image/png' ); | ||
} | ||
@@ -239,3 +241,3 @@ }); | ||
params = _.clone(params); | ||
this._sign(params); | ||
params = this.sign_params(params); | ||
@@ -242,0 +244,0 @@ var req = rest.post(url, |
@@ -5,3 +5,3 @@ { | ||
"description": "YellowBot API wrapper", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"homepage": "https://github.com/solfo/node-yellowbot", | ||
@@ -8,0 +8,0 @@ "repository": { |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
13802
285
2