|
1 | | -// Github.js 0.6.1 |
| 1 | +// Github.js 0.6.2 |
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: |
|
16 | 16 | function headers() { |
17 | 17 | var headers = {} |
18 | 18 | if (options.auth === 'oauth' && !options.token) return { Accept: 'application/vnd.github.raw' }; |
19 | | - if (options.auth === 'basic' && (!options.username || !options.password)) return { Accept: 'application/vnd.github.raw' }; |
| 19 | + if (options.auth === 'basic' && (!options.username || !options.password)) return { Accept: 'application/vnd.github.raw' }; |
20 | 20 | return options.auth == 'oauth' |
21 | | - ? { Authorization: 'token '+ options.token, Accept: 'application/vnd.github.raw' } |
| 21 | + ? { Authorization: 'token '+ options.token, Accept: 'application/vnd.github.raw' } |
22 | 22 | : { Authorization : 'Basic ' + Base64.encode(options.username + ':' + options.password), Accept: 'application/vnd.github.raw' } |
23 | 23 | } |
24 | 24 |
|
25 | | - function _request(method, path, data, cb) { |
26 | | - $.ajax({ |
27 | | - type: method, |
28 | | - url: API_URL + path, |
29 | | - data: JSON.stringify(data), |
30 | | - dataType: 'json', |
31 | | - contentType: 'application/x-www-form-urlencoded', |
32 | | - success: function(res) { cb(null, res); }, |
33 | | - error: function(err) { cb(err); }, |
34 | | - headers : headers() |
35 | | - }); |
36 | | - } |
37 | | - |
38 | | - function _raw_request(method, path, data, cb) { |
39 | | - $.ajax({ |
40 | | - type: method, |
41 | | - url: API_URL + path, |
42 | | - data: JSON.stringify(data), |
43 | | - contentType: 'application/x-www-form-urlencoded', |
44 | | - success: function(res) { cb(null, res); }, |
45 | | - error: function(err) { cb(err); }, |
46 | | - headers : headers() |
47 | | - }); |
| 25 | + function _request(method, path, data, cb, raw) { |
| 26 | + var xhr = new XMLHttpRequest(); |
| 27 | + if (!raw) {xhr.dataType = "json"} |
| 28 | + xhr.open(method, API_URL + path); |
| 29 | + xhr.onreadystatechange = function () { |
| 30 | + if (this.readyState == 4) { |
| 31 | + this.status == 200 ? cb(null, JSON.parse(this.responseText)) : cb(this.status); |
| 32 | + } |
| 33 | + } |
| 34 | + data ? xhr.send(JSON.stringify(data)) : xhr.send(); |
48 | 35 | } |
49 | 36 |
|
50 | 37 | // User API |
|
156 | 143 | // ------- |
157 | 144 |
|
158 | 145 | this.getBlob = function(sha, cb) { |
159 | | - _raw_request("GET", repoPath + "/git/blobs/" + sha, null, cb); |
| 146 | + _request("GET", repoPath + "/git/blobs/" + sha, null, cb, 'raw'); |
160 | 147 | }; |
161 | 148 |
|
162 | 149 | // For a given file path, get the corresponding sha (blob for files, tree for dirs) |
|
0 commit comments