Last active
May 30, 2017 14:23
-
-
Save chyld/d57834ba463e57d8345c to your computer and use it in GitHub Desktop.
slack outgoing webhook, quote service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var bodyParser = require("body-parser"); | |
var request = require('request'); | |
var app = express(); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.get('/', function (req, res) { | |
res.send('Hello World!'); | |
}); | |
app.post('/quote', function(req, res){ | |
console.log('req.body:', req.body); | |
var symbol = req.body.text.split(' ')[1]; | |
console.log('symbol:', symbol); | |
var o = { | |
url: 'https://openwhisk.ng.bluemix.net/api/v1/namespaces/chyld_dev/actions/chyld/stock?blocking=true', | |
method: 'post', | |
headers: {authorization: 'Basic ABCD='}, | |
body: {symbol: symbol}, | |
json: true | |
}; | |
console.log('ooo:', o); | |
request(o, function(e, r, b){ | |
console.log('b:',b); | |
console.log('quote:', b.response.result.LastPrice);; | |
res.send({text: b.response.result.Name + ': $' + b.response.result.LastPrice.toFixed(2)}); | |
}); | |
}); | |
app.listen(process.env.PORT, process.env.IP, function () { | |
console.log('EXPRESS: ONLINE'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global whisk */ | |
var request = require('request'); | |
function main(params){ | |
console.log('**********************'); | |
console.log('STOCK: params:', params); | |
var symbol = params.symbol || 'AAPL'; | |
symbol = symbol.toUpperCase(); | |
request({url:'http://dev.markitondemand.com/MODApis/Api/v2/Quote/json?symbol=' + symbol, json:true}, function(err, res, body){ | |
return whisk.done(body); | |
}); | |
return whisk.async(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment