diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..0ad676c Binary files /dev/null and b/.DS_Store differ diff --git a/.env b/.env new file mode 100644 index 0000000..bb88c24 --- /dev/null +++ b/.env @@ -0,0 +1,5 @@ +ID = TLGmM57uOhQn8Xhqf2IZ3LwRa +SECRET = 0uEgTaPmGp0uhIWLVLWs9K1jIfK34afN9bihD4f21ZcA9hYg6p + +TOKEN = 836421347693645827-s5iFfii3RW8Y79m8t1MEMQUyOZjRCyh +TOKEN_SECRET = zBGzr4ABkxqK6UzQdWmN1ysD92gQZ44V10w5FLSjE5Ome diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/app.js b/app.js new file mode 100644 index 0000000..b2a5037 --- /dev/null +++ b/app.js @@ -0,0 +1,46 @@ +var express = require('express'); +var path = require('path'); +var favicon = require('serve-favicon'); +var logger = require('morgan'); +var cookieParser = require('cookie-parser'); +var bodyParser = require('body-parser'); + +var index = require('./routes/index'); +var users = require('./routes/users'); + +var app = express(); + +// view engine setup +app.set('views', path.join(__dirname, 'views')); +app.set('view engine', 'ejs'); + +// uncomment after placing your favicon in /public +//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); +app.use(logger('dev')); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: false })); +app.use(cookieParser()); +app.use(express.static(path.join(__dirname, 'public'))); + +app.use('/', index); +app.use('/users', users); + +// catch 404 and forward to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + +// error handler +app.use(function(err, req, res, next) { + // set locals, only providing error in development + res.locals.message = err.message; + res.locals.error = req.app.get('env') === 'development' ? err : {}; + + // render the error page + res.status(err.status || 500); + res.render('error'); +}); + +module.exports = app; diff --git a/bin/www b/bin/www new file mode 100755 index 0000000..c799455 --- /dev/null +++ b/bin/www @@ -0,0 +1,90 @@ +#!/usr/bin/env node + +/** + * Module dependencies. + */ + +var app = require('../app'); +var debug = require('debug')('twatt:server'); +var http = require('http'); + +/** + * Get port from environment and store in Express. + */ + +var port = normalizePort(process.env.PORT || '3000'); +app.set('port', port); + +/** + * Create HTTP server. + */ + +var server = http.createServer(app); + +/** + * Listen on provided port, on all network interfaces. + */ + +server.listen(port); +server.on('error', onError); +server.on('listening', onListening); + +/** + * Normalize a port into a number, string, or false. + */ + +function normalizePort(val) { + var port = parseInt(val, 10); + + if (isNaN(port)) { + // named pipe + return val; + } + + if (port >= 0) { + // port number + return port; + } + + return false; +} + +/** + * Event listener for HTTP server "error" event. + */ + +function onError(error) { + if (error.syscall !== 'listen') { + throw error; + } + + var bind = typeof port === 'string' + ? 'Pipe ' + port + : 'Port ' + port; + + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': + console.error(bind + ' requires elevated privileges'); + process.exit(1); + break; + case 'EADDRINUSE': + console.error(bind + ' is already in use'); + process.exit(1); + break; + default: + throw error; + } +} + +/** + * Event listener for HTTP server "listening" event. + */ + +function onListening() { + var addr = server.address(); + var bind = typeof addr === 'string' + ? 'pipe ' + addr + : 'port ' + addr.port; + debug('Listening on ' + bind); +} diff --git a/helper/helpers.js b/helper/helpers.js new file mode 100644 index 0000000..e3da63a --- /dev/null +++ b/helper/helpers.js @@ -0,0 +1,24 @@ +// var OAuth = require('oauth'); +// +// var oauth = new OAuth.OAuth( +// 'https://api.twitter.com/oauth/request_token', +// 'https://api.twitter.com/oauth/access_token', +// 'TLGmM57uOhQn8Xhqf2IZ3LwRa', +// '0uEgTaPmGp0uhIWLVLWs9K1jIfK34afN9bihD4f21ZcA9hYg6p', +// '1.0A', +// null, +// 'HMAC-SHA1' +// ); +// var getTwit = function () { +// oauth.get( +// 'https://api.twitter.com/1.1/trends/place.json?id=23424977', +// '836421347693645827-s5iFfii3RW8Y79m8t1MEMQUyOZjRCyh', //test user token +// 'zBGzr4ABkxqK6UzQdWmN1ysD92gQZ44V10w5FLSjE5Ome', //test user secret +// function (e, data, res){ +// if (e) console.error(e); +// console.log(require('util').inspect(data)); +// }); +// +// module.exports = { +// getTwit +// } diff --git a/package.json b/package.json new file mode 100644 index 0000000..cbe711a --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "twatt", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "node ./bin/www" + }, + "dependencies": { + "body-parser": "~1.16.0", + "cookie-parser": "~1.4.3", + "debug": "~2.6.0", + "ejs": "~2.5.5", + "express": "~4.14.1", + "morgan": "~1.7.0", + "serve-favicon": "~2.3.2" + } +} diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css new file mode 100644 index 0000000..9453385 --- /dev/null +++ b/public/stylesheets/style.css @@ -0,0 +1,8 @@ +body { + padding: 50px; + font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; +} + +a { + color: #00B7FF; +} diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..f0fcc52 --- /dev/null +++ b/routes/index.js @@ -0,0 +1,32 @@ +var express = require('express'); +var router = express.Router(); +var OAuth = require('oauth'); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.render('index', { title: 'Express' }); +}); + +router.get('/tweet/:q', function(req, res, next){ + var oauth = new OAuth.OAuth( + 'https://api.twitter.com/oauth/request_token', + 'https://api.twitter.com/oauth/access_token', + 'TLGmM57uOhQn8Xhqf2IZ3LwRa', + '0uEgTaPmGp0uhIWLVLWs9K1jIfK34afN9bihD4f21ZcA9hYg6p', + '1.0A', + null, + 'HMAC-SHA1' + ); +oauth.get( + + `https://api.twitter.com/1.1/search/tweets.json?q=${req.params.q}`, + '836421347693645827-s5iFfii3RW8Y79m8t1MEMQUyOZjRCyh', //test user token + 'zBGzr4ABkxqK6UzQdWmN1ysD92gQZ44V10w5FLSjE5Ome', //test user secret + function (e, data, respon){ + if (e) console.error(e); + // console.log(require('util').inspect(data)); + res.send(data) + }); +}) + +module.exports = router; diff --git a/routes/users.js b/routes/users.js new file mode 100644 index 0000000..623e430 --- /dev/null +++ b/routes/users.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET users listing. */ +router.get('/', function(req, res, next) { + res.send('respond with a resource'); +}); + +module.exports = router; diff --git a/views/error.ejs b/views/error.ejs new file mode 100644 index 0000000..7cf94ed --- /dev/null +++ b/views/error.ejs @@ -0,0 +1,3 @@ +

<%= message %>

+

<%= error.status %>

+
<%= error.stack %>
diff --git a/views/index.ejs b/views/index.ejs new file mode 100644 index 0000000..7b7a1d6 --- /dev/null +++ b/views/index.ejs @@ -0,0 +1,11 @@ + + + + <%= title %> + + + +

<%= title %>

+

Welcome to <%= title %>

+ +