Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Created January 26, 2017 15:05
Show Gist options
  • Save tmplinshi/6e57d1391031eeea53218bb47ac8e462 to your computer and use it in GitHub Desktop.
Save tmplinshi/6e57d1391031eeea53218bb47ac8e462 to your computer and use it in GitHub Desktop.
CreateGist(content, description:="", filename:="file1.ahk", token:="", public:=true) {
url := "https://api.github.com/gists"
obj := { "description": description
, "public": (public ? "true" : "false")
, "files": { (filename): {"content": content} } }
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("POST", url)
whr.SetRequestHeader("Content-Type", "application/json; charset=utf-8")
if token {
whr.SetRequestHeader("Authorization", "token " token)
}
whr.Send( JSON_FromObj(obj) )
if retUrl := JSON_ToObj(whr.ResponseText).html_url
return retUrl
else
throw, whr.ResponseText
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment