UNPKG

jpush-sdk-cube

Version:

JPush's officially supported Node.js client library.

79 lines (63 loc) 1.88 kB
/* extend start */ var extend, _extend, _isObject; _isObject = function(o){ return Object.prototype.toString.call(o) === '[object Object]'; } _extend = function self(destination, source) { var property; for (property in destination) { if (destination.hasOwnProperty(property)) { // 若destination[property]和sourc[property]都是对象,则递归 if (_isObject(destination[property]) && _isObject(source[property])) { self(destination[property], source[property]); }; // 若sourc[property]已存在,则跳过 if (source.hasOwnProperty(property)) { continue; } else { source[property] = destination[property]; } } } } extend = function(){ var arr = arguments, result = {}, i; if (!arr.length) return {}; for (i = arr.length - 1; i >= 0; i--) { if (_isObject(arr[i])) { _extend(arr[i], result); }; } arr[0] = result; return result; } exports.extend = extend; /* extend end */ /* sendRequest start */ exports.sendRequest = function(url, payload, appkey, masterSecret, callback) { var done = function (err, res, body) { if (err) return callback(err); if (res.statusCode == 200) { callback(null, JSON.parse(payload)); } else { callback({ statusCode: res.statusCode, body: JSON.parse(body) }) } request.post({ url: url, body: JSON.stringify(postBody), auth: { user: options.appkey, pass: options.masterSecret }, timeout: options.timeout || 60000 //default 1 min timeout }, done) }; } /* sendRequest end */