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

Feedback needed #11

Open
wants to merge 2 commits 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.
66 changes: 66 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<title>SOCIAL MEDIA AGGREGATOR</title>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous">
</script>
</head>
<body>
<h1>TWATT</h1>
<h3>Post a tweet</h3>
<input id="tweet" type="text" placeholder="Post a tweet">
<input id="submit" type="submit" onclick="postTweet()">
<h3>Search a tweet</h3>
<input id="search" type="text" placeholder="Search a tweet">
<input id="submit" type="submit" onclick="searchTweet()">
<h3>Get twatt timeline</h3>
<input id="submit" type="submit" value="Get twatt timeline" onclick="getTimeLine()">
<ol class="333"></ol>
<ul class="222"></ul>
</body>
<footer>
<script>
function getTimeLine(){
$.ajax({
type:'GET',
url:'http://localhost:3000/twatt',
success: (res)=>{
res.data.map((v,i,a)=>{
$(".333").prepend(`<li>${v.created_at}................${v.text}</li>`);
})
}
})
}
function postTweet() {
let dataInput = document.getElementById("tweet").value
$.ajax({
type:'POST',
url:'http://localhost:3000/twatt',
data:{status: dataInput},
success: (res)=>{
$('.333').prepend(`<li>${res.data.created_at}................${res.data.text}</li>`);
$('.333').val('')
}
})
}
function searchTweet(){
// console.log(`IN BABY`)
let dataInput = document.getElementById("search").value
console.log(dataInput);
$.ajax({
type:'post',
url:'http://localhost:3000/twatt/search',
data:{search: dataInput},
success: (res)=>{
res.data.statuses.forEach((v,i,a)=>{
$(".222").prepend(`<li>${v.created_at}................${v.text}</li>`);
})
}
})
}
</script>
</footer>
</html>
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "socmed-aggregator",
"version": "1.0.0",
"description": "client server app for your social media with oAuth and Facebook login",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dennish8/socmed-aggregator.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/dennish8/socmed-aggregator/issues"
},
"homepage": "https://github.com/dennish8/socmed-aggregator#readme"
}
2 changes: 2 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# twatt
oauth twitter
46 changes: 46 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');

const index = require('./routes/index');
const twatt = require('./routes/twatt');
const cors = require('cors')
const app = express();



app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(cors());
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('/twatt', twatt);

// 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 server/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);
}
67 changes: 67 additions & 0 deletions server/controllers/twatt.controllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const OAuth = require('oauth').OAuth;
const consumer_key = `UV2dfuLTRrw6IGrBP4qjiruv0`;
const consumer_secret = `YQiRGibmOtFgsJJAPR7JrNBwoZO7kZuxLaDujaAXufnauj4R12`;
const user_token = `971257855746740224-0Fn4fJEmJ1flpVGt20XAb9Ws1oMfG3C`;
const user_secret = `AnNXsfPWqink2xhWC57rk9QbrTbf7XVbdHPH7T4etUhiT`;
const twatt = new OAuth(
'https://api.twitter.com/oauth/request_token',
'https://api.twitter.com/oauth/access_token',
consumer_key, //application consumer key
consumer_secret, //application secret key
'1.0A',
null,
'HMAC-SHA1'
);


class Twatt_Controller{
static get_user_timeline(req,res,next){
twatt.get(
'https://api.twitter.com/1.1/statuses/home_timeline.json',
user_token, //test user token
user_secret, //test user secret
(e, data, res2)=>{
if (e) res.status(500).json(e)
else{
res.status(200).json({
message:'Timeline',
data:JSON.parse(data)
})
}
});
}
static post_a_tweet(req,res,next){
console.log(req.body)
twatt.post(
'https://api.twitter.com/1.1/statuses/update.json',
user_token, //test user token
user_secret, //test user secret
{status:req.body.status} ,
(e, data, res2)=>{
if (e) res.status(500).json(e)
else{
res.status(200).json({
message:'New Tweet',
data:JSON.parse(data)
})
}
});
}
static search_a_tweet(req,res,next){
twatt.get(
`https://api.twitter.com/1.1/search/tweets.json?q=${req.body.search}`,
user_token, //test user token
user_secret, //test user secret
(e, data, res2)=>{
if (e) res.status(500).json(e)
else{
res.status(200).json({
message:'New Tweet',
data:JSON.parse(data)
})
}
});
}
}

module.exports = Twatt_Controller;
Loading