Package: gists.py
gists.pyA simple asynchronous python wrapper for theGitHub GistsAPIThis API wrapper mainly focuses on the Gists part of the GitHub API, not the entire APIFeaturesAll unchecked features are plannedGistsGETing from/gists, to get authenticated user's GistsGETing from/users/{username}/giststo get a user's GistsGETing from/gists/publicto get public GistsGETing from/gists/starredto get authenticated user's starred GistsPOSTing to/gists, to create a GistGETing from/gists/{gist_id}to get a GistPATCHing to/gists/{gist_id}, to edit a GistDELETEing from/gists/{gist_id}to delete a GistGists - ForksPOSTing to/gists/{gist_id}/forksto fork a Gist to the authenticated user's profileGists - StarGETing from/gists/{gist_id}/starto check if a gist is starred by the authenticated userPUTing/gists/{gist_id}/starto star a Gist with the authenticated userDELETEing from/gists/{gist_id}/starto unstar a Gist with the authenticated userGists - CommentsGETing from/gists/{gist_id}/commentsto get all comments on a GistPOSTing to/gists/{gist_id}/commentsto create a comment on a GistGETing from/gists/{gist_id}/comments/{comment_id}to get a comment on a GistPATCHing to/gists/{gist_id}/comments/{comment_id}to edit a comment of the authenticated user on a GistDELETEing from/gists/{gist_id}/comments/{comment_id}to delete a comment of the authenticated user on a GistInstallationWindowspy-mpipinstallgists.pyorpy-mpipinstallgit+https://github.com/WitherredAway/gists.pyLinux/macOSpython3-mpipinstallgists.pyorpython3-mpipinstallgit+https://github.com/WitherredAway/gists.pyUsage examplesThis section is a work in progressImport gists and instantiate a client# Import asyncioimportasyncio# Import the packageimportgists# Create a client instanceclient=gists.Client()Get a gistasyncdefmain_get():# Getting a gist does not require authorization# This method fetches the gist associated with the provided gist id, and returns a Gist objectgist=awaitclient.get_gist("GIST ID")returngist# Run the main_get() functiongist=asyncio.run(main_get())# Print the gist's descriptionprint(gist.description)Create a new gistasyncdefmain_create()->gists.Gist:# Creating a gist requires authorization, use client.authorize to authorize the clientawaitclient.authorize("YOUR GITHUB PERSONAL ACCESS TOKEN")# The description to setdescription="Hi this is a gist"# The files to create in the new gistfiles=[gists.File(name="example.txt",content="I like turtles"),gists.File(name="helloworld.py",content="print(\"Hello, world!\")"),]# Whether or not the gist should be publicpublic=True# This method creates a new gist and returns a Gist object associated with that gistgist=awaitclient.create_gist(files=files,description=description,public=public)returngist# Run the main_create() functiongist_1=asyncio.run(main_create())# Print the gist's idprint(gist_1.id)Edit gist using the edit method of a Gist objectasyncdefmain_edit():# Editing a gist requires authorization, but we already authorized the client when creating the gist# The description to edit todescription="Hello this is a gist, but edited"# The files to edit in gistfiles=[# Use a unique filename for the name parameter to create a new filegists.File(name="newfile.txt",content="New file"),# Use an existing filename for the name parameter to edit that filegists.File(name="example.txt",content="I like all animals"),# Use an existing filename for the name parameter and# pass in the new_name parameter to edit the name of that file,# in which case the content parameter is not mandatorygists.File(name="helloworld.py",new_name="hellouniverse.py")]awaitgist_1.edit(files=files,description=description)# Run the main_edit() functionasyncio.run(main_edit())# Print the gist's edited descriptionprint(gist_1.description)