Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ID = TLGmM57uOhQn8Xhqf2IZ3LwRa
SECRET = 0uEgTaPmGp0uhIWLVLWs9K1jIfK34afN9bihD4f21ZcA9hYg6p

TOKEN = 836421347693645827-s5iFfii3RW8Y79m8t1MEMQUyOZjRCyh
TOKEN_SECRET = zBGzr4ABkxqK6UzQdWmN1ysD92gQZ44V10w5FLSjE5Ome
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
46 changes: 46 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -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;
90 changes: 90 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -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);
}
24 changes: 24 additions & 0 deletions helper/helpers.js
Original file line number Diff line number Diff line change
@@ -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
// }
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}

a {
color: #00B7FF;
}
32 changes: 32 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 9 additions & 0 deletions routes/users.js
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions views/error.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1><%= message %></h1>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>
11 changes: 11 additions & 0 deletions views/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1><%= title %></h1>
<p>Welcome to <%= title %></p>
</body>
</html>