node-ghapi
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -1,2 +0,2 @@ | ||
var { getJSON } = require('./utils'); | ||
var { getJSON, getOptions } = require('./utils'); | ||
@@ -21,15 +21,7 @@ var baseURL = 'api.github.com'; | ||
repo: (owner, name, callback) => { | ||
getJSON({ | ||
host: baseURL, | ||
port: 443, | ||
path: `/repos/${owner}/${name}`, | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'User-Agent': 'ghapi-npm' | ||
} | ||
}, (status, repo) => { | ||
getJSON(getOptions(`/repo/${owner}/${name}`), (status, repo) => { | ||
callback(repo); | ||
}); | ||
}, | ||
/** | ||
@@ -49,15 +41,26 @@ * user: Returns a user JSON object | ||
user: (user, callback) => { | ||
getJSON({ | ||
host: baseURL, | ||
port: 443, | ||
path: `/users/${user}`, | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'User-Agent': 'ghapi-npm' | ||
} | ||
}, (status, user) => { | ||
getJSON(getOptions(`/user/${user}`), (status, user) => { | ||
callback(user); | ||
}); | ||
}, | ||
/** | ||
* commits: Returns a JSON object populated with commits. | ||
* @function | ||
* @public | ||
* | ||
* @param {string} owner The owner of the repo. | ||
* @param {string} name The name of the repo. | ||
* @param {function} callback The callback with the results. | ||
* | ||
* @example | ||
* commits('haydennyyy', (res) => { | ||
* console.log(res); | ||
* }); | ||
*/ | ||
commits: (owner, name, callback) => { | ||
getJSON(getOptions(`/repos/${owner}/${name}/commits`), (status, commits) => { | ||
callback(commits); | ||
}); | ||
} | ||
} |
{ | ||
"name": "node-ghapi", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "A predictable GitHub API wrapper for NodeJS.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
19
utils.js
@@ -31,3 +31,22 @@ var http = require('http'); | ||
req.end(); | ||
}, | ||
/** | ||
* getOptions: Provides a JSON object containing options. | ||
* @param {string} APIPath The path you're connecting to on GitHub | ||
* | ||
* @example | ||
* getOptions('/users/haydennyyy/ghapi') | ||
*/ | ||
getOptions: (APIPath) => { | ||
return { | ||
host: 'api.github.com', | ||
port: 443, | ||
path: APIPath, | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'User-Agent': 'ghapi-npm' | ||
} | ||
} | ||
} | ||
} |
3738
105
5