Skip to content

Instantly share code, notes, and snippets.

@kusor
Created December 20, 2009 10:15
Show Gist options
  • Save kusor/260432 to your computer and use it in GitHub Desktop.
Save kusor/260432 to your computer and use it in GitHub Desktop.
Playing with identi.ca API using node.js
var sys = require('sys'),
http = require('http');
var identica = {
host: 'identi.ca',
root: '/api',
search: '/search.json?q=',
statuses: '/statuses',
publicTimeline: function() {
return( this.root + this.statuses + "/public_timeline.json" );
},
userTimeline: function (screen_name) {
return( this.root + this.statuses + "/user_timeline/" + screen_name + ".json" );
}
}
var identicaClient = http.createClient( 80, identica.host );
var request = identicaClient.request( "GET", identica.userTimeline('kusor'), { "host": identica.host } );
request.finish( function ( response ) {
var body = '';
// sys.puts( "STATUS: " + response.statusCode );
// TODO: Hanle eTag & Last-Modified. Store it somewhere.
// sys.puts( "HEADERS: " + JSON.stringify(response.headers) );
response.setBodyEncoding( "utf8" );
response.addListener( "body", function (chunk) {
body += chunk;
});
response.addListener( "complete", function (){
if (response.statusCode == 200) {
// statuses = JSON.stringify(body);
// sys.puts(statuses);
statuses = JSON.parse(body);
for ( var i = (statuses.length - 1); i >= 0; i-- ) {
status = statuses[i];
sys.puts(
status['user']['screen_name'] + ' (' + status['user']['name'] + "):\n" +
status['text'] + "\n" +
"\n-----\n"
);
}
} else {
sys.puts( "identi.ca API failed with status " + response.statusCode );
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment