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

twatt release 4 #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const express = require('express')
const bodyParser = require('body-parser')
const home = require('./routes/home')
const profile = require('./routes/profile')
const search = require('./routes/search')
const app = express()
const PORT = 3000

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

app.use('/home', home)
app.use('/profile', profile)
app.use('/search', search)
// app.get('/', (req, res) => {
// res.status(201).json({
// message: 'Connected!'
// })
// })

// Server
app.listen(PORT, () => {
console.log(`Connected! on port ${PORT}`)
})
57 changes: 57 additions & 0 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const OAuth = require('oauth')
const twatt = new OAuth.OAuth(
'https://api.twitter.com/oauth/request_token',
'https://api.twitter.com/oauth/access_token',
'Kx7I6e3gRrqpQvjDWVyMqKhVe',
'Rio96FKTgxAfcX6dhD0H76RKJdJqtZ7AprLd1TDxHac2bp6DUC',
'1.0A',
null,
'HMAC-SHA1'
);

module.exports = {
home (req, res) {
twatt.get(
'https://api.twitter.com/1.1/statuses/home_timeline.json',
'90120636-cQkBcSWtJa39SnBOowuo2ZrzvpSwymlEXHOA1sElH', //test user token
'0VkZwtF20DDdMmlGSQgBmYSYh6RsW8LLEvIFA1ZBhATSn', //test user secret
function (e, data){
if (e) console.error(e);
res.send(data)
});
},

update (req, res) {
twatt.post(
'https://api.twitter.com/1.1/statuses/update.json?',
'90120636-cQkBcSWtJa39SnBOowuo2ZrzvpSwymlEXHOA1sElH', //test user token
'0VkZwtF20DDdMmlGSQgBmYSYh6RsW8LLEvIFA1ZBhATSn', //test user secret
{status: req.body.status},
function (e, data){
if (e) console.error(e);
res.send(data)
});
},

profile (req, res) {
twatt.get(
'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=cimacim&count=10',
'90120636-cQkBcSWtJa39SnBOowuo2ZrzvpSwymlEXHOA1sElH', //test user token
'0VkZwtF20DDdMmlGSQgBmYSYh6RsW8LLEvIFA1ZBhATSn', //test user secret
function (e, data){
if (e) console.error(e);
res.send(data)
});
},

search (req, res) {
twatt.get(
`https://api.twitter.com/1.1/search/tweets.json?q=${req.params.q}&result_type=mixed&count=4`,
'90120636-cQkBcSWtJa39SnBOowuo2ZrzvpSwymlEXHOA1sElH', //test user token
'0VkZwtF20DDdMmlGSQgBmYSYh6RsW8LLEvIFA1ZBhATSn', //test user secret
function (e, data){
if (e) console.error(e);
res.send(data)
});
}
}
372 changes: 372 additions & 0 deletions package-lock.json
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "twatt",
"version": "1.0.0",
"description": "oauth twitter",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fatimahazzhr/twatt.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/fatimahazzhr/twatt/issues"
},
"homepage": "https://github.com/fatimahazzhr/twatt#readme",
"dependencies": {
"dotenv": "^5.0.1",
"express": "^4.16.2",
"oauth": "^0.9.15"
}
}
12 changes: 12 additions & 0 deletions routes/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const routes = require('express').Router()
const { home, update } = require('../controllers/index')

routes.get('/', home)
routes.post('/', update)
// routes.get('/', (req, res) => {
// res.status(201).json({
// message: 'Connected!'
// })
// })

module.exports = routes;
11 changes: 11 additions & 0 deletions routes/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const routes = require('express').Router()
const { profile } = require('../controllers/index')

routes.get('/', profile)
// routes.get('/', (req, res) => {
// res.status(201).json({
// message: 'Connected!'
// })
// })

module.exports = routes;
11 changes: 11 additions & 0 deletions routes/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const routes = require('express').Router()
const { search } = require('../controllers/index')

routes.get('/:q', search)
// routes.get('/', (req, res) => {
// res.status(201).json({
// message: 'Connected!'
// })
// })

module.exports = routes;