Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
GitHub Api v3 library. Ideally, it should work in node via http request, and in browsers using jsonp.
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
api
docs
support
tests
.gitignore
readme.md

readme.md

Github api v3 library. ideally, it should work in node via http request, and in browsers using jsonp.

Quick docs

docco-generated docs

dependencies

The only required dependency is underscore. Used mainly to implement class in a way similar to Backbone, thus enforcing functional programming style and providing a set of utility methods.

May introduce EventEmitter2 to provide emitter style, it has browser environment compatibility and may be used as a module than can be mixed in to any object in order to provide it with custom events an emit-ing ability.

callbacks

every api methods takes a callback as last parameter. This try to follow the node convention:

function(err, values...){
  if(err) { return console.error(err); }
        do something
}

cache

the exposed variable gh defined the raw request method, which api components must use to interact with the api. A simple in-memory caching strategy based on requested uri (may be soon slightly reworked to work with adapters or something, so that other caching strategy may be implemented).

Basically, an api access should be done just once, any other subsequent calls gets result from the built-in cache.

The gh.request method is wrapped by the gh.cache method.

tests

Run the tests.

quick api overview

Head over to http://developer.github.com/v3/ and check the uri endpoint that you'd like to test.

Most likely any GET request is supported.

Gh.request

show user info:

http://developer.github.com/v3/users/

gh.request('/users/:user', {user: 'mklabs'}, console.log.bind(console));
gh.request('/users/:user', {user: 'github'}, console.log.bind(console));
gh.request('/users/:user', {user: 'somefancynamethatdoesnotexists'}, console.log.bind(console));

show repo info:

http://developer.github.com/v3/repos/

gh.request('/repos/:user/:repo', {user: 'loicdescotte', repo: 'coffeeblog'}, console.log.bind(console));

List public repositories for the specified user:

gh.request('/users/:user/repos', {user: 'mklabs'}, console.log.bind(console));

List public repositories for the specified user:

gh.request('/orgs/:org/repos', {org: 'github'}, console.log.bind(console));

Get a Tree:

http://developer.github.com/v3/git/trees/

gh.request('/repos/:user/:repo/git/trees/:sha', {
  user: 'github', 
  repo: 'developer.github.com',
  sha: 'ddec68feb7486edb94be5e102f433cf25ccd7390'
}, console.log.bind(console));

Get a Tree Recursively:

gh.request('/repos/:user/:repo/git/trees/:sha?recursive=1', {
  user: 'github', 
  repo: 'developer.github.com',
  sha: 'ddec68feb7486edb94be5e102f433cf25ccd7390'
}, console.log.bind(console));

notes on error

http://developer.github.com/v3/#client-errors

Callback functions can take any number of arguments, but the first argument is always an error or null.

todo

changelog

  • v.0.0.1:
    • raw request method
    • caching request output
    • starting point of tree wrapper api
    • tests
Something went wrong with that request. Please try again.