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

finishing code #8

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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules
.env
14 changes: 14 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var express = require('express');
var bodyParser = require('body-parser');

var index = require('./routes/index');

var app = express();

app.use('/', index);

app.listen (3000, ()=>{
console.log('app run on port 3000')
})

module.express = app;
15 changes: 15 additions & 0 deletions controller/twatt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const model = require('../models/twats');

module.exports = {
search: (req, res, next)=>{
let username = req.params.search
model.search(username, (data)=>{
res.send(data);
})
},
trend: (req, res, next)=>{
model.trends((data)=>{
res.send(data);
})
}
}
42 changes: 42 additions & 0 deletions models/twats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const OAuth = require('oauth');
require('dotenv').config();

var oauth = new OAuth.OAuth(
'https://api.twitter.com/oauth/request_token',
'https://api.twitter.com/oauth/access_token',
process.env.consumerKey,
process.env.consumerSecret,
'1.0A',
null,
'HMAC-SHA1'
);

module.exports = {
search: (datasearch, callback)=>{
oauth.get(
'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name='+datasearch+'&count=4',
process.env.accessToken,
process.env.accessTokenSecret,
(e, data)=>{
if(e){
console.log(e);
} else {
callback(data)
}
})
},
trends: (callback)=>{
oauth.get(
'https://api.twitter.com/1.1/trends/user_timeline.json',
process.env.accessToken,
process.env.accessTokenSecret,
(e, data)=>{
if(e){
console.log(e);
} else {
callback(data);
}
}
)
}
}
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "twatt-recent",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/DeriKurniawan/twatt-recent.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/DeriKurniawan/twatt-recent/issues"
},
"homepage": "https://github.com/DeriKurniawan/twatt-recent#readme",
"dependencies": {
"body-parser": "^1.17.2",
"dotenv": "^4.0.0",
"express": "^4.15.3",
"nodemon": "^1.11.0",
"oauth": "^0.9.15"
}
}
8 changes: 8 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const router = require('express').Router();
const control = require('../controller/twatt');

router.get('/:search', control.search);

router.get('/trend', control.trend);

module.exports = router;