From 8f9b52f0d7f7542be188d6bdd168c4af6bf5293e Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sat, 16 Feb 2019 10:56:37 -0500 Subject: [PATCH] Created function to pull data from github's api. --- githubAPI.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 githubAPI.js diff --git a/githubAPI.js b/githubAPI.js new file mode 100644 index 0000000..d68c190 --- /dev/null +++ b/githubAPI.js @@ -0,0 +1,45 @@ +/** + * Simple file which uses jQuery's ajax + * calls to make it easier to get data + * from the github api. + * + * @author Jeffery Russell 2-16-19 + */ + + +const APIROOT = "https://api.github.com"; + +const API_USER_PATH = "/users/"; + +const API_FOLLOWING = "/following"; + +const API_FOLLOWERS = "/followers"; + +const API_REPOSITORIES = "/repos"; + +const API_ORGANIZATIONS = "/orgs"; + + +/** + * Builds a query for the github rest api and + * allows you to get at the data using a + * callback which gives you a json object. + * + * @param apiPath the path on the github api ie API_FOLLOWING + * @param user the username to query + * @param successCallBack callback to complete when data is returned + * @param errorCallBack callback which is invoked on error + */ +function queryAPIByUser(apiPath, user, successCallBack, errorCallBack) +{ + const urlpath = APIROOT + API_USER_PATH + user + apiPath; + console.log(urlpath); + $.ajax({ + type:'GET', + url: urlpath, + crossDomain: true, + dataType: "json", + success: successCallBack, + error:errorCallBack + }); +} \ No newline at end of file