mirror of
https://github.com/koodiklinikka/koodiklinikka.fi-api.git
synced 2026-01-26 03:34:03 +00:00
Added GitHub event feed data fetching
This commit is contained in:
25
feeds/github.js
Normal file
25
feeds/github.js
Normal 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);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user