3
3
[ ![ Downloads per month] ( https://img.shields.io/npm/dm/github-api.svg?maxAge=2592000 )] [ npm-package ]
4
4
[ ![ Latest version] ( https://img.shields.io/npm/v/github-api.svg?maxAge=3600 )] [ npm-package ]
5
5
[ ![ Gitter] ( https://img.shields.io/gitter/room/michael/github.js.svg?maxAge=2592000 )] [ gitter ]
6
- [ ![ Travis] ( https://img.shields.io/travis/michael/github.svg?maxAge=60 )] [ travis-ci ]
7
6
<!-- [][codecov] -->
8
7
9
- Github.js provides a minimal higher-level wrapper around Github's API. It was concieved in the context of
10
- [ Prose] [ prose ] , a content editor for GitHub.
8
+ Github.js provides a minimal higher-level wrapper around Github's API.
11
9
12
- ## [ Read the docs] [ docs ]
13
-
14
- ## Installation
15
- Github.js is available from ` npm ` or [ unpkg] [ unpkg ] .
16
-
17
- ``` shell
18
- npm install github-api
19
- ```
20
-
21
- ``` html
22
- <!-- just github-api source (5.3kb) -->
23
- <script src =" https://unpkg.com/github-api/dist/GitHub.min.js" ></script >
24
-
25
- <!-- standalone (20.3kb) -->
26
- <script src =" https://unpkg.com/github-api/dist/GitHub.bundle.min.js" ></script >
27
- ```
28
-
29
- ## Compatibility
30
- Github.js is tested on Node:
31
- * 6.x
32
- * 5.x
33
- * 4.x
34
- * 0.12
35
-
36
- ## GitHub Tools
37
-
38
- The team behind Github.js has created a whole organization, called [ GitHub Tools] ( https://github.com/github-tools ) ,
39
- dedicated to GitHub and its API. In the near future this repository could be moved under the GitHub Tools organization
40
- as well. In the meantime, we recommend you to take a look at other projects of the organization.
41
-
42
- ## Samples
10
+ ## Usage
43
11
44
12
``` javascript
45
13
/*
46
14
Data can be retrieved from the API either using callbacks (as in versions < 1.0)
47
- or using a new promise-based API. For now the promise-based API just returns the
48
- raw HTTP request promise; this might change in the next version .
15
+ or using a new promise-based API. The promise-based API returns the raw Axios
16
+ request promise.
49
17
*/
50
18
import GitHub from ' github-api' ;
51
19
@@ -62,52 +30,70 @@ gist.create({
62
30
}
63
31
}).then (function ({data}) {
64
32
// Promises!
65
- let gistJson = data;
66
- gist .read (function (err , gist , xhr ) {
67
- // if no error occurred then err == null
68
-
69
- // gistJson === httpResponse.data
70
-
71
- // xhr === httpResponse
72
- });
33
+ let createdGist = data;
34
+ return gist .read ();
35
+ }).then (function ({data}) {
36
+ let retrievedGist = data;
37
+ // do interesting things
73
38
});
74
39
```
75
40
76
41
``` javascript
77
- import GitHub from ' github-api' ;
42
+ var GitHub = require ( ' github-api' ) ;
78
43
79
44
// basic auth
80
- const gh = new GitHub ({
45
+ var gh = new GitHub ({
81
46
username: ' FOO' ,
82
47
password: ' NotFoo'
48
+ /* also acceptable:
49
+ token: 'MY_OAUTH_TOKEN'
50
+ */
83
51
});
84
52
85
- const me = gh .getUser ();
53
+ var me = gh .getUser (); // no user specified defaults to the user for whom credentials were provided
86
54
me .listNotifications (function (err , notifications ) {
87
55
// do some stuff
88
56
});
89
57
90
- const clayreimann = gh .getUser (' clayreimann' );
91
- clayreimann .listStarredRepos ()
92
- .then (function ({data: reposJson}) {
93
- // do stuff with reposJson
94
- });
58
+ var clayreimann = gh .getUser (' clayreimann' );
59
+ clayreimann .listStarredRepos (function (err , repos ) {
60
+ // look at all the starred repos!
61
+ });
95
62
```
96
63
97
- ``` javascript
98
- var GitHub = require (' github-api' );
64
+ ## API Documentation
99
65
100
- // token auth
101
- var gh = new GitHub ({
102
- token: ' MY_OAUTH_TOKEN'
103
- });
66
+ [ API documentation] [ docs ] is hosted on github pages, and is generated from JSDoc; any contributions
67
+ should include updated JSDoc.
104
68
105
- var yahoo = gh .getOrganization (' yahoo' );
106
- yahoo .listRepos (function (err , repos ) {
107
- // look at all the repos!
108
- })
69
+ ## Installation
70
+ Github.js is available from ` npm ` or [ unpkg] [ unpkg ] .
71
+
72
+ ``` shell
73
+ npm install github-api
109
74
```
110
75
76
+ ``` html
77
+ <!-- just github-api source (5.3kb) -->
78
+ <script src =" https://unpkg.com/github-api/dist/GitHub.min.js" ></script >
79
+
80
+ <!-- standalone (20.3kb) -->
81
+ <script src =" https://unpkg.com/github-api/dist/GitHub.bundle.min.js" ></script >
82
+ ```
83
+
84
+ ## Compatibility
85
+ Github.js is tested on Node:
86
+ * 6.x
87
+ * 5.x
88
+ * 4.x
89
+ * 0.12
90
+
91
+ ## GitHub Tools
92
+
93
+ The team behind Github.js has created a whole organization, called [ GitHub Tools] ( https://github.com/github-tools ) ,
94
+ dedicated to GitHub and its API. In the near future this repository could be moved under the GitHub Tools organization
95
+ as well. In the meantime, we recommend you to take a look at other projects of the organization.
96
+
111
97
[ codecov ] : https://codecov.io/github/michael/github?branch=master
112
98
[ docs ] : http://michael.github.io/github/
113
99
[ gitter ] : https://gitter.im/michael/github
0 commit comments