-
-
Save jhgaylor/8079890 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feeds = new Meteor.Collection('feeds'); | |
if (Meteor.isServer) { | |
var twitter_user_id = 0; | |
var boundCallback = Meteor.bindEnvironment(function (err, resp) { | |
var timestamp = new Date().getTime(); | |
for (var obj in resp['statuses']) { | |
twitter_user_id = resp['statuses'][obj].user.id; | |
Feeds.insert({ | |
feed: resp['statuses'][obj].text, | |
timestamp: timestamp | |
}); | |
} | |
Feeds.remove({timestamp: {$lt: timestamp - 5}}); | |
}); | |
Meteor.startup(function () { | |
Feeds.remove({}); | |
}); | |
Meteor.methods({ | |
twit_get: function() { | |
Twit = new TwitMaker({ | |
consumer_key: 'foo', | |
consumer_secret: 'foo', | |
access_token: 'foo', | |
access_token_secret: 'foo' | |
}); | |
Twit.get( | |
'search/tweets', | |
{ | |
q: 'banana since_id:' + twitter_user_id, | |
count: 10 | |
}, | |
boundCallback | |
); | |
} | |
}); | |
} | |
if (Meteor.isClient) { | |
Template.twitter_feeds.feeds = function () { | |
return Feeds.find({}, {sort: {feed: -1}}); | |
}; | |
//Meteor.setInterval(Meteor.call('twit_get'), 10000); | |
Meteor.setInterval(function () { | |
Meteor.call('twit_get'); | |
}, 10000); | |
//another way | |
function cb() { | |
Meteor.call('twit_get'); | |
} | |
Meteor.setInterval(cb, 10000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment