|
1 | | -// Github.js 0.5.0 |
| 1 | +// Github.js 0.5.1 |
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: |
|
13 | 13 | // Util |
14 | 14 | // ======= |
15 | 15 |
|
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 | | - } |
| 16 | + function headers() { |
| 17 | + return options.auth == 'oauth' |
| 18 | + ? { Authorization: 'token '+ options.token, Accept: 'application/vnd.github.raw' } |
| 19 | + : { Authorization : 'Basic ' + Base64.encode(options.username + ':' + options.password) } |
| 20 | + } |
22 | 21 |
|
| 22 | + function _request(method, path, data, cb) { |
23 | 23 | $.ajax({ |
24 | 24 | type: method, |
25 | 25 | url: API_URL + path, |
|
32 | 32 | }); |
33 | 33 | } |
34 | 34 |
|
| 35 | + function _raw_request(method, path, data, cb) { |
| 36 | + $.ajax({ |
| 37 | + type: method, |
| 38 | + url: API_URL + path, |
| 39 | + data: JSON.stringify(data), |
| 40 | + contentType: 'application/x-www-form-urlencoded', |
| 41 | + success: function(res) { cb(null, res); }, |
| 42 | + error: function(err) { cb(err); }, |
| 43 | + headers : headers() |
| 44 | + }); |
| 45 | + } |
| 46 | + |
35 | 47 | // USER API |
36 | 48 | // ======= |
37 | 49 |
|
|
78 | 90 | // ------- |
79 | 91 |
|
80 | 92 | this.getBlob = function(sha, cb) { |
81 | | - _request("GET", repoPath + "/git/blobs/" + sha, null, function(err, res) { |
| 93 | + _raw_request("GET", repoPath + "/git/blobs/" + sha, null, function(err, res) { |
82 | 94 | cb(err, res); |
83 | 95 | }); |
84 | 96 | }; |
|
199 | 211 | that.getSha(branch, path, function(err, sha) { |
200 | 212 | if (!sha) return cb("not found", null); |
201 | 213 |
|
202 | | - that.getBlob(sha, function(err, blob) { |
203 | | - function decode(blob) { |
204 | | - if (blob.content) { |
205 | | - var data = blob.encoding == 'base64' ? |
206 | | - atob(blob.content.replace(/\s/g, '')) : |
207 | | - blob.content; |
208 | | - return data; |
209 | | - } else { |
210 | | - return ""; |
211 | | - } |
212 | | - } |
213 | | - cb(null, decode(blob)); |
214 | | - }); |
| 214 | + that.getBlob(sha, cb); |
215 | 215 | }); |
216 | 216 | }; |
217 | 217 |
|
|
0 commit comments