β A small yet useful .Net library for manage GitHub Gists via API and in a very easy way!
β
If you have some issues with the code, open an issue.
β
For questions, ideas, how-to, etc, please use the discussions area, thanks!
- Browse your own Gists or Gists of any user or by ID, date, pagination and revision
- Create, edit and delete Gists
- Rename and delete Gists files
- More to come...
- Ensure that you have installed .Net 6 Runtime
- Download the release
- Add it as a dependency to your project
- Get a GitHub classic Token from here or a new beta Token from here.
- Copy and paste the code below
- Enjoy!
Just add these lines of code in your project!
Be careful, these examples are for .Net 6. For use them in .Net Framework, you need to change any new(...)
with new ClassName(...)
, example:
GistNet.Create TheGist = new("YOUR_GITHUB_TOKEN");
will be GistNet.Create TheGist = new GistNet.Create("YOUR_GITHUB_TOKEN");
.
Also, ensure that your method is async, as the example: From this private void Button1_Click
to this private async void Button1_Click
.
GistNet.Explore ExploreCollection = new("YOUR_GITHUB_TOKEN");
string ReturnedString = await ExploreCollection.GetAll();
In this case, you will get your latest 30
Gists.
By adding and int after the username, you will be able to browse the pagination.
In this case, you will get the page 2
on the default 30 per page
.
GistNet.Explore ExploreCollection = new("YOUR_GITHUB_TOKEN", 2);
In this case, 10
is the max results for each page, and 2
is the current page to fetch.
GistNet.Explore ExploreCollection = new("YOUR_GITHUB_TOKEN", 10, 2);
It is possible to add a DateTime
to show only Gists created or edited after the gived date.
In this example, will return only Gists post 2 November 2022 @ 18:20:00
.
GistNet.Explore ExploreCollection = new("YOUR_GITHUB_TOKEN", new DateTime(2022, 11, 2, 18, 20, 0));
Of course you can combine any of above, in this way:
GistNet.Explore ExploreCollection = new("YOUR_GITHUB_TOKEN", new DateTime(2022, 11, 2, 18, 20, 0), 10, 2);
GistNet.MyGists MyCollection = new("YOUR_GITHUB_TOKEN");
string ReturnedString = await MyCollection.GetAll();
In this case, you will get your latest 30
Gists.
You can combine by page or date same as the Explore function, just change GistNet.Explore
with GistNet.MyGists
.
GistNet.GetByUser UserCollection = new("YOUR_GITHUB_TOKEN", "RallyTuning");
string ReturnedString = await UserCollection.GetAll();
In this case, you will get the latest 30
(public) Gist of the selected username. (If this is the owner of the token, you will get the last 30 public and secret Gists).
You can combine by page or date same as the Explore function, just change GistNet.Explore
with GistNet.GetByUser
.
Easy as the name suggest, you will get a single Gist by the ID. (In this way, you will get also history
and forks
of the Gist).
GistNet.GetByID TheGist = new("YOUR_GITHUB_TOKEN", "GIST_ID");
string ReturnedString = await TheGist.Get();
You can set the visibility, description and add as many files you want.
GistNet.Create TheGist = new("YOUR_GITHUB_TOKEN");
TheGist.Content.IsPublic = true; // Or false for a secret Gist
TheGist.Content.Description = "A short description of your Gist";
TheGist.Content.Files.Add("Your new file.txt", new("Something cool inside the file"));
TheGist.Content.Files.Add("Another file.txt", new("Something really really cool"));
string ReturnedString = await TheGist.Push();
It will return a JSON with the details of the new Gist.
You can edit the Gist description and a content of any existing file, just "add" them inside the Files
list.
GistNet.UpdateGist TheGist = new("YOUR_GITHUB_TOKEN", "GIST_ID");
TheGist.Content.Description = "New cool description";
TheGist.Content.Files.Add("Existing file.txt", new("New content..."));
TheGist.Content.Files.Add("Another existing file.txt", new("Another new content of the file..."));
string ReturnedString = await TheGist.Patch();
GistNet.Delete TheGist = new("YOUR_GITHUB_TOKEN", "GIST_ID");
string ReturnedString = await TheGist.Confirm();
It will not return a JSON, but the StatusCodes of the HTTP Request.
GistNet.RenameFiles TheGist = new("YOUR_GITHUB_TOKEN", "GIST_ID");
TheGist.Content.Files.Add("Existing file.txt", new GistNet.RenameFiles.Details.FileContent("New name.txt"));
string ReturnedString = await TheGist.Patch();
It is possible to rename multiple files at once, just "add" them inside the Files
list.
For delete a file(s), just "add" the name in the list and set the content of it to null
or better, like the example, new()
.
GistNet.DeleteFiles TheGist = new("YOUR_GITHUB_TOKEN", "GIST_ID");
TheGist.Content.Files.Add("File to delete.txt", new());
string ReturnedString = await TheGist.Patch();
It is possible to delete multiple files at once, just "add" them inside the Files
list.
You can know the SHA
of any Gist revision, by looking in the history
node of any returned JSON.
GistNet.GetGistRevision TheGist = new("YOUR_GITHUB_TOKEN", "GIST_ID", "SHA_OF_THE_REVISION");
string ReturnedString = await TheGist.Get();
- Nothing yet π₯³
- List starred gists
- List gist commits
- List gist forks
- Fork a gist
- Check if a gist is starred
- Star a gist
- Unstar a gist