Permalink
Browse files

Refine the fiels.

  • Loading branch information...
1 parent 063611f commit dc8d98d8a7c00918489c932f28ffbaaa5ef317ed @JacksonTian committed Jul 15, 2011
View
@@ -1,17 +0,0 @@
-exports.controller = function () {
-
- var index = function () {
- var response = this.response;
- response.writeHeader(200, {'Content-Type':'text/html; charset=utf-8'});
- setInterval(function () {
- response.write("Hello!");
- }, 1000);
- //response.end();
- };
-
- return {
- get: {
- index: index
- }
- };
-}();
View
@@ -1,72 +0,0 @@
-var https = require('https'),
- http = require('http');
-
-exports.controller = function () {
- var index = function () {
- this.render("google_index");
- },
- // getShortURL = function () {
- // var context = this;
- // var post = context.request.post;
-
- // //https://www.googleapis.com/urlshortener/v1/url
- // var options = {
- // host: 'www.googleapis.com',
- // port: 443,
- // path: '/urlshortener/v1/url?key=AIzaSyAPqm_U5TmWX-QfsZM5KkINLAwkBa9zmuY',
- // method: 'POST',
- // headers: {
- // 'Content-Type': 'application/json'
- // }
- // };
-
- // var request = https.request(options, function(response) {
- // var data = '';
-
- // response.on('data',function(chunk){
- // data += chunk;
- // process.stdout.write(chunk);
- // }).on('end', function (){
- // console.log(data);
- // context.renderJSON(JSON.parse(data));
- // });
- // });
-
- // request.write(JSON.stringify({"longUrl": post.longURL}));
- // request.end();
- // },
- getShortURL = function () {
- var context = this;
- var post = context.request.post;
-
- //http://api.t.sina.com.cn/short_url/shorten.json;
- var options = {
- host: 'api.t.sina.com.cn',
- port: 80,
- path: '/short_url/shorten.json?source=1662172390&url_long=' + post.longURL,
- method: 'GET'
- };
-
- var request = http.request(options, function(response) {
- var data = '';
-
- response.on('data',function(chunk){
- data += chunk;
- }).on('end', function (){
- console.log(data);
- context.renderJSON(JSON.parse(data));
- });
- });
- request.end();
- };
-
-
- return {
- get: {
- index: index
- },
- post: {
- getShortURL: getShortURL
- }
- };
-}();
View
@@ -1,64 +1,12 @@
var http = require("http");
exports.controller = function() {
- var index = function (username) {
- var response = this.response,
- request = this.request,
- username = username || request.cookie.getCookie("username");
- request.cookie.setCookie("username", username, {path: "/"});
- response.writeHead(200, {'Content-Type': 'text/plain'});
- console.log("set cookie:");
- console.log(request.cookie.getCookies());
- response.end('Hello, '+ username +'\n');
- },
- tweets = function () {
- var res = this.response
- tweets,
- template = '<li>\
- <em>@user.screen_name</em>\
- <img src="@user.profile_image_url" />\
- <span>@text</span>\
- <li>';
- http.createClient(80, 'api.t.sina.com.cn')
- .request('GET', '/statuses/public_timeline.json?source=1662172390', {'host': 'api.t.sina.com.cn'})
- .addListener('response', function(response){
- var result = '';
- response.addListener('data',function(data){
- result += data;
- }).addListener('end',function( ){
- tweets = JSON.parse(result);
- res.writeHeader(200, {'Content-Type':'text/html; charset=utf-8'});
- res.write('<!docytype html><html><head><title>Public tweets from sina</title><link rel="stylesheet" type="text/css" href="/static/style.css" media="all" /></head><body>');
- res.write('<div id="tweets"><ul>');
- if(tweets && tweets.length) {
- for(var i = 0; i<tweets.length; i++) {
- var itm = template.replace(/@([\w\.]+)/g, function(){ return eval('tweets[i].'+arguments[1]) });
- res.write(itm);
- }
- }
- res.end('</ul></div></body></html>');
- });
- }).end();
- },
- getEmotions = function () {
- var context = this;
- http.createClient(80, 'api.t.sina.com.cn')
- .request('GET', '/emotions.json?source=1662172390', {'host': 'api.t.sina.com.cn'})
- .addListener('response', function(response){
- var result = '';
- response.addListener('data',function(data){
- result += data;
- }).addListener('end',function( ){
- var emotions = JSON.parse(result);
- context.render("emotions", {"emotions": emotions});
- });
- }).end();
+ var index = function () {
+ this.render("index");
};
-
+
return {
get: {
- index: index,
- tweets: tweets,
- getEmotions: getEmotions
+ index: index
}
};
}();
View
@@ -1,99 +0,0 @@
-var http = require("http"),
- sinaWeibo = require("../models/sina.weibo");
-
-exports.controller = function () {
- var APP_KEY = "YOUR APP KEY";
- var APP_SECRET = "YOUR APP SECRET";
-
- var index = function (username) {
- this.render("index");
- },
- getEmotions = function () {
- var context = this;
- http.createClient(80, 'api.t.sina.com.cn')
- .request('GET', '/emotions.json?source=1662172390', {'host': 'api.t.sina.com.cn'})
- .addListener('response', function(response){
- var result = '';
- response.addListener('data',function(data){
- result += data;
- }).addListener('end',function( ){
- var emotions = JSON.parse(result);
- context.render("emotions", {"emotions": emotions});
- });
- }).end();
- },
- getOAuthURL = function () {
- var context = this;
- var request = context.request;
- var session = request.session;
- var weibo = new sinaWeibo.Weibo(APP_KEY, APP_SECRET);
- weibo.getRequestToken(function () {
- session.add("requestToken", weibo.requestToken);
- context.renderJSON({redirect: weibo.getAuthorizeURL()});
- });
- },
- getHomeTimeline = function () {
- //http://api.t.sina.com.cn/statuses/friends_timeline.json
- var context = this,
- session = this.request.session,
- accessToken = session.get("accessToken");
-
- if (accessToken) {
- var weibo = new sinaWeibo.Weibo(APP_KEY, APP_SECRET, accessToken.oauthToken, accessToken.oauthTokenSecret);
- weibo.getHomeTimeline(function (timeline) {
- console.log(JSON.parse(timeline));
- context.render("hometimeline", {timeline: JSON.parse(timeline)});
- });
-
- } else {
- context.redirect("/sina");
- }
- },
- callback = function () {
- var context = this;
- var request = context.request;
- var session = request.session;
- var get = request.get;
-
- if (get.oauth_token && get.oauth_verifier && (requestToken = session.get("requestToken"))) {
- var weibo = new sinaWeibo.Weibo(APP_KEY, APP_SECRET, requestToken.oauthToken, requestToken.oauthTokenSecret);
- weibo.getAccessToken(get.oauth_verifier, function () {
- console.log(weibo.accessToken);
- session.add("accessToken", weibo.accessToken);
- context.redirect("/sina/getHomeTimeline");
- });
- } else {
- context.redirect("/sina");
- }
- },
- publishTweet = function () {
- var context = this,
- request = context.request,
- session = request.session,
- accessToken = session.get("accessToken");
-
- if (accessToken) {
- var weibo = new sinaWeibo.Weibo(APP_KEY, APP_SECRET, accessToken.oauthToken, accessToken.oauthTokenSecret);
- weibo.publishWeibo(function (status) {
- context.renderJSON(JSON.parse(status));
- }, {
- "status": request.post.status
- });
-
- } else {
- context.renderJSON({"result": "fails"});
- }
- };
-
- return {
- get: {
- index: index,
- getHomeTimeline: getHomeTimeline,
- getOAuthURL: getOAuthURL,
- callback: callback
- },
- post: {
- publishTweet: publishTweet
- }
- };
-}();
View
@@ -1,63 +0,0 @@
-var http = require("http"),
- tencent = require("../models/tencent.weibo");
-
-exports.controller = function () {
- var APP_KEY = "YOUR APP KEY";
- var APP_SECRET = "YOU APP SECRET";
-
- var index = function () {
- this.render("tencent_index");
- },
- getOAuthURL = function () {
- var context = this;
- var request = context.request;
- var session = request.session;
- var weibo = new tencent.Weibo(APP_KEY, APP_SECRET);
- weibo.getRequestToken(function () {
- session.add("requestToken", weibo.requestToken);
- context.renderJSON({redirect: weibo.getAuthorizeURL()});
- });
- },
- getHomeTimeline = function () {
- //http://api.t.sina.com.cn/statuses/friends_timeline.json
- var context = this,
- session = this.request.session,
- accessToken = session.get("accessToken");
-
- if (accessToken) {
- var weibo = new tencent.Weibo(APP_KEY, APP_SECRET, accessToken.oauthToken, accessToken.oauthTokenSecret);
- weibo.getHomeTimeline(function (timeline) {
- context.render("hometimeline", {timeline: JSON.parse(timeline)});
- });
-
- } else {
- context.redirect("/tencent");
- }
- },
- callback = function () {
- var context = this;
- var request = context.request;
- var session = request.session;
- var get = request.get;
- if (get.oauth_token && get.oauth_verifier && (requestToken = session.get("requestToken"))) {
-
- var weibo = new tencent.Weibo(APP_KEY, APP_SECRET, requestToken.oauthToken, requestToken.oauthTokenSecret);
- weibo.getAccessToken(get.oauth_verifier, function () {
- console.log(weibo.accessToken);
- session.add("accessToken", weibo.accessToken);
- context.redirect("/tencent/getHomeTimeline");
- });
- } else {
- context.redirect("/tencent");
- }
- };
-
- return {
- get: {
- index: index,
- getHomeTimeline: getHomeTimeline,
- getOAuthURL: getOAuthURL,
- callback: callback
- }
- };
-}();
Oops, something went wrong.

0 comments on commit dc8d98d

Please sign in to comment.