From 40480624c1d0e52b820ac122cd062ae7bce72bfa Mon Sep 17 00:00:00 2001 From: Eksa Date: Wed, 7 Mar 2018 13:20:52 +0700 Subject: [PATCH 1/6] Start the project --- app.js | 13 ++ bin/www | 90 ++++++++++ controllers/twatts.js | 5 + models/twatts.js | 10 ++ package-lock.json | 376 ++++++++++++++++++++++++++++++++++++++++++ package.json | 16 ++ routes/index.js | 9 + routes/twatts.js | 9 + yarn.lock | 310 ++++++++++++++++++++++++++++++++++ 9 files changed, 838 insertions(+) create mode 100644 app.js create mode 100755 bin/www create mode 100644 controllers/twatts.js create mode 100644 models/twatts.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 routes/index.js create mode 100644 routes/twatts.js create mode 100644 yarn.lock diff --git a/app.js b/app.js new file mode 100644 index 0000000..544d05b --- /dev/null +++ b/app.js @@ -0,0 +1,13 @@ +require('dotenv').config(); +var express = require('express'); +var bodyParser = require('body-parser'); + +var app = express(); + +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: false })); + +app.use('/twatts', require('./routes/twatts')); + + +module.exports = app; diff --git a/bin/www b/bin/www new file mode 100755 index 0000000..21a95c6 --- /dev/null +++ b/bin/www @@ -0,0 +1,90 @@ +#!/usr/bin/env node + +/** + * Module dependencies. + */ + +var app = require('../app'); +var debug = require('debug')('twatt-1: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/controllers/twatts.js b/controllers/twatts.js new file mode 100644 index 0000000..db2f893 --- /dev/null +++ b/controllers/twatts.js @@ -0,0 +1,5 @@ +const twatts = require('../models/twatts') + +module.exports = { + +} diff --git a/models/twatts.js b/models/twatts.js new file mode 100644 index 0000000..b3523fc --- /dev/null +++ b/models/twatts.js @@ -0,0 +1,10 @@ +const oauth = require('oauth').OAuth + +// console.log(process.env); +var Twitter = new oauth( + 'https://twitter.com/oauth/request_token', 'https://twitter.com/oauth/access_token', + process.env.TOKEN_APPKEY, process.env.TOKEN_APPSECRET, '1.0A', + 'http://localhost:3000/api/twitter/sessions/callback', 'HMAC-SHA1' +) + +module.exports = Twitter diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..9438f0c --- /dev/null +++ b/package-lock.json @@ -0,0 +1,376 @@ +{ + "name": "twatt-1", + "version": "0.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "accepts": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", + "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", + "requires": { + "mime-types": "2.1.18", + "negotiator": "0.6.1" + } + }, + "array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" + }, + "body-parser": { + "version": "1.18.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", + "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=", + "requires": { + "bytes": "3.0.0", + "content-type": "1.0.4", + "debug": "2.6.9", + "depd": "1.1.2", + "http-errors": "1.6.2", + "iconv-lite": "0.4.19", + "on-finished": "2.3.0", + "qs": "6.5.1", + "raw-body": "2.3.2", + "type-is": "1.6.16" + } + }, + "bytes": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", + "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" + }, + "content-disposition": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", + "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" + }, + "content-type": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" + }, + "cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" + }, + "cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + }, + "destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" + }, + "encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, + "etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" + }, + "express": { + "version": "4.15.5", + "resolved": "https://registry.npmjs.org/express/-/express-4.15.5.tgz", + "integrity": "sha1-ZwI1ypWYiQpa6BcLg9tyK4Qu2Sc=", + "requires": { + "accepts": "1.3.5", + "array-flatten": "1.1.1", + "content-disposition": "0.5.2", + "content-type": "1.0.4", + "cookie": "0.3.1", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "1.1.2", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "etag": "1.8.1", + "finalhandler": "1.0.6", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "1.1.2", + "on-finished": "2.3.0", + "parseurl": "1.3.2", + "path-to-regexp": "0.1.7", + "proxy-addr": "1.1.5", + "qs": "6.5.0", + "range-parser": "1.2.0", + "send": "0.15.6", + "serve-static": "1.12.6", + "setprototypeof": "1.0.3", + "statuses": "1.3.1", + "type-is": "1.6.16", + "utils-merge": "1.0.0", + "vary": "1.1.2" + }, + "dependencies": { + "qs": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.0.tgz", + "integrity": "sha512-fjVFjW9yhqMhVGwRExCXLhJKrLlkYSaxNWdyc9rmHlrVZbk35YHH312dFd7191uQeXkI3mKLZTIbSvIeFwFemg==" + }, + "statuses": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", + "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" + } + } + }, + "finalhandler": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.6.tgz", + "integrity": "sha1-AHrqM9Gk0+QgF/YkhIrVjSEvgU8=", + "requires": { + "debug": "2.6.9", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "on-finished": "2.3.0", + "parseurl": "1.3.2", + "statuses": "1.3.1", + "unpipe": "1.0.0" + }, + "dependencies": { + "statuses": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", + "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" + } + } + }, + "forwarded": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", + "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" + }, + "fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" + }, + "http-errors": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", + "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=", + "requires": { + "depd": "1.1.1", + "inherits": "2.0.3", + "setprototypeof": "1.0.3", + "statuses": "1.4.0" + }, + "dependencies": { + "depd": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", + "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" + } + } + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "ipaddr.js": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.4.0.tgz", + "integrity": "sha1-KWrKh4qCGBbluF0KKFqZvP9FgvA=" + }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" + }, + "mime": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz", + "integrity": "sha1-EV+eO2s9rylZmDyzjxSaLUDrXVM=" + }, + "mime-db": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz", + "integrity": "sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==" + }, + "mime-types": { + "version": "2.1.18", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz", + "integrity": "sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==", + "requires": { + "mime-db": "1.33.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "negotiator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", + "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" + }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "requires": { + "ee-first": "1.1.1" + } + }, + "parseurl": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", + "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" + }, + "path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" + }, + "proxy-addr": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.5.tgz", + "integrity": "sha1-ccDuOxAt4/IC87ZPYI0XP8uhqRg=", + "requires": { + "forwarded": "0.1.2", + "ipaddr.js": "1.4.0" + } + }, + "qs": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", + "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" + }, + "range-parser": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", + "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" + }, + "raw-body": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", + "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=", + "requires": { + "bytes": "3.0.0", + "http-errors": "1.6.2", + "iconv-lite": "0.4.19", + "unpipe": "1.0.0" + } + }, + "send": { + "version": "0.15.6", + "resolved": "https://registry.npmjs.org/send/-/send-0.15.6.tgz", + "integrity": "sha1-IPI6nJJbdiq4JwX+L52yUqzkfjQ=", + "requires": { + "debug": "2.6.9", + "depd": "1.1.2", + "destroy": "1.0.4", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "etag": "1.8.1", + "fresh": "0.5.2", + "http-errors": "1.6.2", + "mime": "1.3.4", + "ms": "2.0.0", + "on-finished": "2.3.0", + "range-parser": "1.2.0", + "statuses": "1.3.1" + }, + "dependencies": { + "statuses": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", + "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" + } + } + }, + "serve-static": { + "version": "1.12.6", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.12.6.tgz", + "integrity": "sha1-uXN3P2NEmTTaVOW+ul4x2fQhFXc=", + "requires": { + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "parseurl": "1.3.2", + "send": "0.15.6" + } + }, + "setprototypeof": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", + "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" + }, + "statuses": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", + "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" + }, + "type-is": { + "version": "1.6.16", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz", + "integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==", + "requires": { + "media-typer": "0.3.0", + "mime-types": "2.1.18" + } + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" + }, + "utils-merge": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz", + "integrity": "sha1-ApT7kiu5N1FTVBxPcJYjHyh8ivg=" + }, + "vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..dbf252b --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "twatt-1", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "node ./bin/www", + "dev": "nodemon ./bin/www" + }, + "dependencies": { + "body-parser": "~1.18.2", + "cors": "^2.8.4", + "dotenv": "^5.0.1", + "express": "~4.15.5", + "oauth": "^0.9.15" + } +} diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..ecca96a --- /dev/null +++ b/routes/index.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.render('index', { title: 'Express' }); +}); + +module.exports = router; diff --git a/routes/twatts.js b/routes/twatts.js new file mode 100644 index 0000000..623e430 --- /dev/null +++ b/routes/twatts.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/yarn.lock b/yarn.lock new file mode 100644 index 0000000..5c358f3 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,310 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +accepts@~1.3.3: + version "1.3.5" + resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.5.tgz#eb777df6011723a3b14e8a72c0805c8e86746bd2" + dependencies: + mime-types "~2.1.18" + negotiator "0.6.1" + +array-flatten@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2" + +body-parser@~1.18.2: + version "1.18.2" + resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.18.2.tgz#87678a19d84b47d859b83199bd59bce222b10454" + dependencies: + bytes "3.0.0" + content-type "~1.0.4" + debug "2.6.9" + depd "~1.1.1" + http-errors "~1.6.2" + iconv-lite "0.4.19" + on-finished "~2.3.0" + qs "6.5.1" + raw-body "2.3.2" + type-is "~1.6.15" + +bytes@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048" + +content-disposition@0.5.2: + version "0.5.2" + resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.2.tgz#0cf68bb9ddf5f2be7961c3a85178cb85dba78cb4" + +content-type@~1.0.2, content-type@~1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b" + +cookie-signature@1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" + +cookie@0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" + +cors@^2.8.4: + version "2.8.4" + resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.4.tgz#2bd381f2eb201020105cd50ea59da63090694686" + dependencies: + object-assign "^4" + vary "^1" + +debug@2.6.9: + version "2.6.9" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + dependencies: + ms "2.0.0" + +depd@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.1.tgz#5783b4e1c459f06fa5ca27f991f3d06e7a310359" + +depd@~1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" + +destroy@~1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" + +dotenv@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-5.0.1.tgz#a5317459bd3d79ab88cff6e44057a6a3fbb1fcef" + +ee-first@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" + +encodeurl@~1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" + +escape-html@~1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" + +etag@~1.8.0, etag@~1.8.1: + version "1.8.1" + resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" + +express@~4.15.5: + version "4.15.5" + resolved "https://registry.yarnpkg.com/express/-/express-4.15.5.tgz#670235ca9598890a5ae8170b83db722b842ed927" + dependencies: + accepts "~1.3.3" + array-flatten "1.1.1" + content-disposition "0.5.2" + content-type "~1.0.2" + cookie "0.3.1" + cookie-signature "1.0.6" + debug "2.6.9" + depd "~1.1.1" + encodeurl "~1.0.1" + escape-html "~1.0.3" + etag "~1.8.0" + finalhandler "~1.0.6" + fresh "0.5.2" + merge-descriptors "1.0.1" + methods "~1.1.2" + on-finished "~2.3.0" + parseurl "~1.3.1" + path-to-regexp "0.1.7" + proxy-addr "~1.1.5" + qs "6.5.0" + range-parser "~1.2.0" + send "0.15.6" + serve-static "1.12.6" + setprototypeof "1.0.3" + statuses "~1.3.1" + type-is "~1.6.15" + utils-merge "1.0.0" + vary "~1.1.1" + +finalhandler@~1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.0.6.tgz#007aea33d1a4d3e42017f624848ad58d212f814f" + dependencies: + debug "2.6.9" + encodeurl "~1.0.1" + escape-html "~1.0.3" + on-finished "~2.3.0" + parseurl "~1.3.2" + statuses "~1.3.1" + unpipe "~1.0.0" + +forwarded@~0.1.0: + version "0.1.2" + resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84" + +fresh@0.5.2: + version "0.5.2" + resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" + +http-errors@1.6.2, http-errors@~1.6.2: + version "1.6.2" + resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.2.tgz#0a002cc85707192a7e7946ceedc11155f60ec736" + dependencies: + depd "1.1.1" + inherits "2.0.3" + setprototypeof "1.0.3" + statuses ">= 1.3.1 < 2" + +iconv-lite@0.4.19: + version "0.4.19" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b" + +inherits@2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + +ipaddr.js@1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.4.0.tgz#296aca878a821816e5b85d0a285a99bcff4582f0" + +media-typer@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" + +merge-descriptors@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" + +methods@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" + +mime-db@~1.33.0: + version "1.33.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.33.0.tgz#a3492050a5cb9b63450541e39d9788d2272783db" + +mime-types@~2.1.18: + version "2.1.18" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.18.tgz#6f323f60a83d11146f831ff11fd66e2fe5503bb8" + dependencies: + mime-db "~1.33.0" + +mime@1.3.4: + version "1.3.4" + resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53" + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + +negotiator@0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9" + +oauth@^0.9.15: + version "0.9.15" + resolved "https://registry.yarnpkg.com/oauth/-/oauth-0.9.15.tgz#bd1fefaf686c96b75475aed5196412ff60cfb9c1" + +object-assign@^4: + version "4.1.1" + resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" + +on-finished@~2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947" + dependencies: + ee-first "1.1.1" + +parseurl@~1.3.1, parseurl@~1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.2.tgz#fc289d4ed8993119460c156253262cdc8de65bf3" + +path-to-regexp@0.1.7: + version "0.1.7" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" + +proxy-addr@~1.1.5: + version "1.1.5" + resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-1.1.5.tgz#71c0ee3b102de3f202f3b64f608d173fcba1a918" + dependencies: + forwarded "~0.1.0" + ipaddr.js "1.4.0" + +qs@6.5.0: + version "6.5.0" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.0.tgz#8d04954d364def3efc55b5a0793e1e2c8b1e6e49" + +qs@6.5.1: + version "6.5.1" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8" + +range-parser@~1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e" + +raw-body@2.3.2: + version "2.3.2" + resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.2.tgz#bcd60c77d3eb93cde0050295c3f379389bc88f89" + dependencies: + bytes "3.0.0" + http-errors "1.6.2" + iconv-lite "0.4.19" + unpipe "1.0.0" + +send@0.15.6: + version "0.15.6" + resolved "https://registry.yarnpkg.com/send/-/send-0.15.6.tgz#20f23a9c925b762ab82705fe2f9db252ace47e34" + dependencies: + debug "2.6.9" + depd "~1.1.1" + destroy "~1.0.4" + encodeurl "~1.0.1" + escape-html "~1.0.3" + etag "~1.8.1" + fresh "0.5.2" + http-errors "~1.6.2" + mime "1.3.4" + ms "2.0.0" + on-finished "~2.3.0" + range-parser "~1.2.0" + statuses "~1.3.1" + +serve-static@1.12.6: + version "1.12.6" + resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.12.6.tgz#b973773f63449934da54e5beba5e31d9f4211577" + dependencies: + encodeurl "~1.0.1" + escape-html "~1.0.3" + parseurl "~1.3.2" + send "0.15.6" + +setprototypeof@1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.0.3.tgz#66567e37043eeb4f04d91bd658c0cbefb55b8e04" + +"statuses@>= 1.3.1 < 2": + version "1.4.0" + resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.4.0.tgz#bb73d446da2796106efcc1b601a253d6c46bd087" + +statuses@~1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e" + +type-is@~1.6.15: + version "1.6.16" + resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.16.tgz#f89ce341541c672b25ee7ae3c73dee3b2be50194" + dependencies: + media-typer "0.3.0" + mime-types "~2.1.18" + +unpipe@1.0.0, unpipe@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" + +utils-merge@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.0.tgz#0294fb922bb9375153541c4f7096231f287c8af8" + +vary@^1, vary@~1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" From f16d4687d6515e4ce444c1c682497bee3e26c8b3 Mon Sep 17 00:00:00 2001 From: Eksa Date: Wed, 7 Mar 2018 13:45:06 +0700 Subject: [PATCH 2/6] Release profile --- app.js | 2 +- controllers/twatts.js | 13 +++++++++++-- models/twatts.js | 3 +-- routes/twatts.js | 6 ++---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index 544d05b..a5e8c5e 100644 --- a/app.js +++ b/app.js @@ -7,7 +7,7 @@ var app = express(); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); -app.use('/twatts', require('./routes/twatts')); +app.use('/api/twatts', require('./routes/twatts')); module.exports = app; diff --git a/controllers/twatts.js b/controllers/twatts.js index db2f893..55cff3f 100644 --- a/controllers/twatts.js +++ b/controllers/twatts.js @@ -1,5 +1,14 @@ -const twatts = require('../models/twatts') +const Twitter = require('../models/twatts') module.exports = { - + twattProfile: (req, res) => { + Twitter.get( + 'https://api.twitter.com/1.1/account/verify_credentials.json', + process.env.TOKEN_USERKEY, process.env.TOKEN_USERSECRET, + (err, data, result) => { + if (err) { res.status(400).json(err) } + else { res.status(200).send(JSON.parse(data)) } + } + ) + } } diff --git a/models/twatts.js b/models/twatts.js index b3523fc..f8eea22 100644 --- a/models/twatts.js +++ b/models/twatts.js @@ -1,10 +1,9 @@ const oauth = require('oauth').OAuth -// console.log(process.env); var Twitter = new oauth( 'https://twitter.com/oauth/request_token', 'https://twitter.com/oauth/access_token', process.env.TOKEN_APPKEY, process.env.TOKEN_APPSECRET, '1.0A', - 'http://localhost:3000/api/twitter/sessions/callback', 'HMAC-SHA1' + null, 'HMAC-SHA1' ) module.exports = Twitter diff --git a/routes/twatts.js b/routes/twatts.js index 623e430..d13b33a 100644 --- a/routes/twatts.js +++ b/routes/twatts.js @@ -1,9 +1,7 @@ var express = require('express'); var router = express.Router(); +var { twattProfile } = require('../controllers/twatts') -/* GET users listing. */ -router.get('/', function(req, res, next) { - res.send('respond with a resource'); -}); +router.get('/profile', twattProfile) module.exports = router; From 1ef3ab08eba5639eed9549b96cfb7887d8ac20a0 Mon Sep 17 00:00:00 2001 From: Eksa Date: Wed, 7 Mar 2018 13:50:52 +0700 Subject: [PATCH 3/6] Release Timeline Home and User --- controllers/twatts.js | 22 ++++++++++++++++++++++ routes/twatts.js | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/controllers/twatts.js b/controllers/twatts.js index 55cff3f..d7db38c 100644 --- a/controllers/twatts.js +++ b/controllers/twatts.js @@ -10,5 +10,27 @@ module.exports = { else { res.status(200).send(JSON.parse(data)) } } ) + }, + + twattTimeHome: (req, res) => { + Twitter.get( + 'https://api.twitter.com/1.1/statuses/home_timeline.json', + process.env.TOKEN_USERKEY, process.env.TOKEN_USERSECRET, + (err, data, result) => { + if (err) { res.status(400).json(err) } + else { res.status(200).send(JSON.parse(data)) } + } + ) + }, + + twattTimeUser: (req, res) => { + Twitter.get( + 'https://api.twitter.com/1.1/statuses/user_timeline.json', + process.env.TOKEN_USERKEY, process.env.TOKEN_USERSECRET, + (err, data, result) => { + if (err) { res.status(400).json(err) } + else { res.status(200).send(JSON.parse(data)) } + } + ) } } diff --git a/routes/twatts.js b/routes/twatts.js index d13b33a..9219129 100644 --- a/routes/twatts.js +++ b/routes/twatts.js @@ -1,7 +1,9 @@ var express = require('express'); var router = express.Router(); -var { twattProfile } = require('../controllers/twatts') +var { twattProfile, twattTimeHome, twattTimeUser } = require('../controllers/twatts') router.get('/profile', twattProfile) +router.get('/timelinehome', twattTimeHome) +router.get('/timelineuser', twattTimeUser) module.exports = router; From 56614048015660219eb80e8ac40be239c5a1eb9b Mon Sep 17 00:00:00 2001 From: Eksa Date: Wed, 7 Mar 2018 13:56:10 +0700 Subject: [PATCH 4/6] Release Search --- controllers/twatts.js | 17 ++++++++++++++--- routes/twatts.js | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/controllers/twatts.js b/controllers/twatts.js index d7db38c..6423599 100644 --- a/controllers/twatts.js +++ b/controllers/twatts.js @@ -6,7 +6,7 @@ module.exports = { 'https://api.twitter.com/1.1/account/verify_credentials.json', process.env.TOKEN_USERKEY, process.env.TOKEN_USERSECRET, (err, data, result) => { - if (err) { res.status(400).json(err) } + if (err) { res.status(400).send(JSON.parse(err.message)) } else { res.status(200).send(JSON.parse(data)) } } ) @@ -17,7 +17,7 @@ module.exports = { 'https://api.twitter.com/1.1/statuses/home_timeline.json', process.env.TOKEN_USERKEY, process.env.TOKEN_USERSECRET, (err, data, result) => { - if (err) { res.status(400).json(err) } + if (err) { res.status(400).send(JSON.parse(err.message)) } else { res.status(200).send(JSON.parse(data)) } } ) @@ -28,7 +28,18 @@ module.exports = { 'https://api.twitter.com/1.1/statuses/user_timeline.json', process.env.TOKEN_USERKEY, process.env.TOKEN_USERSECRET, (err, data, result) => { - if (err) { res.status(400).json(err) } + if (err) { res.status(400).send(JSON.parse(err.message)) } + else { res.status(200).send(JSON.parse(data)) } + } + ) + }, + + twattSearch: (req, res) => { + Twitter.get( + 'https://api.twitter.com/1.1/search/tweets.json?q=' + req.query.search, + process.env.TOKEN_USERKEY, process.env.TOKEN_USERSECRET, + (err, data, result) => { + if (err) { res.status(400).send(JSON.parse(err.message)) } else { res.status(200).send(JSON.parse(data)) } } ) diff --git a/routes/twatts.js b/routes/twatts.js index 9219129..9813ea7 100644 --- a/routes/twatts.js +++ b/routes/twatts.js @@ -1,9 +1,10 @@ var express = require('express'); var router = express.Router(); -var { twattProfile, twattTimeHome, twattTimeUser } = require('../controllers/twatts') +var { twattProfile, twattTimeHome, twattTimeUser, twattSearch } = require('../controllers/twatts') router.get('/profile', twattProfile) router.get('/timelinehome', twattTimeHome) router.get('/timelineuser', twattTimeUser) +router.get('/search', twattSearch) module.exports = router; From 92f43d7921ea79bd7bb6ff4f2d42868981646f2c Mon Sep 17 00:00:00 2001 From: Eksa Date: Wed, 7 Mar 2018 14:15:04 +0700 Subject: [PATCH 5/6] Release post tweet --- controllers/twatts.js | 11 +++++++++++ routes/twatts.js | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/controllers/twatts.js b/controllers/twatts.js index 6423599..4139d6c 100644 --- a/controllers/twatts.js +++ b/controllers/twatts.js @@ -43,5 +43,16 @@ module.exports = { else { res.status(200).send(JSON.parse(data)) } } ) + }, + + twattPost: (req, res) => { + Twitter.post( + 'https://api.twitter.com/1.1/statuses/update.json', + process.env.TOKEN_USERKEY, process.env.TOKEN_USERSECRET, { 'status' : req.body.status }, + (err, data, result) => { + if (err) { res.status(400).send(JSON.parse(err.message)) } + else { res.status(200).send(JSON.parse(data)) } + } + ) } } diff --git a/routes/twatts.js b/routes/twatts.js index 9813ea7..ae24fa7 100644 --- a/routes/twatts.js +++ b/routes/twatts.js @@ -1,10 +1,11 @@ var express = require('express'); var router = express.Router(); -var { twattProfile, twattTimeHome, twattTimeUser, twattSearch } = require('../controllers/twatts') +var { twattProfile, twattTimeHome, twattTimeUser, twattSearch, twattPost } = require('../controllers/twatts') router.get('/profile', twattProfile) router.get('/timelinehome', twattTimeHome) router.get('/timelineuser', twattTimeUser) router.get('/search', twattSearch) +router.post('/post', twattPost) module.exports = router; From ebe86c3f48231248725eccc18e0b725e63b5f163 Mon Sep 17 00:00:00 2001 From: Eksa Date: Wed, 7 Mar 2018 14:24:24 +0700 Subject: [PATCH 6/6] Update ReadMe --- README.md | 21 +++++++++++++++++++++ controllers/twatts.js | 2 +- routes/twatts.js | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b9c09e3..c7d8d54 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,23 @@ # twatt oauth twitter + +### Route List +List of twatts in routes: + +| Route | HTTP | Description | +| ------------------------- | ------ | -------------------- | +| /api/twatts/profile | GET | Get profile user | +| /api/twatts/timelinehome | GET | Get home timeline | +| /api/twatts/timelineuser | GET | Get user timeline | +| /api/twatts/search | GET | Search a tweet | +| /api/twatts/newpost | POST | Post tweet status | + + +### Usage +``` +yarn install +yarn run dev +``` + + +Access API `http://localhost:3000/api/twatts` diff --git a/controllers/twatts.js b/controllers/twatts.js index 4139d6c..de9666c 100644 --- a/controllers/twatts.js +++ b/controllers/twatts.js @@ -45,7 +45,7 @@ module.exports = { ) }, - twattPost: (req, res) => { + twattNewPost: (req, res) => { Twitter.post( 'https://api.twitter.com/1.1/statuses/update.json', process.env.TOKEN_USERKEY, process.env.TOKEN_USERSECRET, { 'status' : req.body.status }, diff --git a/routes/twatts.js b/routes/twatts.js index ae24fa7..438ffa1 100644 --- a/routes/twatts.js +++ b/routes/twatts.js @@ -1,11 +1,11 @@ var express = require('express'); var router = express.Router(); -var { twattProfile, twattTimeHome, twattTimeUser, twattSearch, twattPost } = require('../controllers/twatts') +var { twattProfile, twattTimeHome, twattTimeUser, twattSearch, twattNewPost } = require('../controllers/twatts') router.get('/profile', twattProfile) router.get('/timelinehome', twattTimeHome) router.get('/timelineuser', twattTimeUser) router.get('/search', twattSearch) -router.post('/post', twattPost) +router.post('/newpost', twattNewPost) module.exports = router;