Added GitHub event feed data fetching

This commit is contained in:
Juuso Tapaninen
2015-01-28 00:15:28 +02:00
parent 85f61f09af
commit e77f87de69
2 changed files with 29 additions and 1 deletions

25
feeds/github.js Normal file
View File

@@ -0,0 +1,25 @@
'use strict';
var request = require('superagent');
var config = require('../lib/config');
var Promise = require('bluebird');
module.exports = {
/**
* Fetch five latest events from GitHub organization
*/
getEvents: function() {
return new Promise(function(resolve, reject) {
request
.get('https://api.github.com/orgs/koodiklinikka/events?per_page=5')
.set('Authorization', 'token ' + config.github.token)
.end(function(error, response){
if(error) {
reject(error);
}
resolve(response.body);
});
});
}
};

View File

@@ -3,6 +3,7 @@
var request = require('superagent');
var cache = require('apicache').middleware;
var twitter = require('../feeds/twitter');
var github = require('../feeds/github');
module.exports = function (app) {
/*
@@ -10,8 +11,10 @@ module.exports = function (app) {
* Endpoint for fetching different information feeds (Twitter, GitHub etc.)
*/
app.get('/feeds', cache('3 hours'), function(req, res, next) {
Promise.all([twitter.getTweets()]).then(function(data) {
Promise.all([twitter.getTweets(), github.getEvents()]).then(function(data) {
res.status(200).send(data);
}, function(err) {
next(err);
});
});
};