Browse Source

Fixed issues where the api was not pulling all of the github followers.

pull/11/head
Jeffery Russell 5 years ago
parent
commit
4be1968ae2
4 changed files with 107 additions and 33 deletions
  1. +82
    -27
      public/js/friendsGraph.js
  2. +2
    -1
      public/js/githubAPI.js
  3. +1
    -1
      public/js/profileTimeLine.js
  4. +22
    -4
      routes/api.js

+ 82
- 27
public/js/friendsGraph.js View File

@ -64,12 +64,15 @@ function addPersonToGraph(profileData)
* @param apiPath
* @returns {Promise<any>}
*/
function addFriends(username, apiPath)
function addFriends(username, apiPath, page)
{
console.log(username + " page=" + page);
return new Promise(function(resolve, reject)
{
queryAPIByUser(apiPath, username, function(data)
queryAPIByUser(apiPath + "?page=" + page, username, function(data)
{
console.log(data);
console.log(data.length);
for(var i = 0; i < data.length; i++)
{
if(!alreadyInGraph(data[i].id))
@ -77,7 +80,18 @@ function addFriends(username, apiPath)
addPersonToGraph(data[i]);
}
}
resolve();
if(data.length === 30)
{
addFriends(username, apiPath, page+ 1).then(function()
{
resolve();
})
}
else
{
resolve();
}
},
function(error)
{
@ -96,6 +110,7 @@ function addFriends(username, apiPath)
*/
function edgeInGraph(id1, id2)
{
console.log("edge check");
for(var i = 0;i < edges.length; i++)
{
if(edges[i].from === id1 && edges[i].to === id2)
@ -133,41 +148,82 @@ function addConnection(person1, person2)
}
/**
* Processes all the connections of a user and adds them to the graph
*
* @param user has .id and .name
* @returns {Promise<any>}
*/
function processUserConnections(user)
function processConnections(user, apiPoint, page)
{
return new Promise(function(resolve, reject)
{
queryAPIByUser(API_FOLLOWING, user.name,
queryAPIByUser(apiPoint + "?page=" + page, user.name,
function(data)
{
for(var i = 0; i < data.length; i++)
{
addConnection(user, data[i])
}
queryAPIByUser(API_FOLLOWERS, user.name, function(data2)
if(data.length === 30)
{
processConnections(user, apiPoint, page + 1).then(function()
{
for(var i = 0; i < data2.length; i++)
{
addConnection(user, data2[i]);
}
resolve();
},
function(error)
{
reject(error);
});
},
function(error)
}
else
{
resolve();
}
}, function(error)
{
console.log(error);
resolve();
})
})
}
/**
* Processes all the connections of a user and adds them to the graph
*
* @param user has .id and .name
* @returns {Promise<any>}
*/
function processUserConnections(user)
{
return new Promise(function(resolve, reject)
{
processConnections(user, API_FOLLOWING, 1).then(function()
{
processConnections(user, API_FOLLOWERS, 1).then(function()
{
reject(error);
resolve();
})
})
// queryAPIByUser(API_FOLLOWING, user.name,
// function(data)
// {
// for(var i = 0; i < data.length; i++)
// {
// addConnection(user, data[i])
// }
//
// queryAPIByUser(API_FOLLOWERS, user.name, function(data2)
// {
// for(var i = 0; i < data2.length; i++)
// {
// addConnection(user, data2[i]);
// }
// resolve();
// },
// function(error)
// {
// // reject(error);
// resolve();
// });
// },
// function(error)
// {
// // reject(error);
// resolve();
// })
});
}
@ -247,10 +303,9 @@ function createFriendsGraph(username, containerName, graphsTitle)
edges = [];
addSelfToGraph(username).then(function()
{
console.log("added self");
addFriends(username, API_FOLLOWERS).then(function()
addFriends(username, API_FOLLOWERS,1).then(function()
{
addFriends(username, API_FOLLOWING).then(function()
addFriends(username, API_FOLLOWING,1).then(function()
{
createConnections().then(function()
{

+ 2
- 1
public/js/githubAPI.js View File

@ -32,6 +32,7 @@ const API_ORGANIZATIONS = "/orgs";
*/
function queryAPIByUser(apiPath, user, successCallBack, errorCallBack) {
const urlpath = APIROOT + API_USER_PATH + user + apiPath;
console.log(urlpath);
$.ajax({
type:'GET',
url: urlpath,
@ -39,6 +40,6 @@ function queryAPIByUser(apiPath, user, successCallBack, errorCallBack) {
dataType: "json",
success: successCallBack,
error:errorCallBack,
timeout: 1500
timeout: 4000
});
}

+ 1
- 1
public/js/profileTimeLine.js View File

@ -126,7 +126,7 @@ function createProfileTimeLine(username, containerName)
{id: 1, content: 'Repositories', value: 2}
]);
console.log("up up duper");
Promise.all(prom).then(function()
{
// note that months are zero-based in the JavaScript Date object

+ 22
- 4
routes/api.js View File

@ -9,7 +9,7 @@ const GITHUB_API = "https://api.github.com";
const configLoader = require('../configManager');
const authenticate = "?client_id=" + configLoader.getClientID() +
const authenticate = "client_id=" + configLoader.getClientID() +
"&client_secret=" + configLoader.getClientSecret();
@ -25,9 +25,17 @@ function queryGitHubAPI(requestURL)
{
if(apiData == null)
{
const queryRUL = GITHUB_API + requestURL + authenticate;
var queryURL;
if(requestURL.includes("?page="))
{
queryURL = GITHUB_API + requestURL + "&" + authenticate;
}
else
{
queryURL = GITHUB_API + requestURL + "?" + authenticate;
}
got(queryRUL, { json: true }).then(response =>
got(queryURL, { json: true }).then(response =>
{
resolve(response.body);
cache.put(requestURL, response.body);
@ -50,7 +58,17 @@ function queryGitHubAPI(requestURL)
routes.get('/*', (request, result) =>
{
const gitHubAPIURL = request.url;
var gitHubAPIURL = request.url;
// if(request.query.hasOwnProperty("page"))
// {
// gitHubAPIURL += "?page=" + request.query.page;
// }
console.log(request.query);
console.log(gitHubAPIURL);
result.setHeader('Content-Type', 'application/json');
queryGitHubAPI(gitHubAPIURL).then(function(data)

Loading…
Cancel
Save