(name:string, content:string, callback:(error:Error, url?:string) => void)
| 180 | } |
| 181 | |
| 182 | export function writeToGist(name:string, content:string, callback:(error:Error, url?:string) => void) { |
| 183 | name = dasherize(name); |
| 184 | let request = new XMLHttpRequest(); |
| 185 | request.onreadystatechange = function() { |
| 186 | if(request.readyState === 4) { |
| 187 | if(request.status !== 201) { |
| 188 | return callback(new Error(`HTTP Response: ${request.status}`)); |
| 189 | } |
| 190 | let response:any = JSON.parse(request.responseText); |
| 191 | let file = response.files[name]; |
| 192 | let url = file.raw_url.split("/raw/")[0]; |
| 193 | let err = (file.truncated) ? new Error("File to large: Maximum gist size is 10mb") : undefined; |
| 194 | callback(err, url); |
| 195 | } |
| 196 | }; |
| 197 | let payload = { |
| 198 | public: true, |
| 199 | description: "", |
| 200 | files: {} |
| 201 | } |
| 202 | payload.files[name] = {content: content}; |
| 203 | request.open("POST", "https://api.github.com/gists"); |
| 204 | request.send(JSON.stringify(payload)); |
| 205 | } |
| 206 | |
| 207 | interface GistResponse {id: string, url: string, files: {[name:string]: {content: string}}} |
| 208 |
no test coverage detected