Skip to content

Commit

Permalink
Made changes to stream method to work with latest Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Smart authored and technoweenie committed Mar 5, 2010
1 parent 1aab36f commit 546ff68
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions lib/index.js
Expand Up @@ -38,20 +38,22 @@ TwitterNode.prototype.follow = function(userId) {
TwitterNode.prototype.stream = function() {
var client = this.createClient(this.port, this.host),
headers = process.mixin({}, this.headers),
node = this
node = this,
request;
headers['Host'] = this.host
if (this.user)
headers['Authorization'] = this.basicAuth(this.user, this.password)
client.request("GET", this.requestUrl(), headers)
.finish(function(resp) {
resp.setBodyEncoding("utf8");
resp.addListener('body', function(chunk) {
node.parser.receive(chunk)
});
resp.addListener('complete', function() {
node.emit('close', this)
});
request = client.request("GET", this.requestUrl(), headers);
request.addListener('response', function(response) {
response.setBodyEncoding('utf8');
response.addListener('data', function(chunk) {
node.parser.receive(chunk)
});
response.addListener('end', function() {
node.emit('close', this)
});
});
request.close();
return this;
}

Expand Down Expand Up @@ -97,4 +99,4 @@ TwitterNode.prototype.buildParams = function() {
return "?" + query.stringify(options)
else
return ""
}
}

0 comments on commit 546ff68

Please sign in to comment.