Skip to content

Instantly share code, notes, and snippets.

@JoeGlines
Last active August 22, 2024 02:58
Show Gist options
  • Save JoeGlines/ecc02d061dd1c6a4d426a6e4e1061df5 to your computer and use it in GitHub Desktop.
Save JoeGlines/ecc02d061dd1c6a4d426a6e4e1061df5 to your computer and use it in GitHub Desktop.
API call to push GIST
;*******************************************************
; Want a clear path for learning AutoHotkey; Take a look at our AutoHotkey Udemy courses. They're structured in a way to make learning AHK EASY
; Right now you can get a coupon code here: https://the-Automator.com/Learn
;*******************************************************
;~ #Include <default_Settings> ;~ https://gist.github.com/JoeGlines
IniRead,Token,B:\Guests\Chad\Github Gist\Creds.ini,Credentials,Token ;Get your own Token and put in here
WinGetTitle, ActiveWindow , A
if (instr(ActiveWindow,"AHK Studio"))
NNE:=SplitPath(ActiveWindow).NNE
Clipboard:=""
Send ^c
ClipWait, 1
If ErrorLevel { ;Added errorLevel checking
Clipboard:=ClipBack ;Restore Clipboard
MsgBox, No text was sent to clipboard
Return
}
gui, add,text,,Name of file (don't add .ahk)
gui, add,edit,w200 vFileName,%NNE%
gui, add,text,,Description
gui, add,edit,w200 vDescr
gui, Add, Button, default, Gist ; The label ButtonOK (if it exists) will be run when the button is pressed.
gui, show, autosize
return
GuiClose:
ButtonGist:
Gui, Submit ; Save the input from the user to each control's associated variable.
Filename:= (SubStr(filename,-3)=".ahk")?(SubStr(Filename,1,StrLen(Filename)-4)):Filename ;just in case they end it with .ahk
Body:=Jxon_Dump({content:Clipboard})
Data={"description": "%Descr%","public": true,"files": {"%FileName%.ahk": %Body%}}
Obj:=ParseJSON(Send(Token,"https://api.github.com/gists","POST",Data))
Clipboard:="<script src='https://gist.github.com/JoeGlines/"(SubStr(obj.url,Instr(obj.url,"/",,0)+1))".js'></script>`n`nYou can get the code here: " obj.html_url
DebugWindow("The clipboard now has:`n" clipboard,Clear:=1,LineBreak:=1,Sleep:=500,AutoHide:=0)
ExitApp
return
Send(Token,URL:="",Verb:="",Data:=""){
static WebRequest:=ComObjCreate("WinHttp.WinHttpRequest.5.1") ;Create COM object
WebRequest.Open(Verb,URL) ;Open connection
WebRequest.SetRequestHeader("Authorization","token " Token,0)
WebRequest.SetRequestHeader("Content-Type","application/json")
WebRequest.Send(Data) ;Send Payload
return WebRequest.ResponseText
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment