simple-github-api
This is a simple wrapper for the
GitHub API to ease requesting files,
directory information from a repository.
Basic Usage:
npm install --save simple-github-api
const API = require('simple-github-api')
let instance = new API({
token: "Some valid OAUTH key issued by github",
repo: "myProject",
username: "markzuckerberg"
})
instance.get('/some/path')
.then(metafile => {
console.log(metafile)
})
.catch(err => {
throw err
})
instance.getContents('some/file/path')
.then(file => {
console.log(file)
})
API
const API = require('simple-github-api')
Constructors
The new
keyword is required to
create an instance of the API
object.
It is recommended to get an OAUTH
key issued for your application and
instantiate with that token.
let instance = new API(
{
token: "A valid token"
})
The default object however doesn't require any config.
let instance = new API()
You can also pass in basic auth credentials, and a repository.
options = {
username: "jeff",
pw: "secret",
repo: "sweetProject",
token: "OAUTHToken"
}
Main Features
The basic interface below is unlikely to change, although further features may be added later. For all of the below path is a string.
Interface | Description |
---|
.get(path) | Returns the fileObject or directory for the relevant file. Takes a string relative path, and requires the repo and user to be set. |
.getUrl(path) | Returns the current url formed for the request. Mainly called internally. |
.getContents(path) | Returns the file contents directly, decoded and ready to use. |
.decode(encodedFile) | Decodes a file object in base64Unicode. |
Configuration
instance.repo = "NewRepo"
instance.user = "newUser"
let axios = instance.axios
Credits
Project built leaning heavily on the simplicity of the axios api.
License
MIT