upload_button.addEventListener('click', function() { upload_button.disabled = true; var button_text = upload_button.innerHTML; upload_button.innerHTML = 'uploading...'; var imgUrl = document.querySelector('#target').getAttribute('src'); var img_file = imgUrl.split(',')[1]; var options = { url: imgur.api, method: 'post', headers: { Authorization: 'Client-ID ' + imgur.client, 'Content-Type': 'application/x-www-form-urlencoded' }, body: qs.stringify({ type: 'base64', image: img_file }) } request(options, function(error, res, body) { upload_button.disabled = false; upload_button.innerHTML = button_text; var data = JSON.parse(body).data; // add to dom var link_box = document.createElement('input'); link_box.setAttribute('type', 'text'); link_box.setAttribute('autofocus', true); link_box.value = data.link; document.querySelector('#share_link').appendChild(link_box); }) });
getData() { request(this.props.url + '/messages?branch_id=' + this.state.branchID, (err, res, body) => { this.setState({ messages: JSON.parse(body) }); }); }
return new Promise((resolve, reject) => { path = path.replace(/^\/+/, ''); method = method.toUpperCase(); const options = { method, url: `${urlBase}/${path}`, }; console.log(`${urlBase}/${path}`); if (method === 'GET' || method === 'HEAD') { options.qs = data; } else { options.form = data; } browserRequest(options, (err, res, body) => { if (err) { reject(err); } else { let data; try { data = JSON.parse(body.toString()); } catch (err) { return reject(new Error('parse JSON data error: ' + err.message)); } if (data.error) { reject(data.error); } else { resolve(data.result); } } }); });
componentDidMount: function(){ console.log(' R D S . Z o n e '); const self = this; request({ type: 'GET', url: 'http://www.apilayer.net/api/live?access_key=d537bc8370bc38ee7109e2c7670449fd&format=1¤cies=EUR', json: true }, function(err, res, body){ if (err){ console.warn(err); throw new Err(err); } else{ const data = self.setState({ exchange: { one: '$1', two: '€' + body.quotes.USDEUR.toFixed(4) }, USD: 1, EUR: body.quotes.USDEUR.toFixed(4) }); } }); },
request.couch = function(options, callback) { if(typeof options === 'string') options = {'uri':options} // Just use the request API to do JSON. options.json = true if(options.body) options.json = options.body delete options.body callback = callback || noop var xhr = request(options, couch_handler) return xhr function couch_handler(er, resp, body) { if(er) return callback(er, resp, body) if((resp.statusCode < 200 || resp.statusCode > 299) && body.error) { // The body is a Couch JSON object indicating the error. er = new Error('CouchDB error: ' + (body.error.reason || body.error.error)) for (var key in body) er[key] = body[key] return callback(er, resp, body); } return callback(er, resp, body); } }
var ajax = function (action, body, method, callback) { var options = { url: "/" + action, method: method || 'GET', json: body || true } var body_error = { "status": "failed" } request(options, function(err, res, body) { console.log(callback) if (err) return callback(err) if (res.statusCode >= 400) return (typeof body !== 'object' ? callback(body_error, body) : callback(body)) if (body === '' || body === undefined) return callback(null, {}) else if (typeof body !== 'object') return callback(body_error, body) else callback(null, body) }) }
handleClick(e) { //the message clicked from the chatbox const branchID = e.target.textContent; const username = this.readCookie('username').split('%20').join(''); let objToSend = JSON.stringify({ username: username, newBranchID: e.target.textContent, oldBranchID: this.state.branchID }); //receive new messages from table related to message clicked from chatbox request({method:'POST', url: this.props.url + '/branch', body: objToSend, json:true}, on_response.bind(this)); function on_response(err, res, body) { console.log(branchID); if (err) throw new Error(err); console.log('body from handleClick after clicking msg', body); this.setState({ messages: body, branchID: branchID }); } }
self.cache.get(function(err, cached) { if (err) { self.emit('bundleEnd') return err } var download = [] modules.forEach(function(module) { if (cached[module]) { allBundles += cached[module]['bundle'] packages.push(cached[module]['package']) } else { download.push(module) } }) if (download.length === 0) { self.emit('modules', packages) return makeIframe(allBundles) } var body = { "options": { "debug": true }, "dependencies": {} } download.map(function(module) { var version = preferredVersions[module] || 'latest' body.dependencies[module] = version }) request({method: "POST", body: JSON.stringify(body), url: self.cdn + '/multi'}, downloadedModules) })
Sonos.prototype.request = function(endpoint, action, body, responseTag, callback) { debug('Sonos.request(%j, %j, %j, %j, %j)', endpoint, action, body, responseTag, callback); request({ uri: 'http://' + this.host + ':' + this.port + endpoint, method: 'POST', headers: { 'SOAPAction': action, 'Content-type': 'text/xml; charset=utf8' }, body: withinEnvelope(body), timeout: 5 * 1000 }, function(err, res, body) { if (err) return callback(err); if (res.statusCode !== 200) return callback (new Error('HTTP response code ' + res.statusCode + ' for ' + action)); (new xml2js.Parser()).parseString(body, function(err, json) { if (err) return callback(err); if(typeof json['s:Envelope']['s:Body'][0]['s:Fault'] !== 'undefined') return callback(json['s:Envelope']['s:Body'][0]['s:Fault']); return callback(null, json['s:Envelope']['s:Body'][0][responseTag]); }); }); };
v.$data.mails.forEach(function (mail) { if (mail.status !== 0) { return } request({ method: 'POST', uri: '/users/invitation', headers: { 'X-Csrf-Token': csrfToken }, json: { utf8: '✓', user: { email: mail.value } } }, function (err, response, data) { if (err) { throw err } if (data.success) { mail.status = 1 } else { mail.message = data.errors.email[0] mail.status = -1 } }) })
_postOrPatch: function(method, token, url, options, json, callback) { if (options) { url + '?' + qs.stringify(options); } request({ url: url, method: method, json: json, headers: { 'Authorization': 'Bearer ' + token } }, function(error, response, body) { if (error || response.statusCode !== 200) { if (response.statusCode === 401) { Dispatcher.dispatch({ actionType: Constants.USER_LOGGED_OUT }); } console.log({ message: 'Error making HTTP Request', error: error, statusCode: response.statusCode }); return; } else { callback(body); } }); },
handleGoogleRequest() { request('/oauth2', (err, res, body) => { if (err) throw new Error(err); localStorage.setItem('signedIn', 1); window.location.replace(body); }); }
return new Promise((resolve, reject) => { request(url, function (error, response, body) { if (!error && response.statusCode == 200) { resolve(body); } else { reject(body); } }); });
return dispatch => { request({ method: 'POST', url: '/signup', body: payload, json: true }, (err, res, body) => { dispatch(signup(body)) if (res.status === 200) { var path = '/dashboard/' + body.user.token browserHistory.push(path) } }) }
exports.del = function (path, cb) { request({ method: 'DELETE', uri: path, json: false, timeout: 10000, headers: {token: localStorage.getItem('token')} }, responseHandler.bind({}, cb)) };
return new Promise ((resolve, reject) => { request(options, (err, response) => { if (err) { reject(err) } else { resolve(JSON.parse(response.responseText)) } }) })
var venuesPromise = new Promise(function (resolve, reject) { request('./geojson/processed.venues.json', function (err, res, body) { if (err) { reject(err); } else { resolve(JSON.parse(body)); } }); });
return new Promise((resolve, reject) => { request(options, (err, response, body) => { if(err) { reject(err); } else { resolve(body); } }); });
exports.put = function (path, obj, cb) { request({ method: 'PUT', uri: path, body: obj, json: true, timeout: 10000, headers: {token: localStorage.getItem('token')} }, responseHandler.bind({}, cb)) };
UserService.prototype.getCurrentUser = function(cb) { request({ method: 'GET', url: '/player/me' }, function(err, response, body) { if (err || !(response.statusCode + '').match(/^2/)) { return cb(extractFetchFailureReason(err, response, body)); } cb(null, JSON.parse(body)); }); };
expand: function(url, onComplete) { request( { method:'GET', url:'https://www.googleapis.com/urlshortener/v1/url?shortUrl=' + url, json:true }, function(err, response, body) { onComplete(err, body); }); }
function getMovies(query) { console.log(query) smallspinner.style.visibility = "visible" request("/api/queryMovie/" + query, (err, res, bod) => { if (err) throw err bod = JSON.parse(bod) buildMovieOptions(bod) smallspinner.style.visibility = "hidden" }) }
UserService.prototype.exitUser = function(cb) { request({ method: 'POST', url: '/player/exit' }, function(err, response, body) { if (err || !(response.statusCode + '').match(/^2/)) { return cb(extractFetchFailureReason(err, response, body)); } cb(); }); };
function (next) { request({ url: apiServer + '/api/deploy/' + name, json: true }, function (err, res, json) { if (err) { return next(err) } return next(null, json['id']) }) },
function fetch (name) { selected = name var base = 'https://raw.githubusercontent.com/mikolalysenko/regl/d91f4bef665795f2f74f5854efcc7257ba678c54/example/' var path = base + name + '.js' request(path, function(er, response, body) { body = body.replace('../regl', 'regl') body = body.replace(new RegExp('assets/', 'g'), window.location.origin + '/assets/') editor.setValue(body) }) css(loading, {opacity: 0.7}) css(demo, {display: 'none'}) }
function prepareRefresh(callback) { nextBrowserRefreshUrlParam(); // Re-request the same page from the server to trigger a re-optimization of // the page. This is done because the RaptorJS Optimizer lazily optimizes // a page on the first request. request(document.location.toString(), function(er, response, body) { // We don't care about the response, but we are now ready to // refresh the page styles or images. callback(); }); }
addProperty: function(name, type) { var self = this; var data = {}; data[name] = type; request({ method: "PATCH", url: this.props.url, json: data }, function(err, res, body) { self.props.onChange(); }); },
return new Promise((resolve, reject) => { request( { method: "GET", url: langPath }, (err, response, body) => { if (err || response.status < 200 || response.status >= 300) { reject({err: err, response: response}); return; } resolve(weblateToCounterpart(JSON.parse(body))); }, ); });
function page(postfix, callback) { request({ uri: 'https://api.github.com' + postfix, headers: { Authorization: 'token ' + token }, json: true, crossOrigin: true }, function(err, res, body) { callback(null, body); }); }
short: function(url, onComplete) { request( { method:'POST', url:'https://www.googleapis.com/urlshortener/v1/url', body:'{\"longUrl\": \"' + url + '\" }', json:true }, function(err, response, body) { onComplete(err, body); }); },