|
1 |
| -# JavaScript GitHub API for node.js |
| 1 | +# JavaScript GitHub API for Node.JS |
2 | 2 |
|
3 |
| -A node.js module, which provides an object oriented wrapper for the GitHub v2 API. This library is a direct port of [php-github-api](http://github.com/ornicar/php-github-api) by Thibault Duplessis to JavaScript. The only major difference is that the JavaScript code is fully asynchronous. |
| 3 | +A Node.JS module, which provides an object oriented wrapper for the GitHub v3 API. |
4 | 4 |
|
5 | 5 | ## Installation
|
6 | 6 |
|
7 |
| - Install with the node package manager [npm](http://npmjs.org/): |
| 7 | + Install with the Node.JS package manager [npm](http://npmjs.org/): |
8 | 8 |
|
9 |
| - $ npm install github |
| 9 | + $ npm install node-github |
10 | 10 |
|
11 | 11 | or
|
12 | 12 |
|
13 | 13 | Install via git clone:
|
14 | 14 |
|
15 |
| - $ git clone git://github.com/ajaxorg/node-github.git |
16 |
| - $ cd node-github |
| 15 | + $ git clone git://github.com/c9/node-github3.git |
| 16 | + $ cd node-github3 |
17 | 17 | $ npm install
|
18 | 18 |
|
| 19 | +## Documentation |
| 20 | + |
| 21 | +You can find the docs for the API of this client at [http://c9.github.com/node-github3/](http://c9.github.com/node-github3/) |
| 22 | + |
| 23 | +Additionally, the [official Github documentation](http://developer.github.com/) |
| 24 | +is a very useful resource. |
| 25 | + |
19 | 26 | ## Example
|
20 | 27 |
|
21 |
| -Print all followers of the user "fjakobs" to the console. |
| 28 | +Print all followers of the user "mikedeboer" to the console. |
22 | 29 |
|
23 |
| - var GitHubApi = require("github").GitHubApi; |
| 30 | + var GitHubApi = require("node-github"); |
24 | 31 |
|
25 |
| - var github = new GitHubApi(true); |
26 |
| - github.getUserApi().getFollowers('fjakobs', function(err, followers) { |
27 |
| - console.log(followers.join('\n')); |
| 32 | + var github = new GitHubApi({ |
| 33 | + version: "3.0.0" |
| 34 | + }); |
| 35 | + github.user.getFollowingFromUser({ |
| 36 | + user: "mikedeboer" |
| 37 | + }, function(err, res) { |
| 38 | + console.log(JSON.stringify(res)); |
28 | 39 | });
|
29 | 40 |
|
30 |
| -First the _GitHubApi_ class is imported from the _github_ module. This class provides access to all of GitHub's APIs (e.g. user, commit or repository APIs). The _getFollowers_ method lists all followers of a given GitHub user. Is is part of the user API. It takes the user name as first argument and a callback as last argument. Once the follower list is returned from the server, the callback is called. |
| 41 | +First the _GitHubApi_ class is imported from the _node-github_ module. This class provides |
| 42 | +access to all of GitHub's APIs (e.g. user, issues or repo APIs). The _getFollowingFromUser_ |
| 43 | +method lists all followers of a given GitHub user. Is is part of the user API. It |
| 44 | +takes the user name as first argument and a callback as last argument. Once the |
| 45 | +follower list is returned from the server, the callback is called. |
31 | 46 |
|
32 |
| -Like in node.js callbacks are always the last argument. If the functions fails an error object is passed as first argument to the callback. |
| 47 | +Like in Node.JS, callbacks are always the last argument. If the functions fails an |
| 48 | +error object is passed as first argument to the callback. |
33 | 49 |
|
34 | 50 | ## Authentication
|
35 | 51 |
|
36 |
| -Most GitHub API calls don't require authentication. As a rule of thumb: If you can see the information by visiting the site without being logged in, you don't have to be authenticated to retrieve the same information through the API. Of course calls, which change data or read sensitive information have to be authenticated. |
| 52 | +Most GitHub API calls don't require authentication. As a rule of thumb: If you |
| 53 | +can see the information by visiting the site without being logged in, you don't |
| 54 | +have to be authenticated to retrieve the same information through the API. Of |
| 55 | +course calls, which change data or read sensitive information have to be authenticated. |
37 | 56 |
|
38 |
| -You need the GitHub user name and the API key for authentication. The API key can be found in the user's _Account Settings_ page. |
| 57 | +You need the GitHub user name and the API key for authentication. The API key can |
| 58 | +be found in the user's _Account Settings_ page. |
39 | 59 |
|
40 |
| -This example shows how to authenticate and then change _location_ field of the account settings to _Argentina_: |
| 60 | +This example shows how to authenticate and then change _location_ field of the |
| 61 | +account settings to _Argentina_: |
41 | 62 |
|
42 |
| - github.authenticate(username, token); |
43 |
| - github.getUserApi().update(username, {location: "Argentina"}, function(err) { |
| 63 | + github.authenticate({ |
| 64 | + type: "basic", |
| 65 | + username: username, |
| 66 | + password: password |
| 67 | + }); |
| 68 | + github.user.update({ |
| 69 | + location: "Argentina" |
| 70 | + }, function(err) { |
44 | 71 | console.log("done!");
|
45 | 72 | });
|
46 | 73 |
|
47 |
| -Note that the _authenticate_ method is synchronous because it only stores the credentials for the next request. |
| 74 | +Note that the _authenticate_ method is synchronous because it only stores the |
| 75 | +credentials for the next request. |
48 | 76 |
|
49 | 77 | ## Implemented GitHub APIs
|
50 | 78 |
|
51 |
| -* User API: 100% |
52 |
| -* Commit API: 100% |
53 |
| -* Object API: 100% |
54 |
| -* Repository API: 90%, missing repo visibility, deploy keys |
55 |
| -* Issues API: 100% |
56 |
| -* Pulls API: only _getList_ is implemented |
57 |
| -* Gist API: 100% v1 Gist API implemented. 0% v3 API |
58 |
| -* Network API: still missing |
| 79 | +* Gists: 100% |
| 80 | +* Git Data: 100% |
| 81 | +* Issues: 100% |
| 82 | +* Orgs: 100% |
| 83 | +* Pull Requests: 100% |
| 84 | +* Repos: 100% |
| 85 | +* Users: 100% |
| 86 | +* Events: 100% |
59 | 87 |
|
60 | 88 | ## Running the Tests
|
61 | 89 |
|
62 |
| -The unit tests are based on the [node-async-test](http://github.com/bentomas/node-async-testing) module, which is provided as a git submodule. To run the tests make sure that the npm dependencies are installed by running `npm install` from the project directory. |
| 90 | +The unit tests are based on the [ayncjs](https://github.com/ajaxorg/async.js) |
| 91 | +module, which is provided as an npm dependency. To run the tests make sure that the |
| 92 | +npm dependencies are installed by running `npm install` from the project directory. |
63 | 93 |
|
64 | 94 | Running all unit tests:
|
65 | 95 |
|
66 | 96 | npm test
|
67 | 97 |
|
68 | 98 | or
|
69 | 99 |
|
70 |
| - node lib/github_all_tests.js |
| 100 | + node test/all.js |
71 | 101 |
|
72 | 102 | The test classes can also be run separately. This will e.g. run the UserApi test:
|
73 | 103 |
|
74 |
| - node lib/github_test.js |
| 104 | + node api/v3.0.0/userTest.js |
75 | 105 |
|
76 | 106 | Note that a connection to the internet is required to run the tests.
|
77 | 107 |
|
78 | 108 | ## TODO
|
79 | 109 |
|
80 |
| -* API docs |
81 |
| - * fix and polish (there might still be some PHP-isms) |
82 |
| - * generate API documentation |
83 |
| -* Documentation |
| 110 | +* generate Client documentation |
84 | 111 |
|
85 | 112 | ## LICENSE
|
86 | 113 |
|
87 | 114 | MIT license. See the LICENSE file for details.
|
88 |
| - |
89 |
| -## Credits |
90 |
| - |
91 |
| -Thanks to Thibault Duplessis for the excellent php-github-api library, which is the blueprint of this library. Especially the unit tests proved to be very helpful. |
|
0 commit comments