How to use needle - 10 common examples

To help you get started, we’ve selected a few needle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Ireoo / spider.npm / test / net.js View on Github external
};
            this.cb = function() {}
        }
        //实列化一个最大并发为1的队列
        this.queue = new Queue(this.init.threads,{
            "queueStart": function(queue){}
            ,"queueEnd": function(queue){}
            ,"workAdd": function(item, queue){}
            ,"workResolve": function(value, queue){}
            ,"workReject": function(reason, queue){}
            ,"workFinally": function(queue){}
            ,"retry": this.init.retry               //Number of retries
            ,"retryIsJump": this.init.retryIsJump     //retry now?
            ,"timeout": this.init.timeout           //The timeout period
        });
        needle.defaults({
            // open_timeout: this.init.timeout,
            // read_timeout: this.init.timeout,
            // timeout: this.init.timeout,
            user_agent: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)'
        });
        if (options.run) this.run(options.links);
        return this;
    }
github leanote / desktop-app / node_modules / api.js View on Github external
exportPdf: function(noteId, callback) {
		var me = this;
		// console.log(me.getUrl('note/exportPdf', {noteId: noteId}));
		needle.get(me.getUrl('note/exportPdf', {noteId: noteId}), function(err, resp) {
			me.checkError(err, resp);
			if(err) {
				return callback && callback(false);
			}
			// log(resp.body);
			/*
			{ 'accept-ranges': 'bytes',
			  'content-disposition': 'inline; filename="logo.png"',
			  'content-length': '8583',
			  'content-type': 'image/png',
			  date: 'Mon, 19 Jan 2015 15:01:47 GMT',
  			*/
 
  			var body = resp.body;
  			if(typeof body == "object" && body.Msg === false) {
  				return callback(false, "", body.Msg);
github leanote / desktop-app / node_modules / api.js View on Github external
uploadImage: function() {
		var data = {
			foo: 'bar',
			cc: [1,2,3,3],
			dd: {name: 'life', age: 18},
			image: { file: '/Users/life/Desktop/imageplus.png', content_type: 'image/png' }
		}
		needle.post('http://localhost/phpinfo.php', data, { multipart: true }, function(err, resp, body) {
			// needle will read the file and include it in the form-data as binary
			console.log(resp.body);
		});
	}
github clusterio / factorioClusterio / sharedPlugins / inventoryImports / interfacingFunctions.js View on Github external
Object.keys(json.exports).forEach(function(playerName){
				// loop over simpleItemStacks to export
				let stackArray = json.exports[playerName];
				for(let i = 0; i < stackArray.length; i++){
					if(stackArray[i].count > 0){
						// console.log("Returning overflow: " + JSON.stringify(stackArray[i]));
						needle.post(
							config.masterURL + '/api/place',
							stackArray[i],
							{headers: {'x-access-token': config.masterAuthToken}},
							function (err, resp, body) {
								// console.log(body);
							}
						);
					}
				}
			});
		}
github prey / prey-node-client / lib / agent / actions / fileretrieval / index.js View on Github external
exports.start = function(options, cb) {
  
  var url = UPLOAD_SERVER + '?uploadID=' + options.file_id;
  // Make a call to get the last byte processed by the upload server
  // in order to resume the upload from that position.
  needle.request('get', url, null, function(err, res) {
    if (err) {
      console.log(err);
      return;
    }
    if (res.statusCode == 404) {
      files.del(options.file_id);
      return;
    }
    var data = JSON.parse(res.body);
    var file_status = JSON.parse(res.body).Status
    options.total = data.Total;

    if (file_status == 0 || file_status == 4) { // File in progress(0) or Pending(4)  
      files.exist(options.file_id, function(err, exist) {
        if (!exist) {
          options.resumable = false;
github prey / prey-node-client / lib / agent / actions / fileretrieval / upload.js View on Github external
function retrieve_file(file, cb) {
  if (file.resumable == 'true') {
    console.log("Resumable file:", file.id);
    var url = UPLOAD_SERVER + '?uploadID=' + file.id;
    // Make a call to get the last byte processed by the upload server
    // in order to resume the upload from that position.
    needle.request('get', url, null, function(err, res) {
      if (err) {
        console.log(err);
        cb(err);
        return;
      }
      var data = JSON.parse(res.body);

      file.total = data.Total;
      get_file(file, cb);
    })
    return;
  }
  get_file(file, cb);
}
github apache / openwhisk-catalog / packages / github / webhook.js View on Github external
var foundWebhookToDelete = false;

        if (error) {
          reject({
            response: response,
            error: error,
            body: body
          });
        } else {
          for (var i = 0; i < body.length; i++) {
            if (decodeURI(body[i].config.url) === whiskCallbackUrl) {
              foundWebhookToDelete = true;

              console.log('DELETE Webhook URL: ' + body[i].url);

              needle.delete(body[i].url, null, { username: username, password: accessToken, user_agent: 'whisk' }, function (error, response, body) {
                if (error) {
                  reject({
                    response: response,
                    error: error,
                    body: body
                  });
                } else {
                  console.log("Status code: " + response.statusCode);
                  if (response.statusCode >= 400) {
                    console.log("Response from Github: " + body);

                    // a 404 is common and confusing enough to warrant an extra message
                    if (response.statusCode === 404) {
                      console.log('Please ensure your accessToken is authorized to delete webhooks.');
                    }
github charltoons / hipchatter / utils / cleanup_webhooks.js View on Github external
// A room can't have webhooks if it doesn't exist
        if (err.message == 'Room not found') return;

        console.error(err);
        return;
    }
    var webhooks = response.items;
    if (webhooks.length == 0) console.log('No webhooks for this room'.green)
    else console.log('Found '+webhooks.length+' for this room.');

    //for each webhook
    for (var i=0; i
github aripalo / node-irc-bot / commands / so.js View on Github external
el = $(el);

      var row = {
        Title: el.find('.result-link a').text(),
        URL: 'http://stackoverflow.com'+el.find('.result-link a').attr('href')
      };

      results.push(row);

    }.bind(this));

    return results;
  }

  needle.get('http://stackoverflow.com/search?q='+querystring.escape(q), defaultHeaders, function(error, response, body) {
    var results = parseString(body);

    var sendTo = from; // send privately
    if (isChannel(to)) {
      sendTo = to; // send publicly
    }

    client.say(sendTo,
      'Here are the top 3 Stackoverflow results for the search "'+q+'": '
      +'\n1: '+results[0].URL
      +'\n2: '+results[1].URL
      +'\n3: '+results[2].URL
      +'\nMore results at: http://stackoverflow.com/search?q='+querystring.escape(q)
      );

  });
github prey / prey-node-client / lib / package.js View on Github external
releases.get_stable_version = function(cb) {
  needle.get(releases_url + latest_text, function(err, resp, body) {
    var ver = body && body.toString().trim();
    // log('Latest upstream version: ' + ver);

    cb(err, ver);
  });
}

needle

The leanest and most handsome HTTP client in the Nodelands.

MIT
Latest version published 4 months ago

Package Health Score

77 / 100
Full package analysis