How to use the superagent.put 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 jsonresume / resume-cli / lib / settings.js View on Github external
function changeTheme(themeCredentials) {
    var spinner = new Spinner('changing theme...');
    spinner.setSpinnerString('/-\\');
    spinner.start();
    request
        .put(registryServer + '/resume')
        .send(themeCredentials)
        .set('X-API-Key', 'foobar')
        .set('Accept', 'application/json')
        .end(function(error, res) {
            spinner.stop();
            // console.log(error, res);
            // cannot read property of null
            if (error && error.code === 'ENOTFOUND') {
                console.log('\nThere has been an error publishing your resume.'.red);
                console.log('Please check your network connection.'.cyan);
                process.exit();
                return;
            } else if (error || res.body.message === 'ERRORRRSSSS') {
                console.log(error, res.body.message);
                console.log('\nThere has been an error publishing your resume.'.red);
github auth0 / wt-cli / lib / webtaskCreator.js View on Github external
function putWebtask(profile, args, codeOrUrl) {
        if (profile.openid) {
            // The POST /api/tokens/issue is not supported with auth v2,
            // use PUT /api/webtask/:tenant/:name instead.
            var payload = {};
            if (args.secrets && Object.keys(args.secrets).length > 0) payload.secrets = args.secrets;
            if (args.meta && Object.keys(args.meta).length > 0) payload.meta = args.meta;
            if (args.host) payload.host = args.host;
            payload[(codeOrUrl.indexOf('http://') === 0 || codeOrUrl.indexOf('https://') === 0) ? 'url' : 'code'] = codeOrUrl;

            return Superagent
                .put(`${profile.url}/api/webtask/${profile.container}/${args.name}`)
                .set('Authorization', `Bearer ${profile.token}`)
                .send(payload)
                .ok(res => res.status === 200)
                .then(res => new Sandbox.Webtask(profile, res.body.token, {
                    name: args.name,
                    meta: res.body.meta,
                    webtask_url: res.body.webtask_url,
                }));
        }
        else {
            return profile.create(codeOrUrl, {
                name: args.name,
                merge: args.merge,
                parse: (args.parseBody || args.parse) !== undefined ? +(args.parseBody || args.parse) : undefined,
                secrets: args.secrets,
github Autodesk / machine-collaboration-utility / src / Components / Bots / Settings / index.js View on Github external
updateBotSettings(event) {
    event.preventDefault();

    const endpoint = `/v1/bots/${this.props.bot.settings.uuid}`;
    let update = request.put(endpoint);
    const paramJson = {};
    Object.keys(this.state.settings).forEach((settingKey) => {
      // add the setting if we aren't a player,
      // or if we are a player and the setting is neither "name" nor "endpoint"
      try {
        if (
          this.props.bot.info.connectionType !== 'player' ||
          (settingKey !== 'name' && settingKey !== 'endpoint')
        ) {
          const newValue = event.target[settingKey].value;
          paramJson[settingKey] = newValue;
        }
      } catch (ex) {
        // Value not listed as a part of the input form, don't add it
      }
    });
github MyScienceWork / PolarisOS / app / modules / entities / exporter / controllers / datacite.js View on Github external
if (!publication) {
        Logger.error('[DataCite(post_resource_url)] Publication id does not refer to an existing publication');
        return false;
    }

    const global_config = await ConfigUtils.get_config();
    if (!global_config) {
        Logger.error('[DataCite(post_resource_url)] Unable to find global config');
        return false;
    }

    const pos_base_url = Utils.find_value_with_path(global_config, 'base_url'.split('.'));
    const publication_url = `${pos_base_url}/view/${id}`;

    try {
        const res = await Request.put(`${url}/doi/${doi_prefix}/${doi_suffix}`)
            .auth(username, password)
            .type('text/plain;charset=UTF-8')
            .send(`doi=${doi_prefix}/${doi_suffix}\nurl=${publication_url}`);
        const { status } = res;
        if (status && (status === 201 || status === '201')) {
            return true;
        }
        throw Errors[`DataCite${status}`];
    } catch (err) {
        Logger.error(`[DataCite(post_resource_url)] Error when sending data to the API: ${err.message}`);
        return false;
    }
}
github vpdb / server / src / app / users / user.api.scope.spec.js View on Github external
it('should deny access to user creation through provider', done => {
			request.put('/api/v1/users').with(tokenAll).send({}).end(hlp.status(401, 'invalid scope', done));
		});
		it('should allow access to user details', done => {
github xyfir / accownt / web / components / dashboard / security / OTP.jsx View on Github external
onEnable() {
    request.put('/api/user/security/otp').end((err, res) => {
      if (err) this.props.alert(res.body.message);
      else this.setState(res.body);
    });
  }
github ewnd9 / media-center / frontend / api.js View on Github external
export const put = (_url, body = {}, query) => {
  const url = baseUrl + _url;
  const req = superagent.put(url).send(JSON.stringify(body));

  return fetch(req, url, {
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    query
  });
};
github dk-lan / vue / VueERP / src / utils / HttpClient.js View on Github external
put: (path, query, payload) => new Promise((resolve, reject) => {
        request
            .put(getUrl(path))
            .query(query)
            .send(payload)
            .end((err, res) => {
                if (err) {
                    errorHandler(err)
                    reject(err);
                } else {
                    resolve(res.body);
                }
            });
    }),
github xyfir / accownt / client / components / dashboard / user / security / SMSOTP.jsx View on Github external
if (this.state.verifying) {
      request
        .put('api/dashboard/user/security/phone/verify')
        .send({
          phone: this.refs.phone.value,
          code: this.refs.smsCode.value
        })
        .end((err, res) => {
          this.props.alert(res.body.message);
          this.setState({ verifying: false });
        })
    }
    else {
      const phone = this.refs.phone.value;
      
      request
        .put('api/dashboard/user/security/phone')
        .send({ phone })
        .end((err, res) => {
          if (!err) {
            this.props.alert(res.body.message);

            if (phone && !res.body.error)
              this.setState({ verifying: true });
          }
        });
    }
  }
github wisnuc / appifi / src / fruitmix / station / lib / request.js View on Github external
module.exports.upload = (url, params, fpath, opts, callback) => {
  let req = request.put(url)
  if(params)
    req.send(params)
  if(opts)
    for(let i in opts){
      if (opts.hasOwnProperty(i))
          req.set(i, opts[i])
  }
  try{
    let readable = fs.createReadStream(fpath)
  }catch(e){
    return callback(e)
  }

  let abort = false

  req.on('finish', () => {