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.

127 lines
2.9 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. function getUserRepositories(userName, suc, err)
  56. {
  57. //ex: http://localhost:7000/api/repositories/jwflory
  58. const urlpath = APIROOT + "/repositories/" + userName;
  59. runAjax(urlpath, suc, err);
  60. }
  61. function getOrganizationRepositories(orgName, suc, err)
  62. {
  63. //ex: http://localhost:7000/api/org/repositories/ComputerScienceHouse
  64. const urlpath = APIROOT + "/org/repositories/" + orgName;
  65. runAjax(urlpath, suc, err);
  66. }
  67. function getOrganizationMembers(orgName, suc, err)
  68. {
  69. const urlpath = APIROOT + "/org/users/" + orgName;
  70. runAjax(urlpath, suc, err);
  71. }
  72. /**
  73. * Queries github API end points with the backend
  74. * proxy server for github graphs.
  75. *
  76. * @param {*} url
  77. * @param {*} successCallBack
  78. * @param {*} errorCallBack
  79. */
  80. function queryUrl(url, successCallBack, errorCallBack)
  81. {
  82. url = url.split("https://api.github.com/").join("api/");
  83. runAjax(url, successCallBack, errorCallBack);
  84. }
  85. /**
  86. * Wrapper for AJAX calls so we can unify
  87. * all of our settings.
  88. *
  89. * @param {*} url -- url to query
  90. * @param {*} successCallBack -- callback with data retrieved
  91. * @param {*} errorCallBack -- callback with error message
  92. */
  93. function runAjax(url, successCallBack, errorCallBack)
  94. {
  95. console.log(url);
  96. $.ajax({
  97. type:'GET',
  98. url: url,
  99. crossDomain: true,
  100. dataType: "json",
  101. success: successCallBack,
  102. error:errorCallBack,
  103. timeout: 3000
  104. });
  105. }