Skip to content

Instantly share code, notes, and snippets.

@tgvashworth
Created August 31, 2012 21:15
Show Gist options
  • Save tgvashworth/3559121 to your computer and use it in GitHub Desktop.
Save tgvashworth/3559121 to your computer and use it in GitHub Desktop.
Watch the app.net global stream for annotations
/*
Note: this was hacked together _very_ fast. It's probably wrong, stupid,
broken, idiotic and generally useless.
To use: stick this in app.js & npm install request
*/
var request = require('request')
, url = require('url')
, access_token = "YOUR_ACCESS_TOKEN (created at alpha.app.net/developer/apps)";
var since_id = 0;
var build_url = function (endpoint, access_token, query) {
query = query || {};
query.access_token = access_token;
return url.format({
protocol: 'https'
, hostname: 'alpha-api.app.net/stream/0'
, pathname: endpoint
, query: query
});
};
// The boss.
var loop = function loop() {
request.get(build_url('/posts/stream/global', access_token, {
include_annotations: 1
, include_directed_posts: 1
, include_user: 1
, since_id: since_id
}), function (err, res, body) {
var posts;
try {
posts = JSON.parse(body);
} catch(e) {
return console.log(e);
}
posts.forEach(function (post) {
if( post.annotations.length === 0 ) return;
console.log("======================================");
console.log(post.user.username);
console.log(post.text);
console.log(post.annotations);
});
if( posts.length > 0 ) since_id = posts[0].id;
setTimeout(loop, 1000);
});
};
// Grab the latest post to work off
request.get(build_url('/posts/stream/global', access_token, {
include_annotations: 1
, include_directed_posts: 1
, include_user: 1
, count: 1
}), function (err, response, body) {
since_id = JSON.parse(body).id;
loop();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment