How to use the needle.delete function in needle

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 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 charltoons / hipchatter / hipchatter.js View on Github external
delete_webhook: function(room, id, callback){
        needle.delete(this.url('room/'+room+'/webhook/'+id), null, function (error, response, body) {
            // Connection error
            if (!!error) callback(new Error('HipChat API Error.'));

            // HipChat returned an error or no HTTP Success status code
            else if (body.hasOwnProperty('error') || response.statusCode < 200 || response.statusCode >= 300){
                try { callback(new Error(body.error.message)); }
                catch (e) {callback(new Error(body)); }
            }

            // Everything worked
            else {
                callback(null, body);
            }
        });
    },
    delete_all_webhooks: function(room, callback){
github charltoons / hipchatter / hipchatter.js View on Github external
var url = payload.hasOwnProperty('token') ? this.url(path, payload, payload.token) : this.url(path, payload);
            needle.get(url, requestCallback);

        // POST request
        } else if (type.toLowerCase() === 'post') {
            var url = payload.hasOwnProperty('token') ? this.url(path, payload.token) : this.url(path);

            needle.post(url, payload, {json: true, headers:{'Content-Type': 'application/json; charset=utf-8'}}, requestCallback);

        // PUT request
        } else if (type.toLowerCase() === 'put') {
            needle.put(this.url(path), payload, {json: true, headers:{'Content-Type': 'application/json; charset=utf-8'}}, requestCallback);

        // DELETE request
        } else if (type.toLowerCase() === 'delete') {
            needle.delete(this.url(path), {}, requestCallback);

        // otherwise, something went wrong
        } else {
            if (self.isFunction(callback)) {
            callback(new Error('Invalid use of the hipchatter.request function.'));
            }
        }
    },
github hortonworks / cloudbreak / auth / main.js View on Github external
deleteUserById = function(req, res, token, userId, version, callback) {
        var usrOptions = {
            headers: {
                'Authorization': 'Bearer ' + token,
                'If-Match': version
            }
        }
        needle.delete(config.uaaAddress + '/Users/' + userId, null, usrOptions, function(err, userResp) {
            if (userResp.statusCode == 200) {
                callback(userResp.body)
            } else {
                console.log('Cannot delete user by id.')
                res.statusCode = 400
                res.json({
                    message: 'Cannot delete user by id - bad request.'
                })
            }
        });
    }
github BeepBoopHQ / in-or-out / src / chronos.js View on Github external
delete (id, callback) {
    console.log(`${this.base}/tasks/${id} - ${this.token}`)
    needle.delete(`${this.base}/tasks/${id}`, null, this._baseOptions(), (err, resp) => {
      if (err) return callback(err)
      if (resp.statusCode !== 200) {
        return callback(new Error(`unsuccesful status code ${resp.statusCode}`))
      }
      callback(null, resp.body)
    })
  }
github HologramEducation / hologram-node / lib / HoloClient.js View on Github external
return new Promise(function(resolve, reject) {

    if (this.config.showDebug || debug) console.log("DELETE: %s with %s", fqdn, JSON.stringify(body));
    needle.delete(fqdn, body, this.responseHandler(resolve, reject));

  }.bind(this));
};
github prey / prey-node-client / lib / conf / remote.js View on Github external
exports.unlink = function(cb){
  var root = get_root();
  if (!root) return cb(kaboom('HOST_NOT_SET'));

  var api_key    = config.get('api_key'),
      device_key = config.get('device_key');

   if (!api_key || !device_key)
    return cb(kaboom('MISSING_KEY'));

  log('Unlinking device...');

  var url = root + '/devices/' + device_key,
      opts = { username: api_key, password: 'x' };

  http_client.delete(url, opts, function(err, resp, body){
    if (err) return cb(err);

    if (resp.statusCode === 401)
      cb(kaboom('INVALID_CREDENTIALS'))
    else if (resp.statusCode != 200)
      return cb(new Error('Unable to unlink device.'));
    else
      cb();
  });
}

needle

The leanest and most handsome HTTP client in the Nodelands.

MIT
Latest version published 3 months ago

Package Health Score

83 / 100
Full package analysis