Skip to content

Commit e242df5

Browse files
committed
* move shortening to node-shorturl
* add #lca2011 related search terms * alphas will always be lower case
1 parent fe00da2 commit e242df5

File tree

5 files changed

+15
-121
lines changed

5 files changed

+15
-121
lines changed

lib/proxy.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var Twitter = require('twitter'),
22
utility = require('./utility'),
3-
unempty = utility.unempty,
4-
shortUrl = utility.shortUrl;
3+
shortUrl = require('shorturl'),
4+
unempty = utility.unempty;
55

66
var tweetbloat = [
77
// strip thus-far unused geolocation data
@@ -40,8 +40,8 @@ DenbyProxy = function(client, ripley) {
4040
header: 'Me'
4141
},
4242
{ id: 'search',
43-
header: 'Search: nodejs, node.js, #denby, hellodenby',
44-
search: 'nodejs,node.js,#denby,hellodenby'
43+
header: 'Search: nodejs, node.js, #denby, hellodenby, lca2011, linux.conf.au',
44+
search: 'nodejs,node.js,#denby,hellodenby,lca2011,linux.conf.au'
4545
}
4646
]
4747
}}};
@@ -73,7 +73,7 @@ DenbyProxy = function(client, ripley) {
7373
// Connect to the stream
7474
// FIXME: q'n'd user streams solution, without ripley for now
7575
//ripley.on('data', send);
76-
twitter.stream('user', {track:'nodejs,node.js,#denby,hellodenby'},
76+
twitter.stream('user', {track:'nodejs,node.js,#denby,hellodenby,lca2011,linux.conf.au'},
7777
function(stream) {
7878
console.log('USER STREAMING FOR ' + screen_name + ' (' + client.sessionId + ')!');
7979
stream.on('data', send);

lib/ripley.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ var Twitter = require('twitter'),
44
inspect = util.inspect;
55

66

7-
function Ripley(twitter, sitestreams) {
7+
function Ripley(twitter, config) {
88
this.twitter = twitter;
9+
this.config = config;
910
this.users = {};
1011

11-
if ( sitestreams === true ) {
12+
//console.log(inspect(this));
13+
14+
/*if ( config.sitestreams === true ) {
1215
// FIXME: bring up the sitestreams
13-
}
16+
}*/
1417
};
1518
module.exports = Ripley;
1619

lib/utility.js

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
var http = require('http'),
2-
urlparse = require('url').parse,
3-
querystring = require('querystring');
4-
51
module.exports.unempty =
62
function unempty(o, deleteKeys) {
73
if ( Array.isArray(o) || typeof o == 'object' ) {
@@ -25,104 +21,3 @@ function unempty(o, deleteKeys) {
2521
}
2622
return o;
2723
}
28-
29-
module.exports.shortUrl =
30-
function shortUrl(longurl, shorter, params, callback) {
31-
if ( typeof params === 'function' ) {
32-
callback = params;
33-
params = null;
34-
}
35-
if ( typeof shorter === 'function' ) {
36-
callback = shorter;
37-
params = null;
38-
shorter = 'arseh.at';
39-
} else if ( typeof shorter === 'object' ) {
40-
params = shorter;
41-
shorter = 'arseh.at';
42-
}
43-
if ( typeof callback === 'function' && shorter in urlShorters )
44-
urlShorters[shorter](longurl, params, callback);
45-
}
46-
47-
// FIXME: create a simple shorturl processor that takes a string
48-
// eg. http://is.gd/api.php?longurl=%s
49-
50-
var urlShorters = {
51-
'is.gd': function(url, params, callback) {
52-
if ( typeof params === 'function' ) {
53-
callback = params;
54-
params = null;
55-
}
56-
get('http://is.gd/api.php', {
57-
longurl: url
58-
}, function(data) {
59-
if ( data.substr(0, 13) === 'http://is.gd/' )
60-
callback(data);
61-
else
62-
callback();
63-
});
64-
},
65-
66-
'bit.ly': function(url, params, callback) {
67-
if ( typeof params === 'function' ) {
68-
callback = params;
69-
params = null;
70-
}
71-
get('http://api.bit.ly/v3/shorten', {
72-
login: params.login || null,
73-
apiKey: params.apiKey || null,
74-
longUrl: url,
75-
format: 'json'
76-
}, function(data) {
77-
try {
78-
var json = JSON.parse(data);
79-
if ( json.data && json.data.url )
80-
callback(json.data.url, json);
81-
} catch(error) {
82-
callback();
83-
}
84-
});
85-
},
86-
87-
'arseh.at': function(url, params, callback) {
88-
if ( typeof params === 'function' ) {
89-
callback = params;
90-
params = null;
91-
}
92-
get('http://arseh.at/api.php', {
93-
action: 'shorturl',
94-
format: 'simple',
95-
url: url
96-
}, function(data) {
97-
callback(data);
98-
});
99-
}
100-
};
101-
102-
function get(uri, params, callback) {
103-
if ( typeof params === 'function' ) {
104-
callback = params;
105-
params = null;
106-
}
107-
var uri = urlparse(uri),
108-
port = (uri.protocol == 'https:') ? 443 : 80,
109-
host = uri.host,
110-
path = uri.pathname, // FIXME: ignoring uri.search
111-
request = http.createClient(port, host).request(
112-
'GET', path + '?' + querystring.stringify(params),
113-
{ 'Host': host, 'User-Agent': 'Denby' });
114-
request.end();
115-
request.on('response', function(response) {
116-
if ( response.statusCode !== 200 ) {
117-
callback(new Error({
118-
message: response.statusCode,
119-
data: response
120-
}));
121-
return;
122-
}
123-
response.setEncoding('utf8');
124-
response.on('data', function(chunk) {
125-
callback(chunk, response);
126-
});
127-
});
128-
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
{ "twitter": ">=0.1.11"
2020
, "socket.io": ">=0.6.3"
2121
, "creationix": ">=0.0.6"
22+
, "shorturl": ">=0.0.2"
2223
}
2324
, "engines": ["node >=0.2.0"]
2425
}

server.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@ try {
1818
var twitter = Twitter(config.twitter || null);
1919
twitter.options.secure = config.secure || false;
2020
twitter.options.cookie_secret = config.secret || null;
21-
// why doesn't node-twitter do cookie-secure already?
22-
twitter.options.cookie_options = {
23-
httpOnly: true,
24-
secure: config.secure
25-
};
21+
twitter.options.cookie_options = {}; // httpOly fucks up flashsocket
2622

2723
// Ripley
28-
var ripley = new Ripley(twitter, config.sitestreams || false);
24+
var ripley = new Ripley(twitter, config);
2925

3026
// Web
31-
var fs = require('fs');
3227
module.exports = require('http').createServer(require('stack')(
3328
require('creationix/log')(),
3429
require('./lib/gzip-proc')(),
@@ -47,7 +42,7 @@ require('socket.io').listen(module.exports).on('connection', function(client) {
4742
// Success! Probably a valid cookie
4843
if ( twauth && twauth.user_id && twauth.access_token_secret ) {
4944
// Deliberately kill off non-alphas
50-
if ( config.alphas && config.alphas.indexOf(twauth.screen_name) < 0 ) {
45+
if ( config.alphas && config.alphas.indexOf(twauth.screen_name.toLowerCase()) < 0 ) {
5146
console.log('DUMPED NON-ALPHA ' + twauth.screen_name + '!');
5247
client.send({AUTHFAIL: "Currently closed for alpha testing. Disconnecting."});
5348
setTimeout(function() {

0 commit comments

Comments
 (0)