https://github.com/prabirshrestha/github
github api wrapper for .net
https://github.com/prabirshrestha/github
Last synced: 9 months ago
JSON representation
github api wrapper for .net
- Host: GitHub
- URL: https://github.com/prabirshrestha/github
- Owner: prabirshrestha
- Created: 2011-06-26T19:32:01.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2023-04-11T03:15:00.000Z (over 2 years ago)
- Last Synced: 2025-02-12T22:49:16.430Z (10 months ago)
- Language: C#
- Homepage:
- Size: 425 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Github .NET SDK
This library is a sdk for accessing github's api using
[FluentHttp](https://github.com/prabirshrestha/FluentHttp)
## Features
* supported HTTP methods - GET, POST, PUT, PATCH , DELETE and HEAD
* supported GitHub version - v2 and v3
* supported mode of authentications - HttpBasic and OAuth2
## Samples
### version 3
All github request returns code, headers. Body is returned for all HTTP methods except HEAD.
var gh = new GithubApi(new GithubOAuthAuthenticator("access_token"));
dynamic result = gh.Get(GithubApiVersion.V3, "/user/followers");
var httpStatusCode = result.code;
var httpResponseHeaders = result.headers;
var rateLimit = httpResponseHeaders["X-RateLimit-Limit"];
var rateLimitRemaining = httpResponseHeaders["X-RateLimit-Remaining"];
dynamic response = result.body;
The body is a json object (IDicitionary<string,object>) or json array (IList<object>)
Example for PUT: (follow user)
gh.Put(GithubApiVersion.V3, "/user/following/prabirshrestha");
Example for POST: (create key)
var parameters = new Dictionary();
parameters["title"] = title;
parameters["key"] = key;
dynamic result = gh.Post(GithubApiVersion.V3, "/user/keys", parameters);
Example for PATCH: (update key)
var parameters = new Dictionary();
if (!string.IsNullOrEmpty(title))
parameters["title"] = title;
if (!string.IsNullOrEmpty(key))
parameters["key"] = key;
if (parameters.Count == 0)
throw new System.ArgumentException("Specify at least title or key");
dynamic result = gh.Patch(GithubApiVersion.V3, string.Concat("/user/keys/", id), parameters);
Example for DELETE: (delete key)
gh.Delete(GithubApiVersion.V3, string.Concat("/user/keys/", id));
### version 2 & downloading files
This example shows downloading files using github api version 2.
Like all api requests code, headers and body is returned. Body contains the byte[] which is the file.
dynamic result = gh.Get(
GithubApiVersion.V2, "/blob/show/defunkt/facebox/d4fc2d5e810d9b4bc1ce67702603080e3086a4ed");
var httpStatusCode = result.code;
var httpResponseHeaders = result.headers;
var file = result.body;
using (var fs = new FileStream("D:\\a.txt", FileMode.Create))
{
fs.Write(file, 0, file.Length);
}
### Async sample
gh.GetAsync(GithubApiVersion.V3, "/users/prabirshresth/gists", null, null,
ar =>
{
if (ar.Exception != null)
Console.WriteLine(ar.Exception);
Console.WriteLine(ar.Result);
});
## License
Apache License v2.0