router.get("/", function(request, response) { var query = request.query.query; var watchaApiUrl = "https://watcha.net/home/news.json?page=1&per=20"; httpRequest(watchaApiUrl, function(error, httpResponse, body) { var data = JSON.parse(body); var newsItems = data.news; if (query) { var matchedNewsItems = []; newsItems.forEach(function(newsItem) { if (newsItem.title.indexOf(query) > -1) { matchedNewsItems.push(newsItem); } }); newsItems = matchedNewsItems; } return response.render("watcha", {newsItems: newsItems, query: query}); }); });
function sendGenericMessage(sender, messageData) { httpRequest({ url: 'https://graph.facebook.com/v2.6/me/messages', qs: { access_token: FACEBOOK_PAGE_ACCESS_TOKEN }, method: 'POST', json: { recipient: { id: sender }, message: messageData, } }, function(error, response, body) { if (error) { console.log('Error sending message: ', error); } else if (response.body.error) { console.log('Error: ', response.body.error); } }); }
function invokeDmrHttp(op, port) { return new Promise(function(fulfil, reject) { httpRequest({ method: 'POST', url: 'http://localhost:' + port + '/rest/v2', auth: { user: 'admin', pass: 'mypassword', sendImmediately: false }, headers: { 'Content-Type' : 'application/json' }, body: JSON.stringify(op) }, function(error, response, body) { if (!error && response.statusCode == 200) { fulfil(JSON.parse(body)); } else { reject(util.format('Error (%s), body (%s), response(%s)', error, body, JSON.stringify(response))); } }); }); }
function processLocation(sender, coords) { httpRequest({ url: BART_API_BASE + '/station/' + coords.lat + '/' + coords.long, method: 'GET'
function invokeDmrHttpGet(opUrl, port) { return new Promise(function(fulfil, reject) { httpRequest({ method: 'GET', url: 'http://localhost:' + port + '/rest/v2' + opUrl, auth: { user: 'admin', pass: 'mypassword', sendImmediately: false }, headers: { 'Content-Type' : 'application/json' } }, function(error, response, body) { if (!error && response.statusCode == 200) { var resp = ""; if (body) { resp = JSON.parse(body); } fulfil(resp); } else { reject(util.format('Error (%s), body (%s), response(%s)', error, body, JSON.stringify(response))); } }); }); }
httpRequest(url, function(error, httpResponse, body) { var data = JSON.parse(body); var newsItems = data.news;
httpRequest(options, function(error, response, body) { httpRequest( "https://www.googleapis.com/oauth2/v3/userinfo?access_token=" + tokens.access_token,
sendTextMessage(sender, respText.substring(26)); } else if (reqText.indexOf('stations') > -1) { httpRequest({ url: BART_API_BASE + '/stations', method: 'GET' stationCode = stationCode.trim(); httpRequest({ url: BART_API_BASE + '/departures/' + stationCode, method: 'GET' httpRequest({ url: BART_API_BASE + '/elevatorStatus', method: 'GET' }); } else if (reqText.indexOf('status') > -1) { httpRequest({ url: BART_API_BASE + '/status', method: 'GET' status = JSON.parse(body); httpRequest({ url: BART_API_BASE + '/serviceAnnouncements', method: 'GET'
function sendTextMessage(sender, text) { var messageData = { text: text }; httpRequest({ url: 'https://graph.facebook.com/v2.6/me/messages', qs: { access_token: FACEBOOK_PAGE_ACCESS_TOKEN }, method: 'POST', json: { recipient: { id: sender }, message: messageData, } }, function(error, response, body) { if (error) { console.log('Error sending message: ', error); } else if (response.body.error) { console.log('Error: ', response.body.error); } }); }