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
44Ever wanted to store a file on Github right from the browser? Here you are.
55
66
7- Expose API for a given repository .
7+ Create a Github instance .
88
99``` js
1010var github = new Github ({
1111 username: " YOU_USER" ,
1212 password: " YOUR_PASSWORD" ,
1313 auth: " basic"
1414});
15+ ```
16+
17+ Or if you prefer OAuth, it looks like this:
1518
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
1629var repo = github .getRepo (reponame);
1730```
1831
Original file line number Diff line number Diff line change 1- // Github.js 0.4 .0
1+ // Github.js 0.5 .0
22// (c) 2012 Michael Aufreiter, Development Seed
33// Github.js is freely distributable under the MIT license.
44// For all details and documentation:
99 var API_URL = 'https://api.github.com' ;
1010
1111 Github = window . Github = function ( options ) {
12- var username = options . username ;
13- var password = options . password ;
1412
1513 // Util
1614 // =======
1715
1816 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+
1923 $ . ajax ( {
2024 type : method ,
2125 url : API_URL + path ,
2428 contentType : 'application/x-www-form-urlencoded' ,
2529 success : function ( res ) { cb ( null , res ) ; } ,
2630 error : function ( err ) { cb ( err ) ; } ,
27- headers : { Authorization : 'Basic ' + Base64 . encode ( username + ':' + password ) }
31+ headers : headers ( )
2832 } ) ;
2933 }
3034
156160 var data = {
157161 "message" : message ,
158162 "author" : {
159- "name" : username
163+ "name" : options . username
160164 } ,
161165 "parents" : [
162166 parent
You can’t perform that action at this time.
0 commit comments