(url:string, callback:(error:Error, content?:GistResponse) => void)
| 207 | interface GistResponse {id: string, url: string, files: {[name:string]: {content: string}}} |
| 208 | |
| 209 | export function readFromGist(url:string, callback:(error:Error, content?:GistResponse) => void) { |
| 210 | let gistId = gistIdFromUrl(url); |
| 211 | |
| 212 | if(!gistId) return callback(new Error(`Invalid gist url: '${url}'.`)); |
| 213 | |
| 214 | let apiUrl = `https://api.github.com/gists/${gistId}`; |
| 215 | |
| 216 | let request = new XMLHttpRequest(); |
| 217 | request.onreadystatechange = function() { |
| 218 | if(request.readyState === 4) { |
| 219 | if(request.status !== 200) { |
| 220 | return callback(new Error(`HTTP Response: ${request.status}`)); |
| 221 | } |
| 222 | |
| 223 | let response = JSON.parse(request.responseText); |
| 224 | |
| 225 | callback(undefined, response); |
| 226 | } |
| 227 | } |
| 228 | request.open("GET", apiUrl); |
| 229 | request.send(); |
| 230 | } |
no test coverage detected