How to use the superagent.patch function in superagent

To help you get started, we’ve selected a few superagent 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 drone / drone-ui / src / actions / events.js View on Github external
events.on(PATCH_REPO, function(event) {
  const {owner, name} = event.data;

  // there is a bug where the input parameter names differ from
  // the output parameter names. This attempts to resolve.
  if (event.data.allow_deploys !== undefined) {
    event.data['allow_deploy'] = event.data.allow_deploys;
  }
  if (event.data.allow_tags !== undefined) {
    event.data['allow_tag'] = event.data.allow_tags;
  }

  Request.patch(`/api/repos/${owner}/${name}`)
    .set('X-CSRF_TOKEN', token)
    .send(event.data)
    .end((err, response) => {
      if (err != null) {
        console.error(err);
        tree.set(['pages', 'toast'], 'Error updating repository settings');
        return
      }
      let repo = JSON.parse(response.text);
      tree.set(['repos', owner, name], repo);
      tree.set(['pages', 'toast'], 'Successfully updated repository settings');
    });
});
github jpodwys / superagent-cache / test / server / caching.js View on Github external
superagent.cache.get(key, function (err, response) {
            expect(response.body.key).toBe('one');
            superagent
              .patch('localhost:3003/one')
              .end(function (err, response, key){
                expect(response.body.key).toBe('patch');
                superagent.cache.get(key, function (err, response) {
                  expect(response).toBe(null);
                  done();
                });
              }
            );
          });
        }
github salesforce / refocus / view / rooms / type / RoomTypeComponent.js View on Github external
updateRoomType(){
    const req = request.patch(`/v1/roomTypes/${this.props.roomType.id}`);
    const obj = {};
    try {
      const obj = {
        name: this.state.Name,
        isEnabled: this.state.Enabled == 'true',
        bots:  Array.isArray(this.state.Bots) ?
          this.state.Bots : typeof this.state.Bots === 'string' ?
          this.state.Bots.split(',') : [],
        settings: JSON.parse(this.state.Settings),
      };
      req
        .send(obj)
        .end((error, res) => {
          if (error) {
            this.setState({ error: error.response.body.errors[0].message });
          } else {
github vpdb / server / src / app / tokens / token.api.acl.spec.js View on Github external
it('should deny access to updating tokens', function(done) {
			request.patch('/api/v1/tokens/1234').send({}).end(hlp.status(401, done));
		});
github vpdb / server / src / app / tokens / token.api.scope.spec.js View on Github external
it('should allow access to token update', done => {
			request.patch('/api/v1/tokens/1234').send({}).with(tokenAll).end(hlp.status(404, done));
		});
github discordjs / discord.js / web-dist / discord.3.9.0.js View on Github external
callback = tts;tts = false;}var user=destination.sender;self.sendMessage(destination,message,tts,callback,user + ", ").then(response)["catch"](reject);});};Client.prototype.deleteMessage = function deleteMessage(message,timeout){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(timeout){setTimeout(remove,timeout);}else {remove();}function remove(){request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).end(function(err,res){if(err){bad();}else {good();}});}function good(){callback();resolve();}function bad(err){callback(err);reject(err);}});};Client.prototype.updateMessage = function updateMessage(message,content){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;var prom=new Promise(function(resolve,reject){content = content instanceof Array?content.join("\n"):content;if(self.options.queue){if(!self.queue[message.channel.id]){self.queue[message.channel.id] = [];}self.queue[message.channel.id].push({action:"updateMessage",message:message,content:content,then:good,error:bad});self.checkQueue(message.channel.id);}else {self._updateMessage(message,content).then(good)["catch"](bad);}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(error){prom.error = error;callback(error);reject(error);}});return prom;};Client.prototype.setUsername = function setUsername(newName){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.API + "/users/@me").set("authorization",self.token).send({avatar:self.user.avatar,email:self.email,new_password:null,password:self.password,username:newName}).end(function(err){callback(err);if(err)reject(err);else resolve();});});};Client.prototype.getChannelLogs = function getChannelLogs(channel){var amount=arguments.length <= 1 || arguments[1] === undefined?500:arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,logs){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {var logs=[];var channel=self.getChannel("id",channelID);for(var _iterator=res.body,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;var mentions=[];for(var _iterator2=message.mentions,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var mention=_ref2;mentions.push(self.addUser(mention));}var author=self.addUser(message.author);logs.push(new Message(message,channel,mentions,author));}callback(null,logs);resolve(logs);}});});};Client.prototype.deleteChannel = function deleteChannel(channel){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization",self.token).end(function(err){if(err){callback(err);reject(err);}else {callback(null);resolve();}});});};Client.prototype.joinServer = function joinServer(invite){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var id=invite instanceof Invite?invite.code:invite;request.post(Endpoints.API + "/invite/" + id).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {if(self.getServer("id",res.body.guild.id)){resolve(self.getServer("id",res.body.guild.id));}else {self.serverCreateListener[res.body.guild.id] = [resolve,callback];}}});});};Client.prototype.sendFile = function sendFile(destination,file){var fileName=arguments.length <= 2 || arguments[2] === undefined?"image.png":arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;var prom=new Promise(function(resolve,reject){var fstream;if(typeof file === "string" || file instanceof String){fstream = fs.createReadStream(file);fileName = file;}else {fstream = file;}self.resolveDestination(destination).then(send)["catch"](bad);function send(destination){if(self.options.queue){ //queue send file too
if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendFile",attachment:fstream,attachmentName:fileName,then:good,error:bad});self.checkQueue(destination);}else { //not queue
github seznam / IMA.js-core / server / proxy.js View on Github external
logger.info(`API proxy: ${req.method} ${proxyUrl} query: ` + JSON.stringify(req.query));

	switch(req.method) {
		case 'POST':
			httpRequest = superAgent
				.post(proxyUrl)
				.send(req.body);
			break;
		case 'PUT':
			httpRequest = superAgent
				.put(proxyUrl)
				.send(req.body);
			break;
		case 'PATCH':
			httpRequest = superAgent
				.patch(proxyUrl)
				.send(req.body);
			break;
		case 'DELETE':
			httpRequest = superAgent
				.del(proxyUrl)
				.send(req.body);
			break;
		case 'GET':
			httpRequest = superAgent
				.get(proxyUrl)
				.query(req.query);
			break;
	}

	Object
github auth0 / webtask-require / index.js View on Github external
switch(method) {
                case 'GET':
                    superagent
                        .get(url)
                        .set(headers)
                        .end(onEnd);
                    break;
                case 'POST':
                    superagent
                        .post(url)
                        .set(headers)
                        .send(body)
                        .end(onEnd);
                    break;
                case 'PATCH':
                    superagent
                        .patch(url)
                        .set(headers)
                        .send(body)
                        .end(onEnd);
                    break;
                case 'PUT':
                    superagent
                        .put(url)
                        .set(headers)
                        .send(body)
                        .end(onEnd);
                    break;
                case 'DELETE':
                    superagent
                        .del(url)
                        .set(headers)
github RackHD / on-web-ui / apps / monorail / api / ActivityAPI.js View on Github external
return new Promise(function (resolve, reject) {
      http.patch(API + 'activities/' + id)
        .accept('json')
        .type('json')
        .send(body)
        .end((err, res) => {
          if (err) { return reject(err); }
          resolve(res && res.body);
        });
    });
  },
github virtool / virtool / client / src / js / subtraction / api.js View on Github external
export const update = ({ subtractionId, nickname }) =>
    Request.patch(`/api/subtractions/${subtractionId}`).send({ nickname });