File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -4,15 +4,28 @@ Github.js
4
4
Ever wanted to store a file on Github right from the browser? Here you are.
5
5
6
6
7
- Expose API for a given repository .
7
+ Create a Github instance .
8
8
9
9
``` js
10
10
var github = new Github ({
11
11
username: " YOU_USER" ,
12
12
password: " YOUR_PASSWORD" ,
13
13
auth: " basic"
14
14
});
15
+ ```
16
+
17
+ Or if you prefer OAuth, it looks like this:
15
18
19
+ ``` js
20
+ var github = new Github ({
21
+ token: " OAUTH_TOKEN"
22
+ auth: " oauth"
23
+ });
24
+ ```
25
+
26
+ Expose API for a given repository.
27
+
28
+ ``` js
16
29
var repo = github .getRepo (reponame);
17
30
```
18
31
Original file line number Diff line number Diff line change 1
- // Github.js 0.4 .0
1
+ // Github.js 0.5 .0
2
2
// (c) 2012 Michael Aufreiter, Development Seed
3
3
// Github.js is freely distributable under the MIT license.
4
4
// For all details and documentation:
9
9
var API_URL = 'https://api.github.com' ;
10
10
11
11
Github = window . Github = function ( options ) {
12
- var username = options . username ;
13
- var password = options . password ;
14
12
15
13
// Util
16
14
// =======
17
15
18
16
function _request ( method , path , data , cb ) {
17
+ function headers ( ) {
18
+ return options . auth == 'oauth'
19
+ ? { Authorization : 'Token ' + options . token }
20
+ : { Authorization : 'Basic ' + Base64 . encode ( options . username + ':' + options . password ) }
21
+ }
22
+
19
23
$ . ajax ( {
20
24
type : method ,
21
25
url : API_URL + path ,
24
28
contentType : 'application/x-www-form-urlencoded' ,
25
29
success : function ( res ) { cb ( null , res ) ; } ,
26
30
error : function ( err ) { cb ( err ) ; } ,
27
- headers : { Authorization : 'Basic ' + Base64 . encode ( username + ':' + password ) }
31
+ headers : headers ( )
28
32
} ) ;
29
33
}
30
34
156
160
var data = {
157
161
"message" : message ,
158
162
"author" : {
159
- "name" : username
163
+ "name" : options . username
160
164
} ,
161
165
"parents" : [
162
166
parent
You can’t perform that action at this time.
0 commit comments