Website for visualizing a persons github network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.3 KiB

  1. /**
  2. * Simple file which uses jQuery's ajax
  3. * calls to make it easier to get data
  4. * from the github api.
  5. *
  6. * @author Jeffery Russell 2-16-19
  7. */
  8. const APIROOT = "api";
  9. const API_USER_PATH = "/users/";
  10. const API_ORG_PATH = "/orgs/";
  11. const API_ORG_MEMBERS = "/members";
  12. const API_REPOS = "/repos";
  13. const API_REPOSITORIES = "/repos";
  14. const API_ORGANIZATIONS = "/orgs";
  15. /**
  16. * Builds a query for the github rest api and
  17. * allows you to get at the data using a
  18. * callback which gives you a json object.
  19. *
  20. * @param user the username to query
  21. * @param successCallBack callback to complete when data is returned
  22. * @param errorCallBack callback which is invoked on error
  23. */
  24. function queryAPIByUser(apiPath, user, successCallBack, errorCallBack)
  25. {
  26. const urlpath = APIROOT + API_USER_PATH + user + apiPath;
  27. runAjax(urlpath, successCallBack, errorCallBack);
  28. }
  29. /**
  30. * Makes API calls for orgs on github
  31. *
  32. * @param {*} apiPath
  33. * @param {*} org
  34. * @param {*} successCallBack
  35. * @param {*} errorCallBack
  36. */
  37. function queryAPIByOrg(apiPath, org, successCallBack, errorCallBack)
  38. {
  39. const urlpath = APIROOT + API_ORG_PATH + org + apiPath;
  40. runAjax(urlpath, successCallBack, errorCallBack);
  41. }
  42. /**
  43. * Fetches a list of fiends for a user.
  44. *
  45. * @param {*} userName
  46. * @param {*} suc
  47. * @param {*} err
  48. */
  49. function getFriendsAPI(userName, suc, err)
  50. {
  51. // api/friends/jrtechs
  52. const urlpath = APIROOT + "/friends/" + userName;
  53. runAjax(urlpath, suc, err);
  54. }
  55. /**
  56. * Queries github API end points with the backend
  57. * proxy server for github graphs.
  58. *
  59. * @param {*} url
  60. * @param {*} successCallBack
  61. * @param {*} errorCallBack
  62. */
  63. function queryUrl(url, successCallBack, errorCallBack)
  64. {
  65. url = url.split("https://api.github.com/").join("api/");
  66. runAjax(url, successCallBack, errorCallBack);
  67. }
  68. /**
  69. * Wrapper for AJAX calls so we can unify
  70. * all of our settings.
  71. *
  72. * @param {*} url -- url to query
  73. * @param {*} successCallBack -- callback with data retrieved
  74. * @param {*} errorCallBack -- callback with error message
  75. */
  76. function runAjax(url, successCallBack, errorCallBack)
  77. {
  78. console.log(url);
  79. $.ajax({
  80. type:'GET',
  81. url: url,
  82. crossDomain: true,
  83. dataType: "json",
  84. success: successCallBack,
  85. error:errorCallBack,
  86. timeout: 3000
  87. });
  88. }