Skip to content

Commit

Permalink
Método POST da API. Separei o arquivo de configuração do Twitter e ma…
Browse files Browse the repository at this point in the history
…is algumas firulas
  • Loading branch information
msfidelis committed Dec 26, 2016
1 parent 67f2522 commit 5799c13
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 50 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions Configs/Json/twitterConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"consumer_key": "",
"consumer_secret": "",
"access_token_key": "",
"access_token_secret": ""
}
1 change: 1 addition & 0 deletions Configs/Token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
17 changes: 17 additions & 0 deletions Configs/TwitterConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

var ConfigFile = "./Json/twitterConfig.json";

/**
* [_createConfig Lê o Json de configuração do Twitter]
* @return {[type]} [description]
*/
function _createConfig() {
var TwitterConfig = require(ConfigFile);
return TwitterConfig;
}

module.exports = {
getConfig : function () {
return _createConfig();
}
}
22 changes: 21 additions & 1 deletion Routes/tweet.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
module.exports = function(app) {

/**
* [tweet GET - Provavelmente este método vai morrer]
* @type {[type]}
*/
app.get("/tweet/newtweet/:tweet?", function (req, res) {
var tweet = req.params.tweet;
var Twitter = require("../Services/Twitter/newTweet");
console.log("Chegou na rota");
Twitter.sendTweet(tweet);
res.send(tweet);
});

/**
* [tweet POST - Vai receber um POST com o parâmetro "Tweet" e vai repassar
* a mensagem para a API do Twitter]
* @type {[type]}
*/
app.post("/tweet/newtweet/", function (req, res) {
var tweet = req.body.tweet;
if (tweet) {
var Twitter = require("../Services/Twitter/newTweet");
Twitter.sendTweet(tweet);
res.send("Seu tweet: " + tweet + " foi enviado!");
} else {
res.send("Não informou o Tweet");
}

});

}
9 changes: 2 additions & 7 deletions Services/Twitter/newTweet.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
var secret = {
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
}

var TwitterClient = require('twitter');

Expand All @@ -13,7 +7,8 @@ var TwitterClient = require('twitter');
* @return {[object]} [Configurações do App do Twitter]
*/
function _getSecret() {
return secret;
var Config = require("../../Configs/TwitterConfig");
return Config.getConfig();
}

module.exports = {
Expand Down
42 changes: 0 additions & 42 deletions Services/tweet.js

This file was deleted.

5 changes: 5 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ var bodyParser = require('body-parser');
var load = require('express-load')
var app = express();

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

load('Models')
.then('Routes')
.into(app);
Expand Down

0 comments on commit 5799c13

Please sign in to comment.