├── .gitignore ├── GitHubSharp.sln ├── GitHubSharp ├── Client.cs ├── Controllers │ ├── AuthorizationsController.cs │ ├── CommentsController.cs │ ├── CommitsController.cs │ ├── Controller.cs │ ├── GistsController.cs │ ├── IssuesController.cs │ ├── LabelsController.cs │ ├── MarkdownController.cs │ ├── MilestonesController.cs │ ├── NotificationsController.cs │ ├── OrganizationsController.cs │ ├── PullRequestsController.cs │ ├── RepositoriesController.cs │ ├── TeamsController.cs │ └── UsersController.cs ├── Exceptions.cs ├── GitHubRequest.cs ├── GitHubResponse.cs ├── GitHubSharp.csproj ├── GitHubSharp.nuspec ├── IJsonSerializer.cs ├── Models │ ├── AuthorizationModel.cs │ ├── BasicUserModel.cs │ ├── ChangeStatusModel.cs │ ├── CommentModel.cs │ ├── CommitModel.cs │ ├── ContentModel.cs │ ├── ErrorModel.cs │ ├── EventModel.cs │ ├── ForkModel.cs │ ├── GistModel.cs │ ├── HistoryModel.cs │ ├── IssueModel.cs │ ├── NotificationModel.cs │ ├── ObjectModel.cs │ ├── PullRequestModel.cs │ ├── ReleaseModel.cs │ ├── RepositoryModel.cs │ ├── SubscriptionModel.cs │ ├── TeamModel.cs │ ├── TreeModel.cs │ └── UserModel.cs ├── Properties │ └── AssemblyInfo.cs ├── SimpleJsonSerializer.cs ├── Utils │ └── ObjectToDictionaryConverter.cs └── packages.config ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | *.userprefs 4 | *.suo 5 | *.DS_store 6 | /packages 7 | -------------------------------------------------------------------------------- /GitHubSharp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHubSharp", "GitHubSharp\GitHubSharp.csproj", "{07CD9573-CF93-4CF9-B3D6-501D30B6AD12}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {07CD9573-CF93-4CF9-B3D6-501D30B6AD12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {07CD9573-CF93-4CF9-B3D6-501D30B6AD12}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {07CD9573-CF93-4CF9-B3D6-501D30B6AD12}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {07CD9573-CF93-4CF9-B3D6-501D30B6AD12}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(MonoDevelopProperties) = preSolution 18 | Policies = $0 19 | $0.DotNetNamingPolicy = $1 20 | $1.DirectoryNamespaceAssociation = None 21 | $1.ResourceNamePolicy = FileFormatDefault 22 | $0.TextStylePolicy = $2 23 | $2.EolMarker = Unix 24 | $2.inheritsSet = VisualStudio 25 | $2.inheritsScope = text/plain 26 | $2.scope = text/x-csharp 27 | $0.CSharpFormattingPolicy = $3 28 | $3.IndentSwitchBody = True 29 | $3.IndentBlocksInsideExpressions = True 30 | $3.AnonymousMethodBraceStyle = NextLine 31 | $3.PropertyBraceStyle = NextLine 32 | $3.PropertyGetBraceStyle = NextLine 33 | $3.PropertySetBraceStyle = NextLine 34 | $3.EventBraceStyle = NextLine 35 | $3.EventAddBraceStyle = NextLine 36 | $3.EventRemoveBraceStyle = NextLine 37 | $3.StatementBraceStyle = NextLine 38 | $3.ElseNewLinePlacement = NewLine 39 | $3.CatchNewLinePlacement = NewLine 40 | $3.FinallyNewLinePlacement = NewLine 41 | $3.WhileNewLinePlacement = DoNotCare 42 | $3.ArrayInitializerWrapping = DoNotChange 43 | $3.ArrayInitializerBraceStyle = NextLine 44 | $3.BeforeMethodDeclarationParentheses = False 45 | $3.BeforeMethodCallParentheses = False 46 | $3.BeforeConstructorDeclarationParentheses = False 47 | $3.NewLineBeforeConstructorInitializerColon = NewLine 48 | $3.NewLineAfterConstructorInitializerColon = SameLine 49 | $3.BeforeDelegateDeclarationParentheses = False 50 | $3.NewParentheses = False 51 | $3.SpacesBeforeBrackets = False 52 | $3.inheritsSet = Mono 53 | $3.inheritsScope = text/x-csharp 54 | $3.scope = text/x-csharp 55 | EndGlobalSection 56 | GlobalSection(SolutionProperties) = preSolution 57 | HideSolutionNode = FALSE 58 | EndGlobalSection 59 | EndGlobal 60 | -------------------------------------------------------------------------------- /GitHubSharp/Client.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using GitHubSharp.Utils; 5 | using GitHubSharp.Controllers; 6 | using System.Threading.Tasks; 7 | using GitHubSharp.Models; 8 | using System.Net.Http; 9 | using System.Text; 10 | using System.Linq; 11 | 12 | namespace GitHubSharp 13 | { 14 | public class Client 15 | { 16 | public const string DefaultApi = "https://api.github.com"; 17 | 18 | public const string AccessTokenUri = "https://github.com"; 19 | 20 | public static Func ClientConstructor = () => new HttpClient(); 21 | 22 | public static IJsonSerializer Serializer = new SimpleJsonSerializer(); 23 | 24 | private readonly HttpClient _client; 25 | 26 | public string ApiUri { get; private set; } 27 | 28 | public AuthenticatedUserController AuthenticatedUser 29 | { 30 | get { return new AuthenticatedUserController(this); } 31 | } 32 | 33 | public UsersController Users 34 | { 35 | get { return new UsersController(this); } 36 | } 37 | 38 | public NotificationsController Notifications 39 | { 40 | get { return new NotificationsController(this); } 41 | } 42 | 43 | public ExploreRepositoriesController Repositories 44 | { 45 | get { return new ExploreRepositoriesController(this); } 46 | } 47 | 48 | public MarkdownController Markdown 49 | { 50 | get { return new MarkdownController(this); } 51 | } 52 | 53 | public TeamsController Teams 54 | { 55 | get { return new TeamsController(this); } 56 | } 57 | 58 | public OrganizationsController Organizations 59 | { 60 | get { return new OrganizationsController(this); } 61 | } 62 | 63 | public GistsController Gists 64 | { 65 | get { return new GistsController(this); } 66 | } 67 | 68 | public AuthorizationsController Authorizations 69 | { 70 | get { return new AuthorizationsController(this); } 71 | } 72 | 73 | /// 74 | /// Gets the username for this client 75 | /// 76 | public string Username { get; set; } 77 | 78 | /// 79 | /// Gets or sets the timeout. 80 | /// 81 | /// 82 | /// The timeout. 83 | /// 84 | public TimeSpan Timeout 85 | { 86 | get { return _client.Timeout; } 87 | set { _client.Timeout = value; } 88 | } 89 | 90 | /// 91 | /// Constructor 92 | /// 93 | private Client() 94 | { 95 | _client = ClientConstructor(); 96 | _client.DefaultRequestHeaders.UserAgent.ParseAdd("GithubSharp"); 97 | Timeout = new TimeSpan(0, 0, 20); 98 | } 99 | 100 | /// 101 | /// Create a BASIC Auth Client 102 | /// 103 | public static Client Basic(string username, string password, string apiUri = DefaultApi) 104 | { 105 | if (string.IsNullOrEmpty(apiUri)) 106 | apiUri = DefaultApi; 107 | 108 | if (string.IsNullOrEmpty(username)) 109 | throw new ArgumentException("Username must be valid!"); 110 | 111 | if (string.IsNullOrEmpty(password)) 112 | throw new ArgumentException("Password must be valid!"); 113 | 114 | Uri apiOut; 115 | if (!Uri.TryCreate(apiUri, UriKind.Absolute, out apiOut)) 116 | throw new ArgumentException("The URL, " + apiUri + ", is not valid!"); 117 | 118 | var c = new Client(); 119 | c.Username = username; 120 | c.ApiUri = apiOut.AbsoluteUri.TrimEnd('/'); 121 | 122 | var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", username, password))); 123 | c._client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", token); 124 | return c; 125 | } 126 | 127 | /// 128 | /// Create a TwoFactor(BASIC + X-GitHub-OTP) Auth Client 129 | /// 130 | public static Client BasicTwoFactorAuthentication(string username, string password, string twoFactor, string apiUri = DefaultApi) 131 | { 132 | var c = Basic(username, password, apiUri); 133 | c._client.DefaultRequestHeaders.Add("X-GitHub-OTP", twoFactor); 134 | return c; 135 | } 136 | 137 | /// 138 | /// Create a BASIC OAuth client 139 | /// 140 | public static Client BasicOAuth(string oauth, string apiUri = DefaultApi) 141 | { 142 | if (string.IsNullOrEmpty(apiUri)) 143 | apiUri = DefaultApi; 144 | 145 | Uri apiOut; 146 | if (!Uri.TryCreate(apiUri, UriKind.Absolute, out apiOut)) 147 | throw new ArgumentException("The URL, " + apiUri + ", is not valid!"); 148 | 149 | var c = new Client(); 150 | c.ApiUri = apiOut.AbsoluteUri.TrimEnd('/'); 151 | var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", oauth, "x-oauth-basic"))); 152 | c._client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", token); 153 | return c; 154 | } 155 | 156 | /// 157 | /// Request an access token 158 | /// 159 | public static async Task RequestAccessToken(string clientId, string clientSecret, string code, string redirectUri, string domainUri = AccessTokenUri) 160 | { 161 | if (string.IsNullOrEmpty(domainUri)) 162 | domainUri = AccessTokenUri; 163 | 164 | if (!domainUri.EndsWith("/", StringComparison.Ordinal)) 165 | domainUri += "/"; 166 | domainUri += "login/oauth/access_token"; 167 | 168 | var c = new Client(); 169 | 170 | using (var r = new HttpRequestMessage(HttpMethod.Post, domainUri)) 171 | { 172 | var args = new { client_id = clientId, client_secret = clientSecret, code, redirect_uri = redirectUri }; 173 | var serialized = Serializer.Serialize(args); 174 | r.Content = new StringContent(serialized, Encoding.UTF8, "application/json"); 175 | r.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); 176 | using (var response = await c.ExecuteRequest(r).ConfigureAwait(false)) 177 | return (await ParseResponse(response).ConfigureAwait(false)).Data; 178 | } 179 | } 180 | 181 | private static string ToQueryString(IEnumerable> nvc) 182 | { 183 | var array = (from key in nvc 184 | select string.Format("{0}={1}", Uri.EscapeDataString(key.Key), Uri.EscapeDataString(key.Value))) 185 | .ToArray(); 186 | return "?" + string.Join("&", array); 187 | } 188 | 189 | /// 190 | /// Makes a 'GET' request to the server using a URI 191 | /// 192 | /// The type of object the response should be deserialized ot 193 | /// An object with response data 194 | private async Task> Get(GitHubRequest githubRequest) where T : new() 195 | { 196 | var url = new StringBuilder().Append(githubRequest.Url); 197 | if (githubRequest.Args != null) 198 | url.Append(ToQueryString(ObjectToDictionaryConverter.Convert(githubRequest.Args).ToArray())); 199 | var absoluteUrl = url.ToString(); 200 | 201 | // If there is no cache, just directly execute and parse. Nothing more 202 | using (var request = new HttpRequestMessage(HttpMethod.Get, absoluteUrl)) 203 | { 204 | using (var requestResponse = await ExecuteRequest(request).ConfigureAwait(false)) 205 | { 206 | return await ParseResponse(requestResponse).ConfigureAwait(false); 207 | } 208 | } 209 | } 210 | 211 | private static HttpRequestMessage CreatePutRequest(GitHubRequest request) 212 | { 213 | var r = new HttpRequestMessage(HttpMethod.Put, request.Url); 214 | if (request.Args != null) 215 | { 216 | var serialized = Serializer.Serialize(request.Args); 217 | r.Content = new StringContent(serialized, Encoding.UTF8, "application/json"); 218 | } 219 | else 220 | { 221 | r.Content = new StringContent(""); 222 | r.Content.Headers.ContentLength = 0; 223 | } 224 | return r; 225 | } 226 | 227 | /// 228 | /// Makes a 'PUT' request to the server 229 | /// 230 | private async Task> Put(GitHubRequest gitHubRequest) where T : new() 231 | { 232 | using (var request = CreatePutRequest(gitHubRequest)) 233 | { 234 | using (var response = await ExecuteRequest(request).ConfigureAwait(false)) 235 | { 236 | return await ParseResponse(response).ConfigureAwait(false); 237 | } 238 | } 239 | } 240 | 241 | /// 242 | /// Makes a 'PUT' request to the server 243 | /// 244 | private async Task Put(GitHubRequest gitHubRequest) 245 | { 246 | using (var request = CreatePutRequest(gitHubRequest)) 247 | { 248 | using (var response = await ExecuteRequest(request).ConfigureAwait(false)) 249 | { 250 | return await ParseResponse(response).ConfigureAwait(false); 251 | } 252 | } 253 | } 254 | 255 | /// 256 | /// Makes a 'POST' request to the server 257 | /// 258 | private async Task> Post(GitHubRequest request) where T : new() 259 | { 260 | using (var r = new HttpRequestMessage(HttpMethod.Post, request.Url)) 261 | { 262 | if (request.Args != null) 263 | { 264 | var serialized = Serializer.Serialize(request.Args); 265 | r.Content = new StringContent(serialized, Encoding.UTF8, "application/json"); 266 | } 267 | 268 | using (var response = await ExecuteRequest(r).ConfigureAwait(false)) 269 | { 270 | return await ParseResponse(response).ConfigureAwait(false); 271 | } 272 | } 273 | } 274 | 275 | /// 276 | /// Makes a 'DELETE' request to the server 277 | /// 278 | private async Task Delete(GitHubRequest request) 279 | { 280 | using (var r = new HttpRequestMessage(HttpMethod.Delete, request.Url)) 281 | { 282 | using (var response = await ExecuteRequest(r).ConfigureAwait(false)) 283 | { 284 | return await ParseResponse(response).ConfigureAwait(false); 285 | } 286 | } 287 | } 288 | 289 | private static HttpRequestMessage CreatePatchRequest(GitHubRequest request) 290 | { 291 | using (var r = new HttpRequestMessage(new HttpMethod("PATCH"), request.Url)) 292 | { 293 | if (request.Args != null) 294 | { 295 | var serialized = Serializer.Serialize(request.Args); 296 | r.Content = new StringContent(serialized, Encoding.UTF8, "application/json"); 297 | } 298 | return r; 299 | } 300 | } 301 | 302 | private async Task> Patch(GitHubRequest gitHubRequest) where T : new() 303 | { 304 | using (var request = CreatePatchRequest(gitHubRequest)) 305 | { 306 | using (var response = await ExecuteRequest(request).ConfigureAwait(false)) 307 | { 308 | return await ParseResponse(response).ConfigureAwait(false); 309 | } 310 | } 311 | } 312 | 313 | private async Task Patch(GitHubRequest gitHubRequest) 314 | { 315 | using (var request = CreatePatchRequest(gitHubRequest)) 316 | { 317 | using (var response = await ExecuteRequest(request).ConfigureAwait(false)) 318 | { 319 | return await ParseResponse(response).ConfigureAwait(false); 320 | } 321 | } 322 | } 323 | 324 | private static async Task> ParseResponse(HttpResponseMessage response) where T : new() 325 | { 326 | var ghr = new GitHubResponse { StatusCode = (int)response.StatusCode }; 327 | 328 | foreach (var h in response.Headers) 329 | { 330 | if (h.Key.Equals("X-RateLimit-Limit")) 331 | ghr.RateLimitLimit = Convert.ToInt32(h.Value.First()); 332 | else if (h.Key.Equals("X-RateLimit-Remaining")) 333 | ghr.RateLimitRemaining = Convert.ToInt32(h.Value.First()); 334 | else if (h.Key.Equals("ETag")) 335 | ghr.ETag = h.Value.First().Replace("\"", "").Trim(); 336 | else if (h.Key.Equals("Link")) 337 | { 338 | var s = h.Value.First().Split(','); 339 | foreach (var link in s) 340 | { 341 | var splitted = link.Split(';'); 342 | var url = splitted[0].Trim(); 343 | var what = splitted[1].Trim(); 344 | what = what.Substring(5); 345 | what = what.Substring(0, what.Length - 1); 346 | url = url.Substring(1); 347 | url = url.Substring(0, url.Length - 1); 348 | 349 | if (what.Equals("next")) 350 | { 351 | ghr.More = GitHubRequest.Get(url); 352 | } 353 | } 354 | } 355 | } 356 | 357 | // Booleans have a special definition in the github responses. 358 | // They typically represent a status code Not Found = false 359 | // or 204 = true and 205 (reset content) 360 | if (typeof(T) == typeof(bool) && (ghr.StatusCode == 204 || ghr.StatusCode == 205 || ghr.StatusCode == 404)) 361 | { 362 | var b = ghr.StatusCode == 204 || ghr.StatusCode == 205; 363 | ghr.Data = (T)(object)(b); 364 | return ghr; 365 | } 366 | 367 | var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); 368 | 369 | if (response.StatusCode < (HttpStatusCode)200 || response.StatusCode >= (HttpStatusCode)300) 370 | throw StatusCodeException.FactoryCreate(response, content); 371 | 372 | ghr.Data = Serializer.Deserialize(content); 373 | 374 | return ghr; 375 | } 376 | 377 | private static async Task ParseResponse(HttpResponseMessage response) 378 | { 379 | var ghr = new GitHubResponse { StatusCode = (int)response.StatusCode }; 380 | foreach (var h in response.Headers) 381 | { 382 | if (h.Key.Equals("X-RateLimit-Limit")) 383 | ghr.RateLimitLimit = Convert.ToInt32(h.Value.First()); 384 | else if (h.Key.Equals("X-RateLimit-Remaining")) 385 | ghr.RateLimitRemaining = Convert.ToInt32(h.Value.First()); 386 | else if (h.Key.Equals("ETag")) 387 | ghr.ETag = h.Value.First().Replace("\"", ""); 388 | } 389 | 390 | var content = await response.Content.ReadAsStringAsync(); 391 | if (response.StatusCode < (HttpStatusCode)200 || response.StatusCode >= (HttpStatusCode)300) 392 | throw StatusCodeException.FactoryCreate(response, content); 393 | 394 | return ghr; 395 | } 396 | 397 | /// 398 | /// Executes a request to the server 399 | /// 400 | internal async Task ExecuteRequest(HttpRequestMessage request) 401 | { 402 | try 403 | { 404 | if (request.Headers.Accept.Count == 0) 405 | request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/vnd.github.v3.full+json")); 406 | return await _client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); 407 | } 408 | catch (TaskCanceledException e) 409 | { 410 | // Provide a better error message 411 | throw new TaskCanceledException("Timeout waiting for GitHub to respond. Check your connection and try again.", e); 412 | } 413 | catch(WebException e) 414 | { 415 | // Provide a better error message 416 | throw new WebException("Unable to communicate with GitHub. Please check your connection and try again.", e); 417 | } 418 | } 419 | 420 | public Task ExecuteAsync(GitHubRequest request) 421 | { 422 | switch (request.RequestMethod) 423 | { 424 | case RequestMethod.DELETE: 425 | return Delete(request); 426 | case RequestMethod.PUT: 427 | return Put(request); 428 | case RequestMethod.PATCH: 429 | return Patch(request); 430 | default: 431 | return null; 432 | } 433 | } 434 | 435 | public Task> ExecuteAsync(GitHubRequest request) where T : new() 436 | { 437 | switch (request.RequestMethod) 438 | { 439 | case RequestMethod.GET: 440 | return Get(request); 441 | case RequestMethod.POST: 442 | return Post(request); 443 | case RequestMethod.PUT: 444 | return Put(request); 445 | case RequestMethod.PATCH: 446 | return Patch(request); 447 | default: 448 | return null; 449 | } 450 | } 451 | 452 | // public bool IsCached(GitHubRequest request) 453 | // { 454 | // if (Cache == null || request.RequestMethod != RequestMethod.GET) 455 | // return false; 456 | // 457 | // var req = new RestRequest(request.Url, Method.GET); 458 | // if (request.Args != null) 459 | // foreach (var arg in ObjectToDictionaryConverter.Convert(request.Args)) 460 | // req.AddParameter(arg.Key, arg.Value); 461 | // 462 | // return Cache.Exists(_client.BuildUri(req).AbsoluteUri); 463 | // } 464 | 465 | public async Task DownloadRawResource(string rawUrl, System.IO.Stream downloadSream) 466 | { 467 | using (var request = new HttpRequestMessage(HttpMethod.Get, rawUrl)) 468 | { 469 | using (var response = await ExecuteRequest(request)) 470 | { 471 | using (var stream = await response.Content.ReadAsStreamAsync()) 472 | { 473 | stream.CopyTo(downloadSream); 474 | return "" + response.Content.Headers.ContentType; 475 | } 476 | } 477 | } 478 | } 479 | 480 | public async Task DownloadRawResource2(string rawUrl, System.IO.Stream downloadSream) 481 | { 482 | using (var request = new HttpRequestMessage(HttpMethod.Get, rawUrl)) 483 | { 484 | request.Headers.Accept.Clear(); 485 | request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/vnd.github.raw")); 486 | using (var response = await ExecuteRequest(request)) 487 | { 488 | using (var stream = await response.Content.ReadAsStreamAsync()) 489 | { 490 | stream.CopyTo(downloadSream); 491 | return "" + response.Content.Headers.ContentType; 492 | } 493 | } 494 | } 495 | } 496 | } 497 | } 498 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/AuthorizationsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using GitHubSharp.Controllers; 3 | using System.Collections.Generic; 4 | using GitHubSharp.Models; 5 | 6 | namespace GitHubSharp 7 | { 8 | public class AuthorizationsController : Controller 9 | { 10 | public AuthorizationsController(Client client) 11 | : base(client) 12 | { 13 | } 14 | 15 | public GitHubRequest GetOrCreate(string clientId, string clientSecret, List scopes, string note, string noteUrl) 16 | { 17 | return GitHubRequest.Put(Uri + "/clients/" + clientId, new { client_secret = clientSecret, scopes = scopes, note = note, note_url = noteUrl }); 18 | } 19 | 20 | public GitHubRequest Create(List scopes, string note, string noteUrl, string fingerprint) 21 | { 22 | return GitHubRequest.Post(Uri, new { scopes, note, note_url = noteUrl, fingerprint }); 23 | } 24 | 25 | public override string Uri 26 | { 27 | get { return Client.ApiUri + "/authorizations"; } 28 | } 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/CommentsController.cs: -------------------------------------------------------------------------------- 1 | using GitHubSharp.Models; 2 | using System.Collections.Generic; 3 | 4 | namespace GitHubSharp.Controllers 5 | { 6 | public class CommentsController : Controller 7 | { 8 | public RepositoryController RepositoryController { get; private set; } 9 | 10 | public CommentController this[string key] 11 | { 12 | get { return new CommentController(Client, RepositoryController, key); } 13 | } 14 | 15 | public CommentsController(Client client, RepositoryController repository) 16 | : base(client) 17 | { 18 | RepositoryController = repository; 19 | } 20 | 21 | public GitHubRequest> GetAll(int page = 1, int perPage = 100) 22 | { 23 | return GitHubRequest.Get>(Uri, new { page = page, per_page = perPage }); 24 | } 25 | 26 | public override string Uri 27 | { 28 | get { return RepositoryController.Uri + "/comments"; } 29 | } 30 | } 31 | 32 | public class CommentController : Controller 33 | { 34 | public RepositoryController RepositoryController { get; private set; } 35 | 36 | public string Id { get; private set; } 37 | 38 | public CommentController(Client client, RepositoryController repositoryController, string id) 39 | : base(client) 40 | { 41 | RepositoryController = repositoryController; 42 | Id = id; 43 | } 44 | 45 | public GitHubRequest Get() 46 | { 47 | return GitHubRequest.Get(Uri); 48 | } 49 | 50 | public GitHubRequest Update(string body) 51 | { 52 | return GitHubRequest.Patch(Uri, new { body = body }); 53 | } 54 | 55 | public GitHubRequest Delete() 56 | { 57 | return GitHubRequest.Delete(Uri); 58 | } 59 | 60 | public override string Uri 61 | { 62 | get { return RepositoryController.Uri + "/comments/" + Id; } 63 | } 64 | } 65 | 66 | public class CommitCommentsController : Controller 67 | { 68 | public CommitController CommitController { get; private set; } 69 | 70 | public CommentController this[string key] 71 | { 72 | get { return new CommentController(Client, CommitController.RepositoryController, key); } 73 | } 74 | 75 | public CommitCommentsController(Client client, CommitController commits) 76 | : base(client) 77 | { 78 | CommitController = commits; 79 | } 80 | 81 | public GitHubRequest Create(string body, string path = null, int? position = null) 82 | { 83 | return GitHubRequest.Post(Uri, new { body = body, path = path, position = position }); 84 | } 85 | 86 | public GitHubRequest> GetAll(int page = 1, int perPage = 100) 87 | { 88 | return GitHubRequest.Get>(Uri, new { page = page, per_page = perPage }); 89 | } 90 | 91 | public override string Uri 92 | { 93 | get { return CommitController.Uri + "/comments"; } 94 | } 95 | } 96 | 97 | public class PullRequestCommentsController : Controller 98 | { 99 | public PullRequestController Parent { get; private set; } 100 | 101 | public PullRequestCommentsController(Client client, PullRequestController parent) 102 | : base(client) 103 | { 104 | Parent = parent; 105 | } 106 | 107 | public GitHubRequest> GetAll(int page = 1, int perPage = 100) 108 | { 109 | return GitHubRequest.Get>(Uri, new { page = page, per_page = perPage }); 110 | } 111 | 112 | public GitHubRequest Create(string body, string commitId, string path, int position) 113 | { 114 | return GitHubRequest.Post(Uri, new { body = body, commit_id = commitId, path = path, position = position }); 115 | } 116 | 117 | public GitHubRequest ReplyTo(string body, long replyToId) 118 | { 119 | return GitHubRequest.Post(Uri, new { body = body, in_reply_to = replyToId }); 120 | } 121 | 122 | public override string Uri 123 | { 124 | get { return Parent.Uri + "/comments"; } 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/CommitsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using GitHubSharp.Models; 3 | using System.Collections.Generic; 4 | 5 | namespace GitHubSharp.Controllers 6 | { 7 | public class CommitsController : Controller 8 | { 9 | public string FilePath { get; set; } 10 | 11 | public RepositoryController RepositoryController { get; private set; } 12 | 13 | public CommitController this[string key] 14 | { 15 | get { return new CommitController(Client, RepositoryController, key); } 16 | } 17 | 18 | public CommitsController(Client client, RepositoryController repo) 19 | : base(client) 20 | { 21 | RepositoryController = repo; 22 | } 23 | 24 | public GitHubRequest> GetAll(string sha = null) 25 | { 26 | if (sha == null) 27 | return GitHubRequest.Get>(Uri); 28 | else 29 | return GitHubRequest.Get>(Uri, new { sha = sha }); 30 | } 31 | 32 | public override string Uri 33 | { 34 | get { return RepositoryController.Uri + "/commits" + (string.IsNullOrEmpty(this.FilePath) ? string.Empty : "?path=" + this.FilePath); } 35 | } 36 | } 37 | 38 | public class CommitController : Controller 39 | { 40 | public RepositoryController RepositoryController { get; private set; } 41 | 42 | public string Sha { get; private set; } 43 | 44 | public CommitCommentsController Comments 45 | { 46 | get { return new CommitCommentsController(Client, this); } 47 | } 48 | 49 | public CommitController(Client client, RepositoryController repositoryController, string sha) 50 | : base(client) 51 | { 52 | RepositoryController = repositoryController; 53 | Sha = sha; 54 | } 55 | 56 | public GitHubRequest Get() 57 | { 58 | return GitHubRequest.Get(Uri); 59 | } 60 | 61 | public override string Uri 62 | { 63 | get { return RepositoryController.Uri + "/commits/" + Sha; } 64 | } 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/Controller.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace GitHubSharp.Controllers 8 | { 9 | public abstract class Controller 10 | { 11 | protected readonly Client Client; 12 | 13 | /// 14 | /// Constructor 15 | /// 16 | /// The GitHubSharp client object 17 | protected Controller(Client client) 18 | { 19 | Client = client; 20 | } 21 | 22 | /// 23 | /// A URI representing this controller 24 | /// 25 | public abstract String Uri { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/GistsController.cs: -------------------------------------------------------------------------------- 1 | using GitHubSharp.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace GitHubSharp.Controllers 9 | { 10 | public class GistsController : Controller 11 | { 12 | public GistController this[string key] 13 | { 14 | get { return new GistController(Client, this, key); } 15 | } 16 | 17 | public GistsController(Client client) 18 | : base(client) 19 | { 20 | } 21 | 22 | public GitHubRequest> GetGists(int page = 1, int perPage = 100) 23 | { 24 | return GitHubRequest.Get>(Uri, new { page = page, per_page = perPage }); 25 | } 26 | 27 | public GitHubRequest> GetPublicGists(int page = 1, int perPage = 100) 28 | { 29 | return GitHubRequest.Get>(Uri + "/public", new { page = page, per_page = perPage }); 30 | } 31 | 32 | public GitHubRequest> GetStarredGists(int page = 1, int perPage = 100) 33 | { 34 | return GitHubRequest.Get>(Uri + "/starred", new { page = page, per_page = perPage }); 35 | } 36 | 37 | public override string Uri 38 | { 39 | get { return Client.ApiUri + "/gists"; } 40 | } 41 | } 42 | 43 | public class UserGistsController : Controller 44 | { 45 | private readonly string _user; 46 | 47 | public UserGistsController(Client client, string user) 48 | : base(client) 49 | { 50 | _user = user; 51 | } 52 | 53 | public GitHubRequest> GetGists(int page = 1, int perPage = 100) 54 | { 55 | return GitHubRequest.Get>(Uri, new { page = page, per_page = perPage }); 56 | } 57 | 58 | public override string Uri 59 | { 60 | get { return Client.ApiUri + "/users/" + _user + "/gists"; } 61 | } 62 | } 63 | 64 | public class AuthenticatedGistsController : UserGistsController 65 | { 66 | public AuthenticatedGistsController(Client client) 67 | : base(client, client.Username) 68 | { 69 | } 70 | 71 | public GitHubRequest CreateGist(GistCreateModel gist) 72 | { 73 | //Great... The RestSharp serializer can't handle this object... 74 | //Dictionary confuses it and converts it into {"key": "ok", "value": "dokie"} 75 | //instead of {"ok": "dokie"} 76 | var obj = new Dictionary(); 77 | obj.Add("description", gist.Description); 78 | obj.Add("public", gist.Public); 79 | 80 | var files = new Dictionary(); 81 | obj.Add("files", files); 82 | 83 | if (gist.Files != null) 84 | { 85 | foreach (var f in gist.Files.Keys) 86 | { 87 | var content = new Dictionary(); 88 | files.Add(f, content); 89 | content.Add("content", gist.Files[f].Content); 90 | } 91 | } 92 | 93 | return GitHubRequest.Post(Client.ApiUri + "/gists", obj); 94 | } 95 | } 96 | 97 | public class GistController : Controller 98 | { 99 | private readonly string _name; 100 | 101 | public GistsController GistsController { get; private set; } 102 | 103 | public GistController(Client client, GistsController gistsController, string name) 104 | : base(client) 105 | { 106 | _name = name; 107 | GistsController = gistsController; 108 | } 109 | 110 | public GitHubRequest Get() 111 | { 112 | return GitHubRequest.Get(Uri); 113 | } 114 | 115 | public GitHubRequest Star() 116 | { 117 | return GitHubRequest.Put(Uri + "/star"); 118 | } 119 | 120 | public GitHubRequest Unstar() 121 | { 122 | return GitHubRequest.Delete(Uri + "/star"); 123 | } 124 | 125 | public GitHubRequest> GetComments() 126 | { 127 | return GitHubRequest.Get>(Uri + "/comments"); 128 | } 129 | 130 | public GitHubRequest ForkGist() 131 | { 132 | return GitHubRequest.Post(Uri + "/forks"); 133 | } 134 | 135 | public GitHubRequest Delete() 136 | { 137 | return GitHubRequest.Delete(Uri); 138 | } 139 | 140 | public GitHubRequest IsGistStarred() 141 | { 142 | return GitHubRequest.Get(Uri + "/star"); 143 | } 144 | 145 | public GitHubRequest CreateGistComment(string body) 146 | { 147 | return GitHubRequest.Post(Uri + "/comments", new { body = body }); 148 | 149 | } 150 | 151 | public GitHubRequest EditGist(GistEditModel gist) 152 | { 153 | 154 | var obj = new Dictionary(); 155 | obj.Add("description", gist.Description); 156 | 157 | var files = new Dictionary(); 158 | obj.Add("files", files); 159 | 160 | if (gist.Files != null) 161 | { 162 | foreach (var f in gist.Files.Keys) 163 | { 164 | if (gist.Files[f] == null) 165 | { 166 | files.Add(f, null); 167 | } 168 | else 169 | { 170 | var content = new Dictionary(); 171 | files.Add(f, content); 172 | content.Add("content", gist.Files[f].Content); 173 | 174 | if (gist.Files[f].Filename != null) 175 | content.Add("filename", gist.Files[f].Filename); 176 | } 177 | } 178 | } 179 | 180 | return GitHubRequest.Patch(Uri, obj); 181 | } 182 | 183 | public override string Uri 184 | { 185 | get { return GistsController.Uri + "/" + _name; } 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/IssuesController.cs: -------------------------------------------------------------------------------- 1 | using GitHubSharp.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace GitHubSharp.Controllers 9 | { 10 | public abstract class IssuesController : Controller 11 | { 12 | public IssuesController(Client client) 13 | : base(client) 14 | { 15 | } 16 | 17 | public GitHubRequest> GetAll(int page = 1, int perPage = 100, 18 | string milestone = null, string state = null, string assignee = null, 19 | string creator = null, string mentioned = null, string labels = null, 20 | string sort = null, string direction = null) 21 | { 22 | return GitHubRequest.Get>(Uri, new { 23 | Milestone = milestone, State = state, Assignee = assignee, 24 | Creator = creator, Mentioned = mentioned, Labels = labels, 25 | Sort = sort, Direction = direction, 26 | page = page, per_page = perPage 27 | }); 28 | } 29 | } 30 | 31 | public class AuthenticatedUserIssuesController : Controller 32 | { 33 | public AuthenticatedUserIssuesController(Client client) 34 | : base(client) 35 | { 36 | } 37 | 38 | public GitHubRequest> GetAll(int page = 1, int perPage = 100, 39 | string filter = null, string state = null, string labels = null, 40 | string sort = null, string direction = null, string since = null) 41 | { 42 | return GitHubRequest.Get>(Uri, new { 43 | Filter = filter, State = state, Labels = labels, 44 | Sort = sort, Direction = direction, Since = since, 45 | page = page, per_page = perPage 46 | }); 47 | } 48 | 49 | public override string Uri 50 | { 51 | get { return Client.ApiUri + "/user/issues"; } 52 | } 53 | } 54 | 55 | public class OrganizationIssuesController : IssuesController 56 | { 57 | public OrganizationController Parent { get; private set; } 58 | 59 | public OrganizationIssuesController(Client client, OrganizationController parent) 60 | : base(client) 61 | { 62 | Parent = parent; 63 | } 64 | 65 | public override string Uri 66 | { 67 | get { return Parent.Uri + "/issues"; } 68 | } 69 | } 70 | 71 | public class RepositoryIssuesController : IssuesController 72 | { 73 | public RepositoryController Parent { get; private set; } 74 | 75 | public IssueController this[long id] 76 | { 77 | get { return new IssueController(Client, this, id); } 78 | } 79 | 80 | public RepositoryIssuesController(Client client, RepositoryController parent) 81 | : base(client) 82 | { 83 | Parent = parent; 84 | } 85 | 86 | public GitHubRequest Create(string title, string body, string assignee, int? milestone, string[] labels) 87 | { 88 | return GitHubRequest.Post(Uri, new { title = title, body = body, assignee = assignee, milestone = milestone, labels = labels }); 89 | } 90 | 91 | public override string Uri 92 | { 93 | get { return Parent.Uri + "/issues"; } 94 | } 95 | 96 | public GitHubRequest> GetEvents() 97 | { 98 | return GitHubRequest.Get>(Uri + "/events"); 99 | } 100 | } 101 | 102 | public class IssueController : Controller 103 | { 104 | public long Id { get; private set; } 105 | 106 | public RepositoryIssuesController Parent { get; private set; } 107 | 108 | public IssueController(Client client, RepositoryIssuesController parent, long id) 109 | : base(client) 110 | { 111 | Parent = parent; 112 | Id = id; 113 | } 114 | 115 | public GitHubRequest Get() 116 | { 117 | return GitHubRequest.Get(Uri); 118 | } 119 | 120 | public GitHubRequest> GetEvents(int page = 1, int perPage = 100) 121 | { 122 | return GitHubRequest.Get>(Uri + "/events", new { page = page, per_page = perPage }); 123 | } 124 | 125 | public GitHubRequest> GetComments(int page = 1, int perPage = 100) 126 | { 127 | return GitHubRequest.Get>(Uri + "/comments", new { page = page, per_page = perPage }); 128 | } 129 | 130 | public GitHubRequest CreateComment(string body) 131 | { 132 | return GitHubRequest.Post(Uri + "/comments", new { body = body }); 133 | } 134 | 135 | public GitHubRequest Update(string title, string body, string state, string assignee, int? milestone, string[] labels) 136 | { 137 | return GitHubRequest.Patch(Uri, new { title, body, assignee, milestone, labels, state }); 138 | } 139 | 140 | public GitHubRequest UpdateAssignee(string assignee) 141 | { 142 | return GitHubRequest.Patch(Uri, new { assignee }); 143 | } 144 | 145 | public GitHubRequest UpdateMilestone(int? milestone) 146 | { 147 | return GitHubRequest.Patch(Uri, new { milestone }); 148 | } 149 | 150 | public GitHubRequest UpdateLabels(IEnumerable labels) 151 | { 152 | return GitHubRequest.Patch(Uri, new { labels = labels.ToArray() }); 153 | } 154 | 155 | public GitHubRequest UpdateState(string state) 156 | { 157 | return GitHubRequest.Patch(Uri, new { state }); 158 | } 159 | 160 | public override string Uri 161 | { 162 | get { return Parent.Uri + "/" + Id; } 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/LabelsController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using GitHubSharp.Models; 3 | 4 | namespace GitHubSharp.Controllers 5 | { 6 | public class LabelsController : Controller 7 | { 8 | public RepositoryController Parent { get; private set; } 9 | 10 | public LabelController this[string name] 11 | { 12 | get { return new LabelController(Client, this, name); } 13 | } 14 | 15 | public LabelsController(Client client, RepositoryController parentController) 16 | : base(client) 17 | { 18 | Parent = parentController; 19 | } 20 | 21 | public GitHubRequest> GetAll(int page = 1, int perPage = 100) 22 | { 23 | return GitHubRequest.Get>(Uri, new { page, per_page = perPage }); 24 | } 25 | 26 | public GitHubRequest Create(string name, string color) 27 | { 28 | return GitHubRequest.Post(Uri, new { name, color }); 29 | } 30 | 31 | public override string Uri 32 | { 33 | get { return Parent.Uri + "/labels"; } 34 | } 35 | } 36 | 37 | public class LabelController : Controller 38 | { 39 | public LabelsController Parent { get; private set; } 40 | 41 | public string Name { get; private set; } 42 | 43 | public LabelController(Client client, LabelsController parentController, string name) 44 | : base(client) 45 | { 46 | Parent = parentController; 47 | Name = name; 48 | } 49 | 50 | public GitHubRequest Delete() 51 | { 52 | return GitHubRequest.Delete(Uri); 53 | } 54 | 55 | public GitHubRequest Update(string title, string color) 56 | { 57 | return GitHubRequest.Patch(Uri, new { title, color }); 58 | } 59 | 60 | public override string Uri 61 | { 62 | get { return Parent.Uri + "/" + System.Uri.EscapeDataString(Name); } 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /GitHubSharp/Controllers/MarkdownController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Net.Http; 7 | 8 | namespace GitHubSharp.Controllers 9 | { 10 | public class MarkdownController : Controller 11 | { 12 | public MarkdownController(Client client) 13 | : base(client) 14 | { 15 | } 16 | 17 | public async Task GetMarkdown(string text) 18 | { 19 | var req = new HttpRequestMessage(HttpMethod.Post, Uri); 20 | req.Content = new StringContent(text, Encoding.UTF8, "text/plain"); 21 | var data = await Client.ExecuteRequest(req).ConfigureAwait(false); 22 | return await data.Content.ReadAsStringAsync().ConfigureAwait(false); 23 | } 24 | 25 | public override string Uri 26 | { 27 | get { return Client.ApiUri + "/markdown/raw"; } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/MilestonesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using GitHubSharp.Models; 4 | 5 | namespace GitHubSharp.Controllers 6 | { 7 | public class MilestonesController : Controller 8 | { 9 | public RepositoryController RepositoryController { get; private set; } 10 | 11 | public MilestonesController(Client client, RepositoryController repository) 12 | : base(client) 13 | { 14 | RepositoryController = repository; 15 | } 16 | 17 | public GitHubRequest> GetAll(bool opened = true, string sort = "due_date", string direction = "desc") 18 | { 19 | return GitHubRequest.Get>(Uri, new { state = opened ? "open" : "closed", sort, direction }); 20 | } 21 | 22 | public GitHubRequest Get(int milestoneNumber) 23 | { 24 | return GitHubRequest.Get(Uri + "/" + milestoneNumber); 25 | } 26 | 27 | public override string Uri 28 | { 29 | get { return RepositoryController.Uri + "/milestones"; } 30 | } 31 | 32 | public GitHubRequest Create(string title, bool open, string description, DateTimeOffset dueDate) 33 | { 34 | return GitHubRequest.Post(Uri, 35 | new {Title = title, State = open ? "open" : "closed", Description = description, DueOn = dueDate}); 36 | } 37 | 38 | public GitHubRequest Delete(string url) 39 | { 40 | return GitHubRequest.Delete(url); 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/NotificationsController.cs: -------------------------------------------------------------------------------- 1 | using GitHubSharp.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace GitHubSharp.Controllers 9 | { 10 | public class NotificationController : Controller 11 | { 12 | public string Id { get; private set; } 13 | 14 | public NotificationController(Client client, string id) 15 | : base(client) 16 | { 17 | Id = id; 18 | } 19 | 20 | public GitHubRequest Get() 21 | { 22 | return GitHubRequest.Get(Uri); 23 | } 24 | 25 | public GitHubRequest MarkAsRead() 26 | { 27 | return GitHubRequest.Patch(Uri); 28 | } 29 | 30 | public override string Uri 31 | { 32 | get { return Client.ApiUri + "/notifications/threads/" + Id; } 33 | } 34 | } 35 | 36 | public class NotificationsController : Controller 37 | { 38 | public NotificationController this[string id] 39 | { 40 | get { return new NotificationController(Client, id); } 41 | } 42 | 43 | public NotificationsController(Client client) 44 | : base(client) 45 | { 46 | } 47 | 48 | public GitHubRequest> GetAll(int page = 1, int perPage = 100, bool? all = null, bool? participating = null) 49 | { 50 | return GitHubRequest.Get>(Uri, new { page = page, per_page = perPage, all = all, participating = participating }); 51 | } 52 | 53 | public GitHubRequest MarkAsRead(DateTime? lastReadAt = null) 54 | { 55 | var data = new Dictionary(); 56 | if (lastReadAt != null) 57 | data.Add("last_read_at", string.Concat(lastReadAt.Value.ToString("s"), "Z")); 58 | return GitHubRequest.Put(Uri, data); 59 | } 60 | 61 | public GitHubRequest MarkRepoAsRead(string username, string repository, DateTime? lastReadAt = null) 62 | { 63 | var data = new Dictionary(); 64 | if (lastReadAt != null) 65 | data.Add("last_read_at", string.Concat(lastReadAt.Value.ToString("s"), "Z")); 66 | return GitHubRequest.Put(Client.ApiUri + "/repos/" + username + "/" + repository + "/notifications", data); 67 | } 68 | 69 | public override string Uri 70 | { 71 | get { return Client.ApiUri + "/notifications"; } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/OrganizationsController.cs: -------------------------------------------------------------------------------- 1 | using GitHubSharp.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace GitHubSharp.Controllers 9 | { 10 | public class OrganizationsController : Controller 11 | { 12 | public OrganizationController this[string name] 13 | { 14 | get { return new OrganizationController(Client, this, name); } 15 | } 16 | 17 | public OrganizationsController(Client client) 18 | : base(client) 19 | { 20 | } 21 | 22 | public override string Uri 23 | { 24 | get { return Client.ApiUri + "/orgs"; } 25 | } 26 | } 27 | 28 | public class OrganizationController : Controller 29 | { 30 | public string Name { get; private set; } 31 | 32 | public OrganizationsController OrganizationsController { get; private set; } 33 | 34 | public OrginzationRepositoriesController Repositories 35 | { 36 | get { return new OrginzationRepositoriesController(Client, this); } 37 | } 38 | 39 | public OrganizationController(Client client, OrganizationsController organizationsController, string name) 40 | : base(client) 41 | { 42 | Name = name; 43 | OrganizationsController = organizationsController; 44 | } 45 | 46 | public GitHubRequest Get() 47 | { 48 | return GitHubRequest.Get(Uri); 49 | } 50 | 51 | public GitHubRequest> GetMembers(int page = 1, int perPage = 100) 52 | { 53 | return GitHubRequest.Get>(Uri + "/members", new { page = page, per_page = perPage }); 54 | } 55 | 56 | public GitHubRequest> GetTeams(int page = 1, int perPage = 100) 57 | { 58 | return GitHubRequest.Get>(Uri + "/teams", new { page = page, per_page = perPage }); 59 | } 60 | 61 | public GitHubRequest> GetEvents(int page = 1, int perPage = 100) 62 | { 63 | return GitHubRequest.Get>(Uri + "/events", new { page = page, per_page = perPage }); 64 | } 65 | 66 | public override string Uri 67 | { 68 | get { return OrganizationsController.Uri + "/" + Name; } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/PullRequestsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using GitHubSharp.Models; 6 | 7 | namespace GitHubSharp.Controllers 8 | { 9 | public class PullRequestsController : Controller 10 | { 11 | public RepositoryController Parent { get; private set; } 12 | 13 | public PullRequestController this[long id] 14 | { 15 | get { return new PullRequestController(Client, this, id); } 16 | } 17 | 18 | public PullRequestsController(Client client, RepositoryController parent) 19 | : base(client) 20 | { 21 | Parent = parent; 22 | } 23 | 24 | public GitHubRequest> GetAll(int page = 1, int perPage = 100, string state = "open") 25 | { 26 | return GitHubRequest.Get>(Uri, new { page = page, per_page = perPage, state = state }); 27 | } 28 | 29 | public override string Uri 30 | { 31 | get { return Parent.Uri + "/pulls"; } 32 | } 33 | } 34 | 35 | public class PullRequestController : Controller 36 | { 37 | public PullRequestsController Parent { get; private set; } 38 | 39 | public long Id { get; private set; } 40 | 41 | public PullRequestCommentsController Comments 42 | { 43 | get { return new PullRequestCommentsController(Client, this); } 44 | } 45 | 46 | public PullRequestController(Client client, PullRequestsController parent, long id) 47 | : base(client) 48 | { 49 | Parent = parent; 50 | Id = id; 51 | } 52 | 53 | public GitHubRequest Get() 54 | { 55 | return GitHubRequest.Get(Uri); 56 | } 57 | 58 | public GitHubRequest> GetFiles(int page = 1, int perPage = 100) 59 | { 60 | return GitHubRequest.Get>(Uri + "/files", new { page = page, per_page = perPage }); 61 | } 62 | 63 | public GitHubRequest> GetCommits(int page = 1, int perPage = 100) 64 | { 65 | return GitHubRequest.Get>(Uri + "/commits", new { page = page, per_page = perPage }); 66 | } 67 | 68 | public GitHubRequest Merge(string commit_message = null) 69 | { 70 | return GitHubRequest.Put(Uri + "/merge", new { commit_message = commit_message }); 71 | } 72 | 73 | public GitHubRequest UpdateState(string state) 74 | { 75 | return GitHubRequest.Patch(Uri, new { state }); 76 | } 77 | 78 | public GitHubRequest IsMerged() 79 | { 80 | return GitHubRequest.Get(Uri + "/merge"); 81 | } 82 | 83 | public override string Uri 84 | { 85 | get { return Parent.Uri + "/" + Id; } 86 | } 87 | } 88 | } 89 | 90 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/RepositoriesController.cs: -------------------------------------------------------------------------------- 1 | using GitHubSharp.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Net.Http; 8 | 9 | namespace GitHubSharp.Controllers 10 | { 11 | public class ExploreRepositoriesController : Controller 12 | { 13 | public ExploreRepositoriesController(Client client) 14 | : base(client) 15 | { 16 | } 17 | 18 | public GitHubRequest SearchRepositories(string[] keywords, string[] languages, string sort = null, int page = 1) 19 | { 20 | var sb = new StringBuilder(); 21 | sb.Append(string.Join(" ", keywords)); 22 | sb.Append(' '); 23 | foreach (var l in languages) 24 | sb.Append("language:").Append(l).Append(' '); 25 | 26 | 27 | return GitHubRequest.Get(Uri, new { q = sb.ToString().Trim(), page = page, sort = sort }); 28 | } 29 | 30 | public override string Uri 31 | { 32 | get { return Client.ApiUri + "/search/repositories"; } 33 | } 34 | } 35 | 36 | public class UserRepositoriesController : Controller 37 | { 38 | public UserController UserController { get; private set; } 39 | 40 | public RepositoryController this[string key] 41 | { 42 | get { return new RepositoryController(Client, UserController.Name, key); } 43 | } 44 | 45 | public UserRepositoriesController(Client client, UserController userController) 46 | : base(client) 47 | { 48 | UserController = userController; 49 | } 50 | 51 | public GitHubRequest> GetAll(int page = 1, int perPage = 100) 52 | { 53 | return GitHubRequest.Get>(Uri, new { page = page, per_page = perPage }); 54 | } 55 | 56 | public GitHubRequest> GetWatching() 57 | { 58 | return GitHubRequest.Get>(UserController.Uri + "/subscriptions"); 59 | } 60 | 61 | public override string Uri 62 | { 63 | get { return UserController.Uri + "/repos"; } 64 | } 65 | } 66 | 67 | public class AuthenticatedRepositoriesController : Controller 68 | { 69 | public RepositoryController this[string key] 70 | { 71 | get { return new RepositoryController(Client, Client.Username, key); } 72 | } 73 | 74 | public AuthenticatedRepositoriesController(Client client) 75 | : base(client) 76 | { 77 | } 78 | 79 | public GitHubRequest> GetAll(string affiliation = null, int page = 1, int perPage = 100) 80 | { 81 | return GitHubRequest.Get>(Uri + "/repos", new { 82 | page, 83 | per_page = perPage, 84 | affiliation 85 | }); 86 | } 87 | 88 | public GitHubRequest> GetStarred(int page = 1, int perPage = 100) 89 | { 90 | return GitHubRequest.Get>(Uri + "/starred", new { page = page, per_page = perPage }); 91 | } 92 | 93 | public GitHubRequest> GetWatching(int page = 1, int perPage = 100) 94 | { 95 | return GitHubRequest.Get>(Uri + "/subscriptions", new { page = page, per_page = perPage }); 96 | } 97 | 98 | public override string Uri 99 | { 100 | get { return Client.ApiUri + "/user"; } 101 | } 102 | } 103 | 104 | public class OrginzationRepositoriesController : Controller 105 | { 106 | public OrganizationController OrganizationController { get; private set; } 107 | 108 | public RepositoryController this[string key] 109 | { 110 | get { return new RepositoryController(Client, OrganizationController.Name, key); } 111 | } 112 | 113 | public OrginzationRepositoriesController(Client client, OrganizationController organizationController) 114 | : base(client) 115 | { 116 | OrganizationController = organizationController; 117 | } 118 | 119 | public GitHubRequest> GetAll(int page = 1, int perPage = 100) 120 | { 121 | return GitHubRequest.Get>(Uri, new { page = page, per_page = perPage }); 122 | } 123 | 124 | public override string Uri 125 | { 126 | get { return OrganizationController.Uri + "/repos"; } 127 | } 128 | } 129 | 130 | public class RepositoryController : Controller 131 | { 132 | public string User { get; private set; } 133 | 134 | public string Repo { get; private set; } 135 | 136 | public CommentsController Comments 137 | { 138 | get { return new CommentsController(Client, this); } 139 | } 140 | 141 | public CommitsController Commits 142 | { 143 | get { return new CommitsController(Client, this); } 144 | } 145 | 146 | public RepositoryIssuesController Issues 147 | { 148 | get { return new RepositoryIssuesController(Client, this); } 149 | } 150 | 151 | public PullRequestsController PullRequests 152 | { 153 | get { return new PullRequestsController(Client, this); } 154 | } 155 | 156 | public MilestonesController Milestones 157 | { 158 | get { return new MilestonesController(Client, this); } 159 | } 160 | 161 | public LabelsController Labels 162 | { 163 | get { return new LabelsController(Client, this); } 164 | } 165 | 166 | public RepositoryController(Client client, string user, string repo) 167 | : base(client) 168 | { 169 | User = user; 170 | Repo = repo; 171 | } 172 | 173 | public GitHubRequest Get() 174 | { 175 | return GitHubRequest.Get( Uri); 176 | } 177 | 178 | public GitHubRequest> GetContributors(int page = 1, int perPage = 100) 179 | { 180 | return GitHubRequest.Get>( Uri + "/contributors", new { page = page, per_page = perPage }); 181 | } 182 | 183 | public GitHubRequest> GetLanguages(int page = 1, int perPage = 100) 184 | { 185 | return GitHubRequest.Get>( Uri + "/languages", new { page = page, per_page = perPage }); 186 | } 187 | 188 | public GitHubRequest> GetTags(int page = 1, int perPage = 100) 189 | { 190 | return GitHubRequest.Get>( Uri + "/tags", new { page = page, per_page = perPage }); 191 | } 192 | 193 | public GitHubRequest> GetBranches(int page = 1, int perPage = 100) 194 | { 195 | return GitHubRequest.Get>(Uri + "/branches", new { page = page, per_page = perPage }); 196 | } 197 | 198 | public GitHubRequest> GetEvents(int page = 1, int perPage = 100) 199 | { 200 | return GitHubRequest.Get>(Uri + "/events", new { page = page, per_page = perPage }); 201 | } 202 | 203 | public GitHubRequest> GetNetworkEvents(int page = 1, int perPage = 100) 204 | { 205 | return GitHubRequest.Get>(Uri + "/networks/" + User + "/" + Repo + "/events", new { page = page, per_page = perPage }); 206 | } 207 | 208 | public GitHubRequest GetReadme(string branch = null) 209 | { 210 | return GitHubRequest.Get(Uri + "/readme", new { Ref = branch }); 211 | } 212 | 213 | public async Task GetReadmeRendered(string branch = null) 214 | { 215 | var r = string.IsNullOrEmpty(branch) ? string.Empty : "?ref=" + branch; 216 | using (var request = new HttpRequestMessage(HttpMethod.Get, Uri + "/readme" + r)) 217 | { 218 | request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/vnd.github.v3.html")); 219 | using (var requestResponse = await Client.ExecuteRequest(request).ConfigureAwait(false)) 220 | { 221 | return await requestResponse.Content.ReadAsStringAsync().ConfigureAwait(false); 222 | } 223 | } 224 | } 225 | 226 | public GitHubRequest> GetContent(string path = "", string branch = "master") 227 | { 228 | return GitHubRequest.Get>(Uri + "/contents/" + path.TrimStart('/'), new { Ref = branch }); 229 | } 230 | 231 | public GitHubRequest GetContentFile(string path = "", string branch = "master") 232 | { 233 | return GitHubRequest.Get(Uri + "/contents/" + path.TrimStart('/'), new { Ref = branch }); 234 | } 235 | 236 | public async Task GetContentFileRendered(string path = "", string branch = "master") 237 | { 238 | using (var request = new HttpRequestMessage(HttpMethod.Get, Uri + "/contents/" + path.TrimStart('/') + "?ref=" + branch)) 239 | { 240 | request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/vnd.github.v3.html")); 241 | using (var requestResponse = await Client.ExecuteRequest(request).ConfigureAwait(false)) 242 | { 243 | return await requestResponse.Content.ReadAsStringAsync().ConfigureAwait(false); 244 | } 245 | } 246 | } 247 | 248 | public GitHubRequest> GetReleases(int page = 1, int perPage = 100) 249 | { 250 | return GitHubRequest.Get>(Uri + "/releases", new { page = page, per_page = perPage }); 251 | } 252 | 253 | public GitHubRequest GetRelease(long id) 254 | { 255 | return GitHubRequest.Get(Uri + "/releases/" + id); 256 | } 257 | 258 | public GitHubRequest CreateContentFile(string path, string message, string content, string branch = "master") 259 | { 260 | if (null == content) 261 | throw new Exception("Content cannot be null!"); 262 | if (string.IsNullOrEmpty(message)) 263 | throw new Exception("Commit message cannot be empty!"); 264 | 265 | content = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(content)); 266 | return GitHubRequest.Put(Uri + "/contents" + path, new { message, content, branch }); 267 | } 268 | 269 | public GitHubRequest UpdateContentFile(string path, string message, string content, string sha, string branch = "master") 270 | { 271 | if (null == content) 272 | throw new Exception("Content cannot be null!"); 273 | if (string.IsNullOrEmpty(message)) 274 | throw new Exception("Commit message cannot be empty!"); 275 | 276 | content = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(content)); 277 | return GitHubRequest.Put(Uri + "/contents" + path, new { message, content, sha, branch }); 278 | } 279 | 280 | public GitHubRequest GetTree(string sha) 281 | { 282 | return GitHubRequest.Get(Uri + "/git/trees/" + sha); 283 | } 284 | 285 | // public string GetFileRaw(string branch, string file, System.IO.Stream stream) 286 | // { 287 | // var uri = Uri + "/contents/"; 288 | // if (!uri.EndsWith("/") && !file.StartsWith("/")) 289 | // file = "/" + file; 290 | // 291 | // var request = new RestSharp.RestRequest(uri + file); 292 | // request.AddHeader("Accept", "application/vnd.github.raw"); 293 | // request.ResponseWriter = (s) => s.CopyTo(stream); 294 | // var response = Client.ExecuteRequest(request); 295 | // return response.ContentType; 296 | // } 297 | // 298 | public GitHubRequest IsWatching() 299 | { 300 | return GitHubRequest.Get(Client.ApiUri + "/user/subscriptions/" + User + "/" + Repo); 301 | } 302 | 303 | public GitHubRequest IsCollaborator(string username) 304 | { 305 | return GitHubRequest.Get(Client.ApiUri + "/repos/" + User + "/" + Repo + "/collaborators/" + username); 306 | } 307 | 308 | public GitHubRequest Watch() 309 | { 310 | return GitHubRequest.Put(Client.ApiUri + "/user/subscriptions/" + User + "/" + Repo); 311 | } 312 | 313 | public GitHubRequest StopWatching() 314 | { 315 | return GitHubRequest.Delete(Client.ApiUri + "/user/subscriptions/" + User + "/" + Repo); 316 | } 317 | 318 | public GitHubRequest GetSubscription() 319 | { 320 | return GitHubRequest.Get(Uri + "/subscription"); 321 | } 322 | 323 | public GitHubRequest SetSubscription(bool subscribed, bool ignored) 324 | { 325 | var uri = Uri + "/subscription"; 326 | return GitHubRequest.Put(uri, new { Subscribed = subscribed, Ignored = ignored }); 327 | } 328 | 329 | public GitHubRequest DeleteSubscription() 330 | { 331 | return GitHubRequest.Delete(Uri + "/subscription"); 332 | } 333 | 334 | public GitHubRequest> GetStargazers(int page = 1, int perPage = 100) 335 | { 336 | return GitHubRequest.Get>(Uri + "/stargazers", new { page = page, per_page = perPage }); 337 | } 338 | 339 | public GitHubRequest> GetWatchers(int page = 1, int perPage = 100) 340 | { 341 | return GitHubRequest.Get>(Uri + "/subscribers", new { page = page, per_page = perPage }); 342 | } 343 | 344 | 345 | public GitHubRequest IsStarred() 346 | { 347 | return GitHubRequest.Get(Client.ApiUri + "/user/starred/" + User + "/" + Repo); 348 | } 349 | 350 | public GitHubRequest Star() 351 | { 352 | return GitHubRequest.Put(Client.ApiUri + "/user/starred/" + User + "/" + Repo); 353 | } 354 | 355 | public GitHubRequest Unstar() 356 | { 357 | return GitHubRequest.Delete(Client.ApiUri + "/user/starred/" + User + "/" + Repo); 358 | } 359 | 360 | public GitHubRequest> GetCollaborators(int page = 1, int perPage = 100) 361 | { 362 | return GitHubRequest.Get>(Uri + "/collaborators", new { page = page, per_page = perPage }); 363 | } 364 | 365 | public GitHubRequest> GetAssignees(int page = 1, int perPage = 100) 366 | { 367 | return GitHubRequest.Get>(Uri + "/assignees", new { page = page, per_page = perPage }); 368 | } 369 | 370 | public GitHubRequest> GetForks(string sort = "newest", int page = 1, int perPage = 100) 371 | { 372 | return GitHubRequest.Get>(Uri + "/forks", new { page = page, per_page = perPage, sort = sort }); 373 | } 374 | 375 | public override string Uri 376 | { 377 | get { return Client.ApiUri + "/repos/" + User + "/" + Repo; } 378 | } 379 | } 380 | } 381 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/TeamsController.cs: -------------------------------------------------------------------------------- 1 | using GitHubSharp.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace GitHubSharp.Controllers 9 | { 10 | /// 11 | /// A collection of teams 12 | /// 13 | public class TeamsController : Controller 14 | { 15 | /// 16 | /// Gets a specific team 17 | /// 18 | /// The id of the team 19 | /// 20 | public TeamController this[long id] 21 | { 22 | get { return new TeamController(Client, this, id); } 23 | } 24 | 25 | /// 26 | /// Constructor 27 | /// 28 | /// The GitHubSharp client 29 | public TeamsController(Client client) 30 | : base(client) 31 | { 32 | } 33 | 34 | /// 35 | /// Gets all the teams 36 | /// 37 | /// 38 | /// 39 | public GitHubRequest> GetAll() 40 | { 41 | return GitHubRequest.Get>(Uri); 42 | } 43 | 44 | public override string Uri 45 | { 46 | get { return Client.ApiUri + "/teams"; } 47 | } 48 | } 49 | 50 | /// 51 | /// A single team 52 | /// 53 | public class TeamController : Controller 54 | { 55 | /// 56 | /// Gets the id of this team 57 | /// 58 | public long Id { get; private set; } 59 | 60 | /// 61 | /// Gets the parent controller 62 | /// 63 | public TeamsController TeamsController { get; private set; } 64 | 65 | /// 66 | /// Constructor 67 | /// 68 | /// The GitHubSharp client 69 | /// The parent controller 70 | /// The id of this team 71 | public TeamController(Client client, TeamsController teamsController, long id) 72 | : base(client) 73 | { 74 | Id = id; 75 | TeamsController = teamsController; 76 | } 77 | 78 | /// 79 | /// Gets information about this team 80 | /// 81 | /// 82 | /// 83 | public GitHubRequest Get() 84 | { 85 | return GitHubRequest.Get(Uri); 86 | } 87 | 88 | public GitHubRequest> GetMembers(int page = 1, int perPage = 100) 89 | { 90 | return GitHubRequest.Get>(Uri + "/members", new { page = page, per_page = perPage }); 91 | } 92 | 93 | public GitHubRequest> GetRepositories() 94 | { 95 | return GitHubRequest.Get>(Uri + "/repos"); 96 | } 97 | 98 | public override string Uri 99 | { 100 | get { return TeamsController.Uri + "/" + Id; } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /GitHubSharp/Controllers/UsersController.cs: -------------------------------------------------------------------------------- 1 | using GitHubSharp.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace GitHubSharp.Controllers 9 | { 10 | /// 11 | /// A collection of users 12 | /// 13 | public class UsersController : Controller 14 | { 15 | /// 16 | /// Get a specific user 17 | /// 18 | /// The username 19 | /// A controller which represents the user selected 20 | public UserController this[string key] 21 | { 22 | get { return new UserController(Client, key); } 23 | } 24 | 25 | /// 26 | /// Constructor 27 | /// 28 | /// The GitHubSharp client object 29 | public UsersController(Client client) 30 | : base(client) 31 | { 32 | } 33 | 34 | public override string Uri 35 | { 36 | get { throw new NotImplementedException(); } 37 | } 38 | } 39 | 40 | public abstract class BaseUserController : Controller 41 | { 42 | /// 43 | /// Constructor 44 | /// 45 | /// The GitHubSharp client object 46 | public BaseUserController(Client client) 47 | : base(client) 48 | { 49 | } 50 | 51 | /// 52 | /// Get a list of users this user is following 53 | /// 54 | public GitHubRequest> GetFollowing(int page = 1, int perPage = 100) 55 | { 56 | return GitHubRequest.Get>(Uri + "/following", new { page = page, per_page = perPage }); 57 | } 58 | 59 | /// 60 | /// Get a list of users following this user 61 | /// 62 | public GitHubRequest> GetFollowers(int page = 1, int perPage = 100) 63 | { 64 | return GitHubRequest.Get>(Uri + "/followers", new { page = page, per_page = perPage }); 65 | } 66 | 67 | /// 68 | /// Gets the organizations this user belongs to 69 | /// 70 | public GitHubRequest> GetOrganizations() 71 | { 72 | return GitHubRequest.Get>(Uri + "/orgs"); 73 | } 74 | } 75 | 76 | /// 77 | /// A specific user 78 | /// 79 | public class UserController : BaseUserController 80 | { 81 | public string Name { get; private set; } 82 | 83 | /// 84 | /// Gets the user's repositories 85 | /// 86 | public UserRepositoriesController Repositories 87 | { 88 | get { return new UserRepositoriesController(Client, this); } 89 | } 90 | 91 | /// 92 | /// Gets the user's Gists 93 | /// 94 | public UserGistsController Gists 95 | { 96 | get { return new UserGistsController(Client, Name); } 97 | } 98 | 99 | /// 100 | /// Constructor 101 | /// 102 | /// The GitHubSharp client object 103 | /// The name of the user 104 | public UserController(Client client, string name) 105 | : base(client) 106 | { 107 | Name = name; 108 | } 109 | 110 | /// 111 | /// Get the user's information 112 | /// 113 | public GitHubRequest Get() 114 | { 115 | return GitHubRequest.Get(Uri); 116 | } 117 | 118 | /// 119 | /// Gets events for this user 120 | /// 121 | /// 122 | /// 123 | /// 124 | public GitHubRequest> GetEvents(int page = 1, int perPage = 100) 125 | { 126 | return GitHubRequest.Get>(Uri + "/events", new { page = page, per_page = perPage }); 127 | } 128 | 129 | /// 130 | /// Gets received events for this user 131 | /// 132 | /// 133 | /// 134 | /// 135 | public GitHubRequest> GetReceivedEvents(int page = 1, int perPage = 100) 136 | { 137 | return GitHubRequest.Get>(Uri + "/received_events", new { page = page, per_page = perPage }); 138 | } 139 | 140 | /// 141 | /// Get Organization events 142 | /// 143 | /// The events. 144 | /// If set to true force cache invalidation. 145 | /// Page. 146 | /// Per page. 147 | public GitHubRequest> GetOrganizationEvents(string org, int page = 1, int perPage = 100) 148 | { 149 | return GitHubRequest.Get>(Uri + "/events/orgs/" + org, new { page = page, per_page = perPage }); 150 | } 151 | 152 | 153 | public override string Uri 154 | { 155 | get { return Client.ApiUri + "/users/" + Name; } 156 | } 157 | } 158 | 159 | public class AuthenticatedUserController : BaseUserController 160 | { 161 | public AuthenticatedRepositoriesController Repositories 162 | { 163 | get { return new AuthenticatedRepositoriesController(Client); } 164 | } 165 | 166 | public OrganizationsController Organizations 167 | { 168 | get { return new OrganizationsController(Client); } 169 | } 170 | 171 | public AuthenticatedUserIssuesController Issues 172 | { 173 | get { return new AuthenticatedUserIssuesController(Client); } 174 | } 175 | 176 | public AuthenticatedGistsController Gists 177 | { 178 | get { return new AuthenticatedGistsController(Client); } 179 | } 180 | 181 | public AuthenticatedUserController(Client client) 182 | : base(client) 183 | { 184 | } 185 | 186 | /// 187 | /// Gets events for this user 188 | /// 189 | /// 190 | /// 191 | /// 192 | public GitHubRequest> GetPublicEvents(int page = 1, int perPage = 100) 193 | { 194 | return GitHubRequest.Get>(Client.ApiUri + "/events", new { page = page, per_page = perPage }); 195 | } 196 | 197 | public GitHubRequest GetInfo() 198 | { 199 | return GitHubRequest.Get(Uri); 200 | } 201 | 202 | public GitHubRequest> GetKeys() 203 | { 204 | return GitHubRequest.Get>(Uri + "/keys"); 205 | } 206 | 207 | public GitHubRequest IsFollowing(string username) 208 | { 209 | return GitHubRequest.Get(Client.ApiUri + "/users/" + Client.Username + "/following/" + username); 210 | } 211 | 212 | public GitHubRequest Follow(string username) 213 | { 214 | return GitHubRequest.Put(Uri + "/following/" + username); 215 | } 216 | 217 | public GitHubRequest Unfollow(string username) 218 | { 219 | return GitHubRequest.Delete(Uri + "/following/" + username); 220 | } 221 | 222 | 223 | public override string Uri 224 | { 225 | get { return Client.ApiUri + "/user"; } 226 | } 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /GitHubSharp/Exceptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net.Http; 6 | using System.Threading.Tasks; 7 | using System.Net.Http.Headers; 8 | 9 | namespace GitHubSharp 10 | { 11 | public class ForbiddenException : StatusCodeException 12 | { 13 | public ForbiddenException(string message, HttpResponseHeaders headers = null) 14 | : base(HttpStatusCode.Forbidden, message, headers) { } 15 | } 16 | 17 | public class NotFoundException : StatusCodeException 18 | { 19 | public NotFoundException(string message, HttpResponseHeaders headers = null) 20 | : base(HttpStatusCode.NotFound, message, headers) { } 21 | } 22 | 23 | public class NotModifiedException : StatusCodeException 24 | { 25 | public NotModifiedException(string message, HttpResponseHeaders headers = null) 26 | : base(HttpStatusCode.NotModified, message, headers) { } 27 | } 28 | 29 | public class UnauthorizedException : StatusCodeException 30 | { 31 | public UnauthorizedException(string message, HttpResponseHeaders headers = null) 32 | : base(HttpStatusCode.Unauthorized, message, headers) { } 33 | } 34 | 35 | public class InternalServerException : StatusCodeException 36 | { 37 | public InternalServerException(string message, HttpResponseHeaders headers = null) 38 | : base(HttpStatusCode.InternalServerError, message, headers) { } 39 | } 40 | 41 | public class StatusCodeException : Exception 42 | { 43 | public HttpStatusCode StatusCode { get; private set; } 44 | 45 | public HttpResponseHeaders Headers { get; private set; } 46 | 47 | public StatusCodeException(HttpStatusCode statusCode, HttpResponseHeaders headers) 48 | : this(statusCode, statusCode.ToString(), headers) 49 | { 50 | } 51 | 52 | public StatusCodeException(HttpStatusCode statusCode, string message, HttpResponseHeaders headers) 53 | : base(message) 54 | { 55 | StatusCode = statusCode; 56 | Headers = headers; 57 | } 58 | 59 | internal static StatusCodeException FactoryCreate(HttpResponseMessage response, string data) 60 | { 61 | var headers = response.Headers; 62 | 63 | string errorStr = null; 64 | try 65 | { 66 | errorStr = Client.Serializer.Deserialize(data).Message; 67 | } 68 | catch 69 | { 70 | //Do nothing 71 | } 72 | 73 | switch (response.StatusCode) 74 | { 75 | case HttpStatusCode.Forbidden: 76 | return new ForbiddenException("You do not have the permissions to access or modify this resource.", headers); 77 | case HttpStatusCode.NotFound: 78 | return new NotFoundException("The server is unable to locate the requested resource.", headers); 79 | case HttpStatusCode.InternalServerError: 80 | return new InternalServerException("The request was unable to be processed due to an interal server error.", headers); 81 | case HttpStatusCode.Unauthorized: 82 | return new UnauthorizedException("You are unauthorized to view the requested resource.", headers); 83 | case HttpStatusCode.NotModified: 84 | return new NotModifiedException("This resource has not been modified since the last request.", headers); 85 | default: 86 | return new StatusCodeException(response.StatusCode, errorStr ?? response.StatusCode.ToString(), headers); 87 | } 88 | } 89 | } 90 | } 91 | 92 | -------------------------------------------------------------------------------- /GitHubSharp/GitHubRequest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace GitHubSharp 4 | { 5 | public enum RequestMethod 6 | { 7 | GET, 8 | POST, 9 | PUT, 10 | DELETE, 11 | PATCH 12 | } 13 | 14 | 15 | public class GitHubRequest 16 | { 17 | public RequestMethod RequestMethod { get; private set; } 18 | 19 | public string Url { get; private set; } 20 | 21 | public object Args { get; private set; } 22 | 23 | internal GitHubRequest(string url, RequestMethod method, object args = null) 24 | { 25 | RequestMethod = method; 26 | Url = url; 27 | Args = args; 28 | } 29 | 30 | internal static GitHubRequest Get(string url, object args = null) where T : new() 31 | { 32 | return new GitHubRequest(url, RequestMethod.GET, args); 33 | } 34 | 35 | internal static GitHubRequest Patch(string url, object args = null) where T : new() 36 | { 37 | return new GitHubRequest(url, RequestMethod.PATCH, args); 38 | } 39 | 40 | internal static GitHubRequest Post(string url, object args = null) where T : new() 41 | { 42 | return new GitHubRequest(url, RequestMethod.POST, args); 43 | } 44 | 45 | internal static GitHubRequest Put(string url, object args = null) where T : new() 46 | { 47 | return new GitHubRequest(url, RequestMethod.PUT, args); 48 | } 49 | 50 | internal static GitHubRequest Put(string url, object args = null) 51 | { 52 | return new GitHubRequest(url, RequestMethod.PUT, args); 53 | } 54 | 55 | internal static GitHubRequest Delete(string url, object args = null) 56 | { 57 | return new GitHubRequest(url, RequestMethod.DELETE, args); 58 | } 59 | } 60 | 61 | 62 | public class GitHubRequest : GitHubRequest where T : new() 63 | { 64 | public GitHubRequest(string url, RequestMethod method, object args = null) 65 | : base(url, method, args) 66 | { 67 | } 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /GitHubSharp/GitHubResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp 4 | { 5 | 6 | public class GitHubResponse 7 | { 8 | public int StatusCode { get; set; } 9 | 10 | public int RateLimitLimit { get; set; } 11 | 12 | public int RateLimitRemaining { get; set; } 13 | 14 | public string ETag { get; set; } 15 | 16 | public bool WasCached { get; set; } 17 | } 18 | 19 | 20 | public class GitHubResponse : GitHubResponse where T : new() 21 | { 22 | public T Data { get; set; } 23 | 24 | public GitHubRequest More { get; set; } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /GitHubSharp/GitHubSharp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 10.0 6 | Debug 7 | AnyCPU 8 | {07CD9573-CF93-4CF9-B3D6-501D30B6AD12} 9 | Library 10 | Properties 11 | GitHubSharp 12 | GitHubSharp 13 | v4.5 14 | Profile111 15 | 512 16 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | true 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 89 | 90 | 91 | ..\packages\Newtonsoft.Json.8.0.3\lib\portable-net45+wp80+win8+wpa81+dnxcore50\Newtonsoft.Json.dll 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /GitHubSharp/GitHubSharp.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | GitHubClient 5 | $version$ 6 | GitHub Client 7 | Dillon Buchanan 8 | Dillon Buchanan 9 | https://github.com/thedillonb/GitHubSharp 10 | false 11 | A .NET client for GitHub v3 APIs 12 | Initial release. 13 | github 14 | 15 | -------------------------------------------------------------------------------- /GitHubSharp/IJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace GitHubSharp 2 | { 3 | public interface IJsonSerializer 4 | { 5 | string Serialize(object item); 6 | T Deserialize(string json); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /GitHubSharp/Models/AuthorizationModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace GitHubSharp.Models 5 | { 6 | public class AuthorizationModel 7 | { 8 | public long Id { get; set; } 9 | public string Url { get; set; } 10 | public List Scopes { get; set; } 11 | public string Token { get; set; } 12 | public AppModel App { get; set; } 13 | public string Note { get; set; } 14 | public DateTimeOffset UpdatedAt { get; set; } 15 | public DateTimeOffset CreatedAt { get; set; } 16 | 17 | public class AppModel 18 | { 19 | public string Url { get; set; } 20 | public string Name { get; set; } 21 | public string ClientId { get; set; } 22 | } 23 | } 24 | 25 | public class AccessTokenModel 26 | { 27 | public string AccessToken { get; set; } 28 | public string Scope { get; set; } 29 | public string TokenType { get; set; } 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /GitHubSharp/Models/BasicUserModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp.Models 4 | { 5 | 6 | public class BasicUserModel 7 | { 8 | public string Login { get; set; } 9 | public long Id { get; set; } 10 | public string AvatarUrl { get; set; } 11 | public string GravatarId { get; set; } 12 | public string Url { get; set; } 13 | public string Type { get; set; } 14 | 15 | public override bool Equals(object obj) 16 | { 17 | if (obj == null) 18 | return false; 19 | if (ReferenceEquals(this, obj)) 20 | return true; 21 | if (obj.GetType() != typeof(BasicUserModel)) 22 | return false; 23 | BasicUserModel other = (BasicUserModel)obj; 24 | return Login == other.Login && Id == other.Id && AvatarUrl == other.AvatarUrl && GravatarId == other.GravatarId && Url == other.Url && Type == other.Type; 25 | } 26 | 27 | 28 | public override int GetHashCode() 29 | { 30 | unchecked 31 | { 32 | return (Login != null ? Login.GetHashCode() : 0) ^ (Id != null ? Id.GetHashCode() : 0) ^ (AvatarUrl != null ? AvatarUrl.GetHashCode() : 0) ^ (GravatarId != null ? GravatarId.GetHashCode() : 0) ^ (Url != null ? Url.GetHashCode() : 0) ^ (Type != null ? Type.GetHashCode() : 0); 33 | } 34 | } 35 | 36 | } 37 | 38 | 39 | public class KeyModel 40 | { 41 | public string Url { get; set; } 42 | public long Id { get; set; } 43 | public string Title { get; set; } 44 | public string Key { get; set; } 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /GitHubSharp/Models/ChangeStatusModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp.Models 4 | { 5 | 6 | public class ChangeStatusModel 7 | { 8 | public int Deletions { get; set; } 9 | public int Additions { get; set; } 10 | public int Total { get; set; } 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /GitHubSharp/Models/CommentModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace GitHubSharp.Models 5 | { 6 | 7 | public class CommentModel 8 | { 9 | public string HtmlUrl { get; set; } 10 | public string Url { get; set; } 11 | public string Id { get; set; } 12 | public string Body { get; set; } 13 | public string BodyHtml { get; set; } 14 | public string Path { get; set; } 15 | public int? Position { get; set; } 16 | public int? Line { get; set; } 17 | public string CommitId { get; set; } 18 | public BasicUserModel User { get; set; } 19 | public DateTimeOffset CreatedAt { get; set; } 20 | public DateTimeOffset UpdatedAt { get; set; } 21 | 22 | public override bool Equals(object obj) 23 | { 24 | if (obj == null) 25 | return false; 26 | if (ReferenceEquals(this, obj)) 27 | return true; 28 | if (obj.GetType() != typeof(CommentModel)) 29 | return false; 30 | CommentModel other = (CommentModel)obj; 31 | return HtmlUrl == other.HtmlUrl && Url == other.Url && Id == other.Id && Body == other.Body && BodyHtml == other.BodyHtml && Path == other.Path && Position == other.Position && Line == other.Line && CommitId == other.CommitId && User == other.User && CreatedAt == other.CreatedAt && UpdatedAt == other.UpdatedAt; 32 | } 33 | 34 | 35 | public override int GetHashCode() 36 | { 37 | unchecked 38 | { 39 | return (HtmlUrl != null ? HtmlUrl.GetHashCode() : 0) ^ (Url != null ? Url.GetHashCode() : 0) ^ (Id != null ? Id.GetHashCode() : 0) ^ (Body != null ? Body.GetHashCode() : 0) ^ (BodyHtml != null ? BodyHtml.GetHashCode() : 0) ^ (Path != null ? Path.GetHashCode() : 0) ^ (Position != null ? Position.GetHashCode() : 0) ^ (Line != null ? Line.GetHashCode() : 0) ^ (CommitId != null ? CommitId.GetHashCode() : 0) ^ (User != null ? User.GetHashCode() : 0) ^ (CreatedAt != null ? CreatedAt.GetHashCode() : 0) ^ (UpdatedAt != null ? UpdatedAt.GetHashCode() : 0); 40 | } 41 | } 42 | } 43 | 44 | 45 | public class CreateCommentModel 46 | { 47 | public string Body { get; set; } 48 | public string Path { get; set; } 49 | public int? Position { get; set; } 50 | } 51 | 52 | 53 | public class CommentForCreationOrEditModel 54 | { 55 | public string Body { get; set; } 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /GitHubSharp/Models/CommitModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace GitHubSharp.Models 5 | { 6 | 7 | public class CommitModel 8 | { 9 | public string Url { get; set; } 10 | public string HtmlUrl { get; set; } 11 | public string CommentsUrl { get; set; } 12 | public string Sha { get; set; } 13 | public CommitDetailModel Commit { get; set; } 14 | public BasicUserModel Author { get; set; } 15 | public BasicUserModel Committer { get; set; } 16 | public List Parents { get; set; } 17 | 18 | public ChangeStatusModel Stats { get; set; } 19 | public List Files { get; set; } 20 | 21 | 22 | public override bool Equals(object obj) 23 | { 24 | if (obj == null) 25 | return false; 26 | if (ReferenceEquals(this, obj)) 27 | return true; 28 | if (obj.GetType() != typeof(CommitModel)) 29 | return false; 30 | CommitModel other = (CommitModel)obj; 31 | return Url == other.Url && HtmlUrl == other.HtmlUrl && CommentsUrl == other.CommentsUrl && Sha == other.Sha && Commit == other.Commit && Author == other.Author && Committer == other.Committer && Parents == other.Parents && Stats == other.Stats && Files == other.Files; 32 | } 33 | 34 | 35 | public override int GetHashCode() 36 | { 37 | unchecked 38 | { 39 | return (Url != null ? Url.GetHashCode() : 0) ^ (HtmlUrl != null ? HtmlUrl.GetHashCode() : 0) ^ (CommentsUrl != null ? CommentsUrl.GetHashCode() : 0) ^ (Sha != null ? Sha.GetHashCode() : 0) ^ (Commit != null ? Commit.GetHashCode() : 0) ^ (Author != null ? Author.GetHashCode() : 0) ^ (Committer != null ? Committer.GetHashCode() : 0) ^ (Parents != null ? Parents.GetHashCode() : 0) ^ (Stats != null ? Stats.GetHashCode() : 0) ^ (Files != null ? Files.GetHashCode() : 0); 40 | } 41 | } 42 | 43 | public class CommitParentModel 44 | { 45 | public string Sha { get; set; } 46 | public string Url { get; set; } 47 | } 48 | 49 | 50 | public class CommitFileModel 51 | { 52 | public string Filename { get; set; } 53 | public int Additions { get; set; } 54 | public int Deletions { get; set; } 55 | public int Changes { get; set; } 56 | public string Status { get; set; } 57 | public string RawUrl { get; set; } 58 | public string BlobUrl { get; set; } 59 | public string Patch { get; set; } 60 | public string ContentsUrl { get; set; } 61 | 62 | public override bool Equals(object obj) 63 | { 64 | if (obj == null) 65 | return false; 66 | if (ReferenceEquals(this, obj)) 67 | return true; 68 | if (obj.GetType() != typeof(CommitFileModel)) 69 | return false; 70 | CommitFileModel other = (CommitFileModel)obj; 71 | return Filename == other.Filename && Additions == other.Additions && Deletions == other.Deletions && Changes == other.Changes && Status == other.Status && RawUrl == other.RawUrl && BlobUrl == other.BlobUrl && Patch == other.Patch && ContentsUrl == other.ContentsUrl; 72 | } 73 | 74 | 75 | public override int GetHashCode() 76 | { 77 | unchecked 78 | { 79 | return (Filename != null ? Filename.GetHashCode() : 0) ^ (Additions != null ? Additions.GetHashCode() : 0) ^ (Deletions != null ? Deletions.GetHashCode() : 0) ^ (Changes != null ? Changes.GetHashCode() : 0) ^ (Status != null ? Status.GetHashCode() : 0) ^ (RawUrl != null ? RawUrl.GetHashCode() : 0) ^ (BlobUrl != null ? BlobUrl.GetHashCode() : 0) ^ (Patch != null ? Patch.GetHashCode() : 0) ^ (ContentsUrl != null ? ContentsUrl.GetHashCode() : 0); 80 | } 81 | } 82 | } 83 | 84 | 85 | public class SingleFileCommitModel : CommitModel 86 | { 87 | public List Added { get; set; } 88 | public List Removed { get; set; } 89 | public List Modified { get; set; } 90 | 91 | 92 | public class SingleFileCommitFileReference 93 | { 94 | public string Filename { get; set; } 95 | } 96 | } 97 | 98 | 99 | public class CommitDetailModel 100 | { 101 | public string Url { get; set; } 102 | public string Sha { get; set; } 103 | public AuthorModel Author { get; set; } 104 | public AuthorModel Committer { get; set; } 105 | public string Message { get; set; } 106 | public CommitParentModel Tree { get; set; } 107 | 108 | 109 | public class AuthorModel 110 | { 111 | public string Name { get; set; } 112 | public DateTimeOffset Date { get; set; } 113 | public string Email { get; set; } 114 | } 115 | 116 | public override bool Equals(object obj) 117 | { 118 | if (obj == null) 119 | return false; 120 | if (ReferenceEquals(this, obj)) 121 | return true; 122 | if (obj.GetType() != typeof(CommitDetailModel)) 123 | return false; 124 | CommitDetailModel other = (CommitDetailModel)obj; 125 | return Url == other.Url && Sha == other.Sha && Author == other.Author && Committer == other.Committer && Message == other.Message && Tree == other.Tree; 126 | } 127 | 128 | 129 | public override int GetHashCode() 130 | { 131 | unchecked 132 | { 133 | return (Url != null ? Url.GetHashCode() : 0) ^ (Sha != null ? Sha.GetHashCode() : 0) ^ (Author != null ? Author.GetHashCode() : 0) ^ (Committer != null ? Committer.GetHashCode() : 0) ^ (Message != null ? Message.GetHashCode() : 0) ^ (Tree != null ? Tree.GetHashCode() : 0); 134 | } 135 | } 136 | 137 | } 138 | } 139 | } 140 | 141 | -------------------------------------------------------------------------------- /GitHubSharp/Models/ContentModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp.Models 4 | { 5 | public class ContentUpdateModel 6 | { 7 | public SlimContentModel Content { get; set; } 8 | 9 | public CommitModel Commit { get; set; } 10 | 11 | public override bool Equals(object obj) 12 | { 13 | if (obj == null) 14 | return false; 15 | if (ReferenceEquals(this, obj)) 16 | return true; 17 | if (obj.GetType() != typeof(ContentUpdateModel)) 18 | return false; 19 | ContentUpdateModel other = (ContentUpdateModel)obj; 20 | return Content == other.Content && Commit == other.Commit; 21 | } 22 | 23 | 24 | public override int GetHashCode() 25 | { 26 | unchecked 27 | { 28 | return (Content != null ? Content.GetHashCode() : 0) ^ (Commit != null ? Commit.GetHashCode() : 0); 29 | } 30 | } 31 | } 32 | 33 | public class SlimContentModel 34 | { 35 | public string Name { get; set; } 36 | public string Path { get; set; } 37 | public string Sha { get; set; } 38 | public long? Size { get; set; } 39 | public string Url { get; set; } 40 | public string HtmlUrl { get; set; } 41 | public string GitUrl { get; set; } 42 | public string Type { get; set; } 43 | 44 | public override bool Equals(object obj) 45 | { 46 | if (obj == null) 47 | return false; 48 | if (ReferenceEquals(this, obj)) 49 | return true; 50 | if (obj.GetType() != typeof(SlimContentModel)) 51 | return false; 52 | SlimContentModel other = (SlimContentModel)obj; 53 | return Name == other.Name && Path == other.Path && Sha == other.Sha && Size == other.Size && Url == other.Url && HtmlUrl == other.HtmlUrl && GitUrl == other.GitUrl && Type == other.Type; 54 | } 55 | 56 | 57 | public override int GetHashCode() 58 | { 59 | unchecked 60 | { 61 | return (Name != null ? Name.GetHashCode() : 0) ^ (Path != null ? Path.GetHashCode() : 0) ^ (Sha != null ? Sha.GetHashCode() : 0) ^ (Size != null ? Size.GetHashCode() : 0) ^ (Url != null ? Url.GetHashCode() : 0) ^ (HtmlUrl != null ? HtmlUrl.GetHashCode() : 0) ^ (GitUrl != null ? GitUrl.GetHashCode() : 0) ^ (Type != null ? Type.GetHashCode() : 0); 62 | } 63 | } 64 | 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /GitHubSharp/Models/ErrorModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp.Models 4 | { 5 | 6 | public class ErrorModel 7 | { 8 | public string Message { get; set; } 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /GitHubSharp/Models/EventModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace GitHubSharp.Models 5 | { 6 | 7 | public class EventModel 8 | { 9 | private Dictionary _payload; 10 | private string _type; 11 | 12 | public string Type 13 | { 14 | get { return _type; } 15 | set 16 | { 17 | _type = value; 18 | DeserializePayloadObject(); 19 | } 20 | } 21 | 22 | public bool Public { get; set; } 23 | 24 | public Dictionary Payload 25 | { 26 | get { return _payload; } 27 | set 28 | { 29 | _payload = value; 30 | DeserializePayloadObject(); 31 | } 32 | } 33 | 34 | public object PayloadObject { get; private set; } 35 | 36 | public RepoModel Repo { get; set; } 37 | public BasicUserModel Actor { get; set; } 38 | public BasicUserModel Org { get; set; } 39 | public DateTimeOffset CreatedAt { get; set; } 40 | public string Id { get; set; } 41 | 42 | private void DeserializePayloadObject() 43 | { 44 | if (Type == null || _payload == null || PayloadObject != null) 45 | return; 46 | 47 | try 48 | { 49 | // The deserialize function on the JsonSerializer.Deserializer only takes a IResponse object. 50 | // So, we'll just do what we have to to create one which is just assigning it's content to our payload. 51 | var payout = Client.Serializer.Serialize(_payload); 52 | 53 | switch (Type) 54 | { 55 | case "CommitCommentEvent": 56 | PayloadObject = Client.Serializer.Deserialize(payout); 57 | return; 58 | case "CreateEvent": 59 | PayloadObject = Client.Serializer.Deserialize(payout); 60 | return; 61 | case "DeleteEvent": 62 | PayloadObject = Client.Serializer.Deserialize(payout); 63 | return; 64 | case "DownloadEvent": 65 | PayloadObject = Client.Serializer.Deserialize(payout); 66 | return; 67 | case "FollowEvent": 68 | PayloadObject = Client.Serializer.Deserialize(payout); 69 | return; 70 | case "ForkEvent": 71 | PayloadObject = Client.Serializer.Deserialize(payout); 72 | return; 73 | case "ForkApplyEvent": 74 | PayloadObject = Client.Serializer.Deserialize(payout); 75 | return; 76 | case "GistEvent": 77 | PayloadObject = Client.Serializer.Deserialize(payout); 78 | return; 79 | case "GollumEvent": 80 | PayloadObject = Client.Serializer.Deserialize(payout); 81 | return; 82 | case "IssueCommentEvent": 83 | PayloadObject = Client.Serializer.Deserialize(payout); 84 | return; 85 | case "IssuesEvent": 86 | PayloadObject = Client.Serializer.Deserialize(payout); 87 | return; 88 | case "MemberEvent": 89 | PayloadObject = Client.Serializer.Deserialize(payout); 90 | return; 91 | case "PublicEvent": 92 | PayloadObject = Client.Serializer.Deserialize(payout); 93 | return; 94 | case "PullRequestEvent": 95 | PayloadObject = Client.Serializer.Deserialize(payout); 96 | return; 97 | case "PullRequestReviewCommentEvent": 98 | PayloadObject = Client.Serializer.Deserialize(payout); 99 | return; 100 | case "PushEvent": 101 | PayloadObject = Client.Serializer.Deserialize(payout); 102 | return; 103 | case "TeamAddEvent": 104 | PayloadObject = Client.Serializer.Deserialize(payout); 105 | return; 106 | case "WatchEvent": 107 | PayloadObject = Client.Serializer.Deserialize(payout); 108 | return; 109 | case "ReleaseEvent": 110 | PayloadObject = Client.Serializer.Deserialize(payout); 111 | return; 112 | } 113 | } 114 | catch 115 | { 116 | } 117 | } 118 | 119 | 120 | public class ReleaseEvent 121 | { 122 | public string Action { get; set; } 123 | public ReleaseModel Release { get; set; } 124 | } 125 | 126 | 127 | public class RepoModel 128 | { 129 | public long Id { get; set; } 130 | public string Name { get; set; } 131 | public string Url { get; set; } 132 | } 133 | 134 | 135 | public class CommitCommentEvent 136 | { 137 | public CommentModel Comment { get; set; } 138 | } 139 | 140 | 141 | public class CreateEvent 142 | { 143 | public string RefType { get; set; } 144 | public string Ref { get; set; } 145 | public string MasterBranch { get; set; } 146 | public string Description { get; set; } 147 | } 148 | 149 | 150 | public class DeleteEvent 151 | { 152 | public string RefType { get; set; } 153 | public string Ref { get; set; } 154 | } 155 | 156 | 157 | public class DownloadEvent 158 | { 159 | } 160 | 161 | 162 | public class FollowEvent 163 | { 164 | public BasicUserModel Target { get; set; } 165 | } 166 | 167 | 168 | public class ForkEvent 169 | { 170 | public RepositoryModel Forkee { get; set; } 171 | } 172 | 173 | 174 | public class ForkApplyEvent 175 | { 176 | public string Head { get; set; } 177 | public string Before { get; set; } 178 | public string After { get; set; } 179 | } 180 | 181 | 182 | public class GistEvent 183 | { 184 | public string Action { get; set; } 185 | public GistModel Gist { get; set; } 186 | } 187 | 188 | 189 | public class GollumEvent 190 | { 191 | public List Pages { get; set; } 192 | 193 | 194 | public class PageModel 195 | { 196 | public string PageName { get; set; } 197 | public string Sha { get; set; } 198 | public string Title { get; set; } 199 | public string Action { get; set; } 200 | public string HtmlUrl { get; set; } 201 | } 202 | } 203 | 204 | 205 | public class IssueCommentEvent 206 | { 207 | public string Action { get; set; } 208 | public IssueModel Issue { get; set; } 209 | public CommentModel Comment { get; set; } 210 | } 211 | 212 | 213 | public class IssuesEvent 214 | { 215 | public string Action { get; set; } 216 | public IssueModel Issue { get; set; } 217 | } 218 | 219 | 220 | public class MemberEvent 221 | { 222 | public BasicUserModel Member { get; set; } 223 | public string Action { get; set; } 224 | } 225 | 226 | 227 | public class PublicEvent 228 | { 229 | } 230 | 231 | 232 | public class PullRequestEvent 233 | { 234 | public string Action { get; set; } 235 | public long Number { get; set; } 236 | public PullRequestModel PullRequest { get; set; } 237 | } 238 | 239 | 240 | public class PullRequestReviewCommentEvent 241 | { 242 | public CommentModel Comment { get; set; } 243 | } 244 | 245 | 246 | public class PushEvent 247 | { 248 | public string Before { get; set; } 249 | public string Ref { get; set; } 250 | public long Size { get; set; } 251 | public List Commits { get; set; } 252 | 253 | 254 | public class CommitModel 255 | { 256 | public CommitAuthorModel Author { get; set; } 257 | public bool? Distinct { get; set; } 258 | public string Url { get; set; } 259 | public string Message { get; set; } 260 | public string Sha { get; set; } 261 | 262 | 263 | public class CommitAuthorModel 264 | { 265 | public string Name { get; set; } 266 | public string Email { get; set; } 267 | } 268 | } 269 | } 270 | 271 | 272 | public class TeamAddEvent 273 | { 274 | public TeamModel Team { get; set; } 275 | public BasicUserModel User { get; set; } 276 | public RepositoryModel Repo { get; set; } 277 | } 278 | 279 | 280 | public class WatchEvent 281 | { 282 | public string Action { get; set; } 283 | } 284 | } 285 | } 286 | 287 | 288 | 289 | -------------------------------------------------------------------------------- /GitHubSharp/Models/ForkModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp.Models 4 | { 5 | 6 | public class ForkModel 7 | { 8 | public BasicUserModel User { get; set; } 9 | public string Url { get; set; } 10 | public DateTimeOffset CreatedAt { get; set; } 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /GitHubSharp/Models/GistModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace GitHubSharp.Models 5 | { 6 | 7 | public class GistModel 8 | { 9 | public string Url { get; set; } 10 | public string Id { get; set; } 11 | public string Description { get; set; } 12 | public bool? Public { get; set; } 13 | public BasicUserModel Owner { get; set; } 14 | public Dictionary Files { get; set; } 15 | public long Comments { get; set; } 16 | public string CommentsUrl { get; set; } 17 | public string HtmlUrl { get; set; } 18 | public string GitPullUrl { get; set; } 19 | public string GitPushUrl { get; set; } 20 | public DateTimeOffset CreatedAt { get; set; } 21 | public DateTimeOffset UpdatedAt { get; set; } 22 | public List Forks { get; set; } 23 | public List History { get; set; } 24 | 25 | public override bool Equals(object obj) 26 | { 27 | if (obj == null) 28 | return false; 29 | if (ReferenceEquals(this, obj)) 30 | return true; 31 | if (obj.GetType() != typeof(GistModel)) 32 | return false; 33 | GistModel other = (GistModel)obj; 34 | return Url == other.Url && Id == other.Id && Description == other.Description && Public == other.Public && Owner == other.Owner && Files == other.Files && Comments == other.Comments && CommentsUrl == other.CommentsUrl && HtmlUrl == other.HtmlUrl && GitPullUrl == other.GitPullUrl && GitPushUrl == other.GitPushUrl && CreatedAt == other.CreatedAt && UpdatedAt == other.UpdatedAt && Forks == other.Forks && History == other.History; 35 | } 36 | 37 | 38 | public override int GetHashCode() 39 | { 40 | unchecked 41 | { 42 | return (Url != null ? Url.GetHashCode() : 0) ^ (Id != null ? Id.GetHashCode() : 0) ^ (Description != null ? Description.GetHashCode() : 0) ^ (Public != null ? Public.GetHashCode() : 0) ^ (Owner != null ? Owner.GetHashCode() : 0) ^ (Files != null ? Files.GetHashCode() : 0) ^ (Comments != null ? Comments.GetHashCode() : 0) ^ (CommentsUrl != null ? CommentsUrl.GetHashCode() : 0) ^ (HtmlUrl != null ? HtmlUrl.GetHashCode() : 0) ^ (GitPullUrl != null ? GitPullUrl.GetHashCode() : 0) ^ (GitPushUrl != null ? GitPushUrl.GetHashCode() : 0) ^ (CreatedAt != null ? CreatedAt.GetHashCode() : 0) ^ (UpdatedAt != null ? UpdatedAt.GetHashCode() : 0) ^ (Forks != null ? Forks.GetHashCode() : 0) ^ (History != null ? History.GetHashCode() : 0); 43 | } 44 | } 45 | } 46 | 47 | 48 | public class GistFileModel 49 | { 50 | public long Size { get; set; } 51 | public string Filename { get; set; } 52 | public string RawUrl { get; set; } 53 | public string Content { get; set; } 54 | public string Type { get; set; } 55 | public string Language { get; set; } 56 | 57 | public override bool Equals(object obj) 58 | { 59 | if (obj == null) 60 | return false; 61 | if (ReferenceEquals(this, obj)) 62 | return true; 63 | if (obj.GetType() != typeof(GistFileModel)) 64 | return false; 65 | GistFileModel other = (GistFileModel)obj; 66 | return Size == other.Size && Filename == other.Filename && RawUrl == other.RawUrl && Content == other.Content && Type == other.Type && Language == other.Language; 67 | } 68 | 69 | 70 | public override int GetHashCode() 71 | { 72 | unchecked 73 | { 74 | return (Size != null ? Size.GetHashCode() : 0) ^ (Filename != null ? Filename.GetHashCode() : 0) ^ (RawUrl != null ? RawUrl.GetHashCode() : 0) ^ (Content != null ? Content.GetHashCode() : 0) ^ (Type != null ? Type.GetHashCode() : 0) ^ (Language != null ? Language.GetHashCode() : 0); 75 | } 76 | } 77 | } 78 | 79 | 80 | public class GistCommentModel 81 | { 82 | public long Id { get; set; } 83 | public string Url { get; set; } 84 | public string Body { get; set; } 85 | public string BodyHtml { get; set; } 86 | public BasicUserModel User { get; set; } 87 | public DateTimeOffset CreatedAt { get; set; } 88 | 89 | public override bool Equals(object obj) 90 | { 91 | if (obj == null) 92 | return false; 93 | if (ReferenceEquals(this, obj)) 94 | return true; 95 | if (obj.GetType() != typeof(GistCommentModel)) 96 | return false; 97 | GistCommentModel other = (GistCommentModel)obj; 98 | return Id == other.Id && Url == other.Url && Body == other.Body && BodyHtml == other.BodyHtml && User == other.User && CreatedAt == other.CreatedAt; 99 | } 100 | 101 | 102 | public override int GetHashCode() 103 | { 104 | unchecked 105 | { 106 | return (Id != null ? Id.GetHashCode() : 0) ^ (Url != null ? Url.GetHashCode() : 0) ^ (Body != null ? Body.GetHashCode() : 0) ^ (BodyHtml != null ? BodyHtml.GetHashCode() : 0) ^ (User != null ? User.GetHashCode() : 0) ^ (CreatedAt != null ? CreatedAt.GetHashCode() : 0); 107 | } 108 | } 109 | } 110 | 111 | 112 | public class GistEditModel 113 | { 114 | public string Description { get; set; } 115 | public Dictionary Files { get; set; } 116 | 117 | 118 | public class File 119 | { 120 | public string Filename { get; set; } 121 | public string Content { get; set; } 122 | } 123 | } 124 | 125 | 126 | public class GistCreateModel 127 | { 128 | public string Description { get; set; } 129 | public bool? Public { get; set; } 130 | public Dictionary Files { get; set; } 131 | 132 | 133 | public class File 134 | { 135 | public string Content { get; set; } 136 | } 137 | } 138 | } 139 | 140 | -------------------------------------------------------------------------------- /GitHubSharp/Models/HistoryModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp.Models 4 | { 5 | 6 | public class HistoryModel 7 | { 8 | public string Url { get; set; } 9 | public string Version { get; set; } 10 | public BasicUserModel User { get; set; } 11 | public ChangeStatusModel ChangeStatus { get; set; } 12 | public DateTimeOffset CommittedAt { get; set; } 13 | 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /GitHubSharp/Models/IssueModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace GitHubSharp.Models 5 | { 6 | 7 | public class IssueModel 8 | { 9 | public string Url { get; set; } 10 | 11 | public string HtmlUrl { get; set; } 12 | 13 | public long Number { get; set; } 14 | 15 | public string State { get; set; } 16 | 17 | public string Title { get; set; } 18 | 19 | public string Body { get; set; } 20 | 21 | public string BodyHtml { get; set; } 22 | 23 | public BasicUserModel User { get; set; } 24 | 25 | public List Labels { get; set; } 26 | 27 | public BasicUserModel Assignee { get; set; } 28 | 29 | public MilestoneModel Milestone { get; set; } 30 | 31 | public int Comments { get; set; } 32 | 33 | public DateTimeOffset CreatedAt { get; set; } 34 | 35 | public DateTimeOffset? ClosedAt { get; set; } 36 | 37 | public DateTimeOffset UpdatedAt { get; set; } 38 | 39 | public PullRequestModel PullRequest { get; set; } 40 | 41 | public override bool Equals(object obj) 42 | { 43 | if (obj == null) 44 | return false; 45 | if (ReferenceEquals(this, obj)) 46 | return true; 47 | if (obj.GetType() != typeof(IssueModel)) 48 | return false; 49 | IssueModel other = (IssueModel)obj; 50 | return Url == other.Url && HtmlUrl == other.HtmlUrl && Number == other.Number && State == other.State && Title == other.Title && Body == other.Body && BodyHtml == other.BodyHtml && User == other.User && Labels == other.Labels && Assignee == other.Assignee && Milestone == other.Milestone && Comments == other.Comments && CreatedAt == other.CreatedAt && ClosedAt == other.ClosedAt && UpdatedAt == other.UpdatedAt && PullRequest == other.PullRequest; 51 | } 52 | 53 | 54 | public override int GetHashCode() 55 | { 56 | unchecked 57 | { 58 | return (Url != null ? Url.GetHashCode() : 0) ^ (HtmlUrl != null ? HtmlUrl.GetHashCode() : 0) ^ (Number != null ? Number.GetHashCode() : 0) ^ (State != null ? State.GetHashCode() : 0) ^ (Title != null ? Title.GetHashCode() : 0) ^ (Body != null ? Body.GetHashCode() : 0) ^ (BodyHtml != null ? BodyHtml.GetHashCode() : 0) ^ (User != null ? User.GetHashCode() : 0) ^ (Labels != null ? Labels.GetHashCode() : 0) ^ (Assignee != null ? Assignee.GetHashCode() : 0) ^ (Milestone != null ? Milestone.GetHashCode() : 0) ^ (Comments != null ? Comments.GetHashCode() : 0) ^ (CreatedAt != null ? CreatedAt.GetHashCode() : 0) ^ (ClosedAt != null ? ClosedAt.GetHashCode() : 0) ^ (UpdatedAt != null ? UpdatedAt.GetHashCode() : 0) ^ (PullRequest != null ? PullRequest.GetHashCode() : 0); 59 | } 60 | } 61 | 62 | 63 | public class PullRequestModel 64 | { 65 | public string HtmlUrl { get; set; } 66 | 67 | public string DiffUrl { get; set; } 68 | 69 | public string PatchUrl { get; set; } 70 | } 71 | } 72 | 73 | 74 | public class LabelModel 75 | { 76 | public string Url { get; set; } 77 | 78 | public string Name { get; set; } 79 | 80 | public string Color { get; set; } 81 | 82 | protected bool Equals(LabelModel other) 83 | { 84 | return string.Equals(Url, other.Url); 85 | } 86 | 87 | public override bool Equals(object obj) 88 | { 89 | if (ReferenceEquals(null, obj)) return false; 90 | if (ReferenceEquals(this, obj)) return true; 91 | if (obj.GetType() != this.GetType()) return false; 92 | return Equals((LabelModel) obj); 93 | } 94 | 95 | public override int GetHashCode() 96 | { 97 | return (Url != null ? Url.GetHashCode() : 0); 98 | } 99 | } 100 | 101 | 102 | public class MilestoneModel 103 | { 104 | public int Number { get; set; } 105 | 106 | public string State { get; set; } 107 | 108 | public string Title { get; set; } 109 | 110 | public string Description { get; set; } 111 | 112 | public BasicUserModel Creator { get; set; } 113 | 114 | public int OpenIssues { get; set; } 115 | 116 | public int ClosedIssues { get; set; } 117 | 118 | public DateTimeOffset CreatedAt { get; set; } 119 | 120 | public DateTimeOffset? DueOn { get; set; } 121 | 122 | public string Url { get; set; } 123 | 124 | protected bool Equals(MilestoneModel other) 125 | { 126 | return string.Equals(Url, other.Url); 127 | } 128 | 129 | public override bool Equals(object obj) 130 | { 131 | if (ReferenceEquals(null, obj)) return false; 132 | if (ReferenceEquals(this, obj)) return true; 133 | if (obj.GetType() != this.GetType()) return false; 134 | return Equals((MilestoneModel) obj); 135 | } 136 | 137 | public override int GetHashCode() 138 | { 139 | return (Url != null ? Url.GetHashCode() : 0); 140 | } 141 | } 142 | 143 | 144 | public class IssueCommentModel 145 | { 146 | public long Id { get; set; } 147 | 148 | public string Url { get; set; } 149 | 150 | public string Body { get; set; } 151 | 152 | public string BodyHtml { get; set; } 153 | 154 | public BasicUserModel User { get; set; } 155 | 156 | public DateTimeOffset CreatedAt { get; set; } 157 | 158 | public DateTimeOffset UpdatedAt { get; set; } 159 | } 160 | 161 | 162 | public class IssueEventModel 163 | { 164 | public string Url { get; set; } 165 | 166 | public BasicUserModel Actor { get; set; } 167 | 168 | public string Event { get; set; } 169 | 170 | public string CommitId { get; set; } 171 | 172 | public DateTimeOffset CreatedAt { get; set; } 173 | 174 | public IssueModel Issue { get; set; } 175 | 176 | public static class EventTypes 177 | { 178 | public static string Closed = "closed", Reopened = "reopened", Subscribed = "subscribed", 179 | Merged = "merged", Referenced = "referenced", Mentioned = "mentioned", 180 | Assigned = "assigned"; 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /GitHubSharp/Models/NotificationModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp.Models 4 | { 5 | 6 | public class NotificationModel 7 | { 8 | public string Id { get; set; } // NB: API currently returns this as string which is Weird 9 | public RepositoryModel Repository { get; set; } 10 | public SubjectModel Subject { get; set; } 11 | public string Reason { get; set; } 12 | public bool Unread { get; set; } 13 | public DateTimeOffset UpdatedAt { get; set; } 14 | public DateTimeOffset? LastReadAt { get; set; } 15 | public string Url { get; set; } 16 | 17 | 18 | public class SubjectModel 19 | { 20 | public string Title { get; set; } 21 | public string Url { get; set; } 22 | public string LatestCommentUrl { get; set; } 23 | public string Type { get; set; } 24 | } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /GitHubSharp/Models/ObjectModel.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | using System; 3 | 4 | namespace GitHubSharp.Models 5 | { 6 | 7 | public class ObjectModel 8 | { 9 | public string Name { get; set; } 10 | public string Sha { get; set; } 11 | public string Mode { get; set; } 12 | public string Type { get; set; } 13 | public ObjectItemType ObjectItemType 14 | { 15 | get { return Type == "blob" ? ObjectItemType.Blob : ObjectItemType.Tree; } 16 | } 17 | } 18 | 19 | 20 | public class BlobModel 21 | { 22 | public string Name { get; set; } 23 | public string Sha { get; set; } 24 | public string Mode { get; set; } 25 | public long Size { get; set; } 26 | public string MimeType { get; set; } 27 | public string Data { get; set; } 28 | } 29 | 30 | 31 | public enum ObjectItemType 32 | { 33 | Blob, 34 | Tree 35 | } 36 | } -------------------------------------------------------------------------------- /GitHubSharp/Models/PullRequestModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace GitHubSharp.Models 5 | { 6 | 7 | public class PullRequestModel 8 | { 9 | public string Url { get; set; } 10 | 11 | public string HtmlUrl { get; set; } 12 | 13 | public string DiffUrl { get; set; } 14 | 15 | public string PatchUrl { get; set; } 16 | 17 | public string IssueUrl { get; set; } 18 | 19 | public long Number { get; set; } 20 | 21 | public string State { get; set; } 22 | 23 | public string Title { get; set; } 24 | 25 | public string Body { get; set; } 26 | 27 | public string BodyHtml { get; set; } 28 | 29 | public DateTimeOffset CreatedAt { get; set; } 30 | 31 | public DateTimeOffset UpdatedAt { get; set; } 32 | 33 | public DateTimeOffset? ClosedAt { get; set; } 34 | 35 | public DateTimeOffset? MergedAt { get; set; } 36 | 37 | public PullRequestCommitReferenceModel Head { get; set; } 38 | 39 | public PullRequestCommitReferenceModel Base { get; set; } 40 | 41 | public BasicUserModel User { get; set; } 42 | 43 | public bool? Merged { get; set; } 44 | 45 | public bool? Mergeable { get; set; } 46 | 47 | public BasicUserModel MergedBy { get; set; } 48 | 49 | public int? Comments { get; set; } 50 | 51 | public int? Commits { get; set; } 52 | 53 | public int? Additions { get; set; } 54 | 55 | public int? Deletions { get; set; } 56 | 57 | public int? ChangedFiles { get; set; } 58 | 59 | public override bool Equals(object obj) 60 | { 61 | if (obj == null) 62 | return false; 63 | if (ReferenceEquals(this, obj)) 64 | return true; 65 | if (obj.GetType() != typeof(PullRequestModel)) 66 | return false; 67 | PullRequestModel other = (PullRequestModel)obj; 68 | return Url == other.Url && HtmlUrl == other.HtmlUrl && DiffUrl == other.DiffUrl && PatchUrl == other.PatchUrl && IssueUrl == other.IssueUrl && Number == other.Number && State == other.State && Title == other.Title && Body == other.Body && BodyHtml == other.BodyHtml && CreatedAt == other.CreatedAt && UpdatedAt == other.UpdatedAt && ClosedAt == other.ClosedAt && MergedAt == other.MergedAt && Head == other.Head && Base == other.Base && User == other.User && Merged == other.Merged && Mergeable == other.Mergeable && MergedBy == other.MergedBy && Comments == other.Comments && Commits == other.Commits && Additions == other.Additions && Deletions == other.Deletions && ChangedFiles == other.ChangedFiles; 69 | } 70 | 71 | 72 | public override int GetHashCode() 73 | { 74 | unchecked 75 | { 76 | return (Url != null ? Url.GetHashCode() : 0) ^ (HtmlUrl != null ? HtmlUrl.GetHashCode() : 0) ^ (DiffUrl != null ? DiffUrl.GetHashCode() : 0) ^ (PatchUrl != null ? PatchUrl.GetHashCode() : 0) ^ (IssueUrl != null ? IssueUrl.GetHashCode() : 0) ^ (Number != null ? Number.GetHashCode() : 0) ^ (State != null ? State.GetHashCode() : 0) ^ (Title != null ? Title.GetHashCode() : 0) ^ (Body != null ? Body.GetHashCode() : 0) ^ (BodyHtml != null ? BodyHtml.GetHashCode() : 0) ^ (CreatedAt != null ? CreatedAt.GetHashCode() : 0) ^ (UpdatedAt != null ? UpdatedAt.GetHashCode() : 0) ^ (ClosedAt != null ? ClosedAt.GetHashCode() : 0) ^ (MergedAt != null ? MergedAt.GetHashCode() : 0) ^ (Head != null ? Head.GetHashCode() : 0) ^ (Base != null ? Base.GetHashCode() : 0) ^ (User != null ? User.GetHashCode() : 0) ^ (Merged != null ? Merged.GetHashCode() : 0) ^ (Mergeable != null ? Mergeable.GetHashCode() : 0) ^ (MergedBy != null ? MergedBy.GetHashCode() : 0) ^ (Comments != null ? Comments.GetHashCode() : 0) ^ (Commits != null ? Commits.GetHashCode() : 0) ^ (Additions != null ? Additions.GetHashCode() : 0) ^ (Deletions != null ? Deletions.GetHashCode() : 0) ^ (ChangedFiles != null ? ChangedFiles.GetHashCode() : 0); 77 | } 78 | } 79 | 80 | public class PullRequestCommitReferenceModel 81 | { 82 | public RepositoryModel Repository { get; set; } 83 | 84 | public string Sha { get; set; } 85 | 86 | public string Label { get; set; } 87 | 88 | public BasicUserModel User { get; set; } 89 | 90 | public string Ref { get; set; } 91 | } 92 | } 93 | 94 | 95 | public class PullRequestMergeModel 96 | { 97 | public string Sha { get; set; } 98 | 99 | public bool Merged { get; set; } 100 | 101 | public string Message { get; set; } 102 | } 103 | } -------------------------------------------------------------------------------- /GitHubSharp/Models/ReleaseModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp.Models 4 | { 5 | 6 | public class ReleaseModel 7 | { 8 | public string Url { get; set; } 9 | public string HtmlUrl { get; set; } 10 | public string AssetsUrl { get; set; } 11 | public string UploadUrl { get; set; } 12 | public long Id { get; set; } 13 | public string TagName { get; set; } 14 | public string TargetCommitish { get; set; } 15 | public string Name { get; set; } 16 | public string Body { get; set; } 17 | public string BodyHtml { get; set; } 18 | public bool Draft { get; set; } 19 | public bool Prerelease { get; set; } 20 | public DateTimeOffset CreatedAt { get; set; } 21 | public DateTimeOffset? PublishedAt { get; set; } 22 | public BasicUserModel Author { get; set; } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /GitHubSharp/Models/RepositoryModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace GitHubSharp.Models 5 | { 6 | 7 | public class RepositoryModel 8 | { 9 | public long Id { get; set; } 10 | public BasicUserModel Owner { get; set; } 11 | public string Name { get; set; } 12 | public string FullName { get; set; } 13 | public string Description { get; set; } 14 | public bool Private { get; set; } 15 | public bool Fork { get; set; } 16 | public string Url { get; set; } 17 | public string Homepage { get; set; } 18 | public string Language { get; set; } 19 | public int Forks { get; set; } 20 | public int ForksCount { get; set; } 21 | public int Watchers { get; set; } 22 | public int WatchersCount { get; set; } 23 | public int SubscribersCount { get; set; } 24 | public long Size { get; set; } 25 | public string DefaultBranch { get; set; } 26 | public int OpenIssues { get; set; } 27 | public DateTimeOffset? PushedAt { get; set; } 28 | public DateTimeOffset CreatedAt { get; set; } 29 | public DateTimeOffset UpdatedAt { get; set; } 30 | public int StargazersCount { get; set; } 31 | 32 | public BasicUserModel Organization { get; set; } 33 | 34 | public RepositoryModel Source { get; set; } 35 | public RepositoryModel Parent { get; set; } 36 | 37 | public bool HasIssues { get; set; } 38 | public bool HasWiki { get; set; } 39 | public bool HasDownloads { get; set; } 40 | 41 | public string HtmlUrl { get; set; } 42 | 43 | public RepositoryPermissions Permissions { get; set; } 44 | 45 | public override bool Equals(object obj) 46 | { 47 | if (obj == null) 48 | return false; 49 | if (ReferenceEquals(this, obj)) 50 | return true; 51 | if (obj.GetType() != typeof(RepositoryModel)) 52 | return false; 53 | RepositoryModel other = (RepositoryModel)obj; 54 | return Id == other.Id && Owner == other.Owner && Name == other.Name && FullName == other.FullName && Description == other.Description && Private == other.Private && Fork == other.Fork && Url == other.Url && Homepage == other.Homepage && Language == other.Language && Forks == other.Forks && ForksCount == other.ForksCount && Watchers == other.Watchers && WatchersCount == other.WatchersCount && SubscribersCount == other.SubscribersCount && Size == other.Size && DefaultBranch == other.DefaultBranch && OpenIssues == other.OpenIssues && PushedAt == other.PushedAt && CreatedAt == other.CreatedAt && UpdatedAt == other.UpdatedAt && StargazersCount == other.StargazersCount && Organization == other.Organization && Source == other.Source && Parent == other.Parent && HasIssues == other.HasIssues && HasWiki == other.HasWiki && HasDownloads == other.HasDownloads && HtmlUrl == other.HtmlUrl && Permissions == other.Permissions; 55 | } 56 | 57 | public override int GetHashCode() 58 | { 59 | unchecked 60 | { 61 | return (Id != null ? Id.GetHashCode() : 0) ^ (Owner != null ? Owner.GetHashCode() : 0) ^ (Name != null ? Name.GetHashCode() : 0) ^ (FullName != null ? FullName.GetHashCode() : 0) ^ (Description != null ? Description.GetHashCode() : 0) ^ (Private != null ? Private.GetHashCode() : 0) ^ (Fork != null ? Fork.GetHashCode() : 0) ^ (Url != null ? Url.GetHashCode() : 0) ^ (Homepage != null ? Homepage.GetHashCode() : 0) ^ (Language != null ? Language.GetHashCode() : 0) ^ (Forks != null ? Forks.GetHashCode() : 0) ^ (ForksCount != null ? ForksCount.GetHashCode() : 0) ^ (Watchers != null ? Watchers.GetHashCode() : 0) ^ (WatchersCount != null ? WatchersCount.GetHashCode() : 0) ^ (SubscribersCount != null ? SubscribersCount.GetHashCode() : 0) ^ (Size != null ? Size.GetHashCode() : 0) ^ (DefaultBranch != null ? DefaultBranch.GetHashCode() : 0) ^ (OpenIssues != null ? OpenIssues.GetHashCode() : 0) ^ (PushedAt != null ? PushedAt.GetHashCode() : 0) ^ (CreatedAt != null ? CreatedAt.GetHashCode() : 0) ^ (UpdatedAt != null ? UpdatedAt.GetHashCode() : 0) ^ (StargazersCount != null ? StargazersCount.GetHashCode() : 0) ^ (Organization != null ? Organization.GetHashCode() : 0) ^ (Source != null ? Source.GetHashCode() : 0) ^ (Parent != null ? Parent.GetHashCode() : 0) ^ (HasIssues != null ? HasIssues.GetHashCode() : 0) ^ (HasWiki != null ? HasWiki.GetHashCode() : 0) ^ (HasDownloads != null ? HasDownloads.GetHashCode() : 0) ^ (HtmlUrl != null ? HtmlUrl.GetHashCode() : 0) ^ (Permissions != null ? Permissions.GetHashCode() : 0); 62 | } 63 | } 64 | 65 | } 66 | 67 | public class RepositoryPermissions 68 | { 69 | public bool Admin { get; set; } 70 | public bool Push { get; set; } 71 | public bool Pull { get; set; } 72 | } 73 | 74 | 75 | public class RepositorySearchModel 76 | { 77 | public int TotalCount { get; set; } 78 | public List Items { get; set; } 79 | 80 | 81 | public class RepositoryModel 82 | { 83 | public long Id { get; set; } 84 | public string Name { get; set; } 85 | public string FullName { get; set; } 86 | public BasicUserModel Owner { get; set; } 87 | public bool Private { get; set; } 88 | public string HtmlUrl { get; set; } 89 | public string Description { get; set; } 90 | public bool Fork { get; set; } 91 | public string Url { get; set; } 92 | public DateTimeOffset CreatedAt { get; set; } 93 | public DateTimeOffset UpdatedAt { get; set; } 94 | public DateTimeOffset? PushedAt { get; set; } 95 | public string Homepage { get; set; } 96 | public int StargazersCount { get; set; } 97 | public int WatchersCount { get; set; } 98 | public string Language { get; set; } 99 | public int ForksCount { get; set; } 100 | public int OpenIssuesCount { get; set; } 101 | public float Score { get; set; } 102 | } 103 | } 104 | 105 | 106 | public class TagModel 107 | { 108 | public string Name { get; set; } 109 | public TagCommitModel Commit { get; set; } 110 | 111 | 112 | public class TagCommitModel 113 | { 114 | public string Sha { get; set; } 115 | } 116 | } 117 | 118 | 119 | public class BranchModel 120 | { 121 | public string Name { get; set; } 122 | 123 | public override bool Equals(object obj) 124 | { 125 | if (obj == null) 126 | return false; 127 | if (ReferenceEquals(this, obj)) 128 | return true; 129 | if (obj.GetType() != typeof(BranchModel)) 130 | return false; 131 | BranchModel other = (BranchModel)obj; 132 | return Name == other.Name; 133 | } 134 | 135 | 136 | public override int GetHashCode() 137 | { 138 | unchecked 139 | { 140 | return (Name != null ? Name.GetHashCode() : 0); 141 | } 142 | } 143 | 144 | } 145 | 146 | 147 | public class ContentModel 148 | { 149 | public string Type { get; set; } 150 | public string Sha { get; set; } 151 | public string Path { get; set; } 152 | public string GitUrl { get; set; } 153 | public string HtmlUrl { get; set; } 154 | public string DownloadUrl { get; set; } 155 | public string Encoding { get; set; } 156 | public string Url { get; set; } 157 | public long? Size { get; set; } 158 | public string Name { get; set; } 159 | public string Content { get; set; } 160 | 161 | public override bool Equals(object obj) 162 | { 163 | if (obj == null) 164 | return false; 165 | if (ReferenceEquals(this, obj)) 166 | return true; 167 | if (obj.GetType() != typeof(ContentModel)) 168 | return false; 169 | ContentModel other = (ContentModel)obj; 170 | return Type == other.Type && Sha == other.Sha && Path == other.Path && GitUrl == other.GitUrl && HtmlUrl == other.HtmlUrl && DownloadUrl == other.DownloadUrl && Encoding == other.Encoding && Url == other.Url && Size == other.Size && Name == other.Name && Content == other.Content; 171 | } 172 | 173 | 174 | public override int GetHashCode() 175 | { 176 | unchecked 177 | { 178 | return (Type != null ? Type.GetHashCode() : 0) ^ (Sha != null ? Sha.GetHashCode() : 0) ^ (Path != null ? Path.GetHashCode() : 0) ^ (GitUrl != null ? GitUrl.GetHashCode() : 0) ^ (HtmlUrl != null ? HtmlUrl.GetHashCode() : 0) ^ (DownloadUrl != null ? DownloadUrl.GetHashCode() : 0) ^ (Encoding != null ? Encoding.GetHashCode() : 0) ^ (Url != null ? Url.GetHashCode() : 0) ^ (Size != null ? Size.GetHashCode() : 0) ^ (Name != null ? Name.GetHashCode() : 0) ^ (Content != null ? Content.GetHashCode() : 0); 179 | } 180 | } 181 | 182 | } 183 | } 184 | 185 | -------------------------------------------------------------------------------- /GitHubSharp/Models/SubscriptionModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp.Models 4 | { 5 | 6 | public class SubscriptionModel 7 | { 8 | public bool Subscribed { get; set; } 9 | public bool Ignored { get; set; } 10 | public string Reason { get; set; } 11 | public DateTimeOffset CreatedAt { get; set; } 12 | public string Url { get; set; } 13 | public string RepositoryUrl { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GitHubSharp/Models/TeamModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp.Models 4 | { 5 | 6 | public class TeamShortModel 7 | { 8 | public string Url { get; set; } 9 | public string Name { get; set; } 10 | public long Id { get; set; } 11 | 12 | public override bool Equals(object obj) 13 | { 14 | if (obj == null) 15 | return false; 16 | if (ReferenceEquals(this, obj)) 17 | return true; 18 | if (obj.GetType() != typeof(TeamShortModel)) 19 | return false; 20 | TeamShortModel other = (TeamShortModel)obj; 21 | return Url == other.Url && Name == other.Name && Id == other.Id; 22 | } 23 | 24 | 25 | public override int GetHashCode() 26 | { 27 | unchecked 28 | { 29 | return (Url != null ? Url.GetHashCode() : 0) ^ (Name != null ? Name.GetHashCode() : 0) ^ (Id != null ? Id.GetHashCode() : 0); 30 | } 31 | } 32 | } 33 | 34 | 35 | public class TeamModel 36 | { 37 | public string Url { get; set; } 38 | public string Name { get; set; } 39 | public long Id { get; set; } 40 | public string Permission { get; set; } 41 | public int MembersCount { get; set; } 42 | public int ReposCount { get; set; } 43 | 44 | public override bool Equals(object obj) 45 | { 46 | if (obj == null) 47 | return false; 48 | if (ReferenceEquals(this, obj)) 49 | return true; 50 | if (obj.GetType() != typeof(TeamModel)) 51 | return false; 52 | TeamModel other = (TeamModel)obj; 53 | return Url == other.Url && Name == other.Name && Id == other.Id && Permission == other.Permission && MembersCount == other.MembersCount && ReposCount == other.ReposCount; 54 | } 55 | 56 | 57 | public override int GetHashCode() 58 | { 59 | unchecked 60 | { 61 | return (Url != null ? Url.GetHashCode() : 0) ^ (Name != null ? Name.GetHashCode() : 0) ^ (Id != null ? Id.GetHashCode() : 0) ^ (Permission != null ? Permission.GetHashCode() : 0) ^ (MembersCount != null ? MembersCount.GetHashCode() : 0) ^ (ReposCount != null ? ReposCount.GetHashCode() : 0); 62 | } 63 | } 64 | 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /GitHubSharp/Models/TreeModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace GitHubSharp.Models 5 | { 6 | 7 | public class TreeModel 8 | { 9 | public string Sha { get; set; } 10 | public string Url { get; set; } 11 | public List Tree { get; set; } 12 | 13 | 14 | public class TreePathModel 15 | { 16 | public string Path { get; set; } 17 | public string Mode { get; set; } 18 | public string Type { get; set; } 19 | public long Size { get; set; } 20 | public string Sha { get; set; } 21 | public string Url { get; set; } 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /GitHubSharp/Models/UserModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GitHubSharp.Models 4 | { 5 | 6 | public class UserModel 7 | { 8 | public string Login { get; set; } 9 | 10 | public long Id { get; set; } 11 | 12 | public string AvatarUrl { get; set; } 13 | 14 | public string GravatarId { get; set; } 15 | 16 | public string Url { get; set; } 17 | 18 | public string Name { get; set; } 19 | 20 | public string Company { get; set; } 21 | 22 | public string Blog { get; set; } 23 | 24 | public string Location { get; set; } 25 | 26 | public string Email { get; set; } 27 | 28 | public bool? Hireable { get; set; } 29 | 30 | public string Bio { get; set; } 31 | 32 | public long PublicRepos { get; set; } 33 | 34 | public long PublicGists { get; set; } 35 | 36 | public long Followers { get; set; } 37 | 38 | public long Following { get; set; } 39 | 40 | public string HtmlUrl { get; set; } 41 | 42 | public DateTimeOffset CreatedAt { get; set; } 43 | 44 | public string Type { get; set; } 45 | 46 | public override bool Equals(object obj) 47 | { 48 | if (obj == null) 49 | return false; 50 | if (ReferenceEquals(this, obj)) 51 | return true; 52 | if (obj.GetType() != typeof(UserModel)) 53 | return false; 54 | UserModel other = (UserModel)obj; 55 | return Login == other.Login && Id == other.Id && AvatarUrl == other.AvatarUrl && GravatarId == other.GravatarId && Url == other.Url && Name == other.Name && Company == other.Company && Blog == other.Blog && Location == other.Location && Email == other.Email && Hireable == other.Hireable && Bio == other.Bio && PublicRepos == other.PublicRepos && PublicGists == other.PublicGists && Followers == other.Followers && Following == other.Following && HtmlUrl == other.HtmlUrl && CreatedAt == other.CreatedAt && Type == other.Type; 56 | } 57 | 58 | 59 | public override int GetHashCode() 60 | { 61 | unchecked 62 | { 63 | return (Login != null ? Login.GetHashCode() : 0) ^ (Id != null ? Id.GetHashCode() : 0) ^ (AvatarUrl != null ? AvatarUrl.GetHashCode() : 0) ^ (GravatarId != null ? GravatarId.GetHashCode() : 0) ^ (Url != null ? Url.GetHashCode() : 0) ^ (Name != null ? Name.GetHashCode() : 0) ^ (Company != null ? Company.GetHashCode() : 0) ^ (Blog != null ? Blog.GetHashCode() : 0) ^ (Location != null ? Location.GetHashCode() : 0) ^ (Email != null ? Email.GetHashCode() : 0) ^ (Hireable != null ? Hireable.GetHashCode() : 0) ^ (Bio != null ? Bio.GetHashCode() : 0) ^ (PublicRepos != null ? PublicRepos.GetHashCode() : 0) ^ (PublicGists != null ? PublicGists.GetHashCode() : 0) ^ (Followers != null ? Followers.GetHashCode() : 0) ^ (Following != null ? Following.GetHashCode() : 0) ^ (HtmlUrl != null ? HtmlUrl.GetHashCode() : 0) ^ (CreatedAt != null ? CreatedAt.GetHashCode() : 0) ^ (Type != null ? Type.GetHashCode() : 0); 64 | } 65 | } 66 | 67 | } 68 | 69 | 70 | public class UserAuthenticatedModel : UserModel 71 | { 72 | public int TotalPrivateRepos { get; set; } 73 | 74 | public int OwnedPrivateRepos { get; set; } 75 | 76 | public long PrivateGists { get; set; } 77 | 78 | public long DiskUsage { get; set; } 79 | 80 | public long Collaborators { get; set; } 81 | // public UserAuthenticatedPlanModel Plan { get; set; } 82 | // 83 | // 84 | // public class UserAuthenticatedPlanModel 85 | // { 86 | // public string Name { get; set; } 87 | // public long Collaborators { get; set; } 88 | // public long Space { get; set; } 89 | // public long PrivateRepos { get; set; } 90 | // } 91 | } 92 | 93 | 94 | public class PublicKeyModel 95 | { 96 | public string Title { get; set; } 97 | 98 | public long Id { get; set; } 99 | 100 | public string Key { get; set; } 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /GitHubSharp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("GitHubSharp.Portable")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("GitHubSharp.Portable")] 14 | [assembly: AssemblyCopyright("Copyright © 2014")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | [assembly: NeutralResourcesLanguage("en")] 18 | 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Build and Revision Numbers 27 | // by using the '*' as shown below: 28 | // [assembly: AssemblyVersion("1.0.*")] 29 | [assembly: AssemblyVersion("1.0.0.0")] 30 | [assembly: AssemblyFileVersion("1.0.0.0")] 31 | -------------------------------------------------------------------------------- /GitHubSharp/SimpleJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | 5 | namespace GitHubSharp 6 | { 7 | internal static class StringExtensions 8 | { 9 | // :trollface: 10 | [SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", 11 | Justification = "Ruby don't care. Ruby don't play that.")] 12 | public static string ToRubyCase(this string propertyName) 13 | { 14 | return string.Join("_", propertyName.SplitUpperCase()).ToLowerInvariant(); 15 | } 16 | 17 | static IEnumerable SplitUpperCase(this string source) 18 | { 19 | int wordStartIndex = 0; 20 | var letters = source.ToCharArray(); 21 | var previousChar = char.MinValue; 22 | 23 | // Skip the first letter. we don't care what case it is. 24 | for (int i = 1; i < letters.Length; i++) 25 | { 26 | if (char.IsUpper(letters[i]) && !char.IsWhiteSpace(previousChar)) 27 | { 28 | //Grab everything before the current character. 29 | yield return new String(letters, wordStartIndex, i - wordStartIndex); 30 | wordStartIndex = i; 31 | } 32 | previousChar = letters[i]; 33 | } 34 | 35 | //We need to have the last word. 36 | yield return new String(letters, wordStartIndex, letters.Length - wordStartIndex); 37 | } 38 | } 39 | 40 | public class LowercaseContractResolver : Newtonsoft.Json.Serialization.DefaultContractResolver { 41 | protected override string ResolvePropertyName(string propertyName) { 42 | return propertyName.ToRubyCase(); 43 | } 44 | } 45 | 46 | public class SimpleJsonSerializer : IJsonSerializer 47 | { 48 | private readonly Newtonsoft.Json.JsonSerializerSettings _settings; 49 | public SimpleJsonSerializer() 50 | { 51 | _settings = new Newtonsoft.Json.JsonSerializerSettings(); 52 | _settings.ContractResolver = new LowercaseContractResolver(); 53 | _settings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat; 54 | _settings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc; 55 | } 56 | 57 | public string Serialize(object item) 58 | { 59 | return Newtonsoft.Json.JsonConvert.SerializeObject(item, _settings); 60 | } 61 | 62 | public T Deserialize(string json) 63 | { 64 | return Newtonsoft.Json.JsonConvert.DeserializeObject(json, _settings); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /GitHubSharp/Utils/ObjectToDictionaryConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | 4 | namespace GitHubSharp.Utils 5 | { 6 | public static class ObjectToDictionaryConverter 7 | { 8 | public static Dictionary Convert(object obj) 9 | { 10 | var dictionary = new Dictionary(); 11 | var properties = obj.GetType().GetRuntimeProperties(); 12 | foreach (var propertyInfo in properties) 13 | { 14 | var value = propertyInfo.GetValue(obj, null); 15 | if (value != null) 16 | { 17 | var valueStr = value.ToString(); 18 | 19 | //Booleans need lowercase! 20 | if (value is bool) 21 | valueStr = valueStr.ToLower(); 22 | 23 | dictionary.Add(propertyInfo.Name.ToLower(), valueStr); 24 | } 25 | } 26 | return dictionary; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /GitHubSharp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Dillon Buchanan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GitHubSharp 2 | ================ 3 | 4 | **OBSOLETE NOTICE**: Please consider using [https://github.com/octokit/octokit.net](GitHub's official C# library) for all GitHub API calls. 5 | 6 | Description 7 | ---------------- 8 | 9 | A C# client for the GitHub REST API. 10 | 11 | 12 | License 13 | ---------------- 14 | 15 | The MIT License (MIT) 16 | 17 | Copyright (c) Dillon Buchanan 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in 27 | all copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 35 | THE SOFTWARE. 36 | --------------------------------------------------------------------------------