-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
63 lines (48 loc) · 1.76 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /usr/bin/env node
"use strict";
const request = require("request");
/*Base Uris for API calls*/
/* "user_url": "https://api.github.com/users/{user}",
"user_repositories_url": "https://api.github.com/users/{user}/repos{?type,page,per_page,sort}",
"starred_url": "https://api.github.com/user/starred{/owner}{/repo}",
*/
class Githuh {
constructor (username, password, userAgent){
this.baseUri = "https://api.github.com/users/";
this.username = username;
this.password = password;
//Create options with username as password
this.options = {
"headers": {
"User-agent" : userAgent || username,
"Accept" : "application/vnd.github.v3+json"
}
};
}
userRepoLookup(name, callback) { //and set url in options
let url = `${this.baseUri}${name}/repos`;
this.options["url"] = url;
this._sendRequest(this.options, callback);
}
userStarsLookup(name, callback) {
let url = `${this.baseUri}${name}/starred`;
this.options["url"] = url;
this._sendRequest(this.options, callback);
}
userProfileLookup(name, callback){
let url = `${this.baseUri}${name}`;
this.options["url"] = url;
this._sendRequest(this.options, callback);
}
_sendRequest(options, callback) {
request.get(options, function(error, response, body) {
if (error) {
console.log(error);
} else if (response.statusCode == 200) {
//how to send this value back to the calling function
callback(JSON.parse(body));
}
}).auth(this.username, this.password);
}
}
module.exports = Githuh;//Constructor