Skip to content

Instantly share code, notes, and snippets.

@jhgaylor
Forked from ricomoss/gist:8079884
Last active January 1, 2016 02:29
Show Gist options
  • Save jhgaylor/8079890 to your computer and use it in GitHub Desktop.
Save jhgaylor/8079890 to your computer and use it in GitHub Desktop.
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