From c7b4899d66ac39101cac0f09628a0b4e06dd7f38 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 18 Dec 2015 00:34:40 +1000 Subject: [PATCH] Replace all other uses of hardcoded HTTP header strings to declare/use entries in the AcceptHeaders helper class Left test methods alone as it isn't good practice to share these definitions between Test and Implementation classes --- Octokit/Clients/MiscellaneousClient.cs | 6 ++---- Octokit/Clients/ReleasesClient.cs | 10 +++++----- Octokit/Helpers/AcceptHeaders.cs | 8 ++++++++ Octokit/Http/Connection.cs | 2 +- Octokit/Http/JsonHttpPipeline.cs | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Octokit/Clients/MiscellaneousClient.cs b/Octokit/Clients/MiscellaneousClient.cs index 38cfeff4..7079fada 100644 --- a/Octokit/Clients/MiscellaneousClient.cs +++ b/Octokit/Clients/MiscellaneousClient.cs @@ -109,10 +109,9 @@ namespace Octokit /// A list of licenses available on the site public async Task> GetAllLicenses() { - const string previewAcceptsHeader = "application/vnd.github.drax-preview+json"; var endpoint = new Uri("licenses", UriKind.Relative); - var response = await _connection.Get(endpoint, null, previewAcceptsHeader) + var response = await _connection.Get(endpoint, null, AcceptHeaders.LicensesApiPreview) .ConfigureAwait(false); return new ReadOnlyCollection(response.Body); } @@ -124,10 +123,9 @@ namespace Octokit /// A that includes the license key, text, and attributes of the license. public async Task GetLicense(string key) { - const string previewAcceptsHeader = "application/vnd.github.drax-preview+json"; var endpoint = new Uri("licenses/" + Uri.EscapeUriString(key), UriKind.Relative); - var response = await _connection.Get(endpoint, null, previewAcceptsHeader) + var response = await _connection.Get(endpoint, null, AcceptHeaders.LicensesApiPreview) .ConfigureAwait(false); return response.Body; } diff --git a/Octokit/Clients/ReleasesClient.cs b/Octokit/Clients/ReleasesClient.cs index b712f8a2..2b33c2b3 100644 --- a/Octokit/Clients/ReleasesClient.cs +++ b/Octokit/Clients/ReleasesClient.cs @@ -37,7 +37,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "repository"); var endpoint = ApiUrls.Releases(owner, name); - return ApiConnection.GetAll(endpoint, null, "application/vnd.github.v3"); + return ApiConnection.GetAll(endpoint, null, AcceptHeaders.ReleaseApi); } /// @@ -78,7 +78,7 @@ namespace Octokit Ensure.ArgumentNotNull(data, "data"); var endpoint = ApiUrls.Releases(owner, name); - return ApiConnection.Post(endpoint, data, "application/vnd.github.v3"); + return ApiConnection.Post(endpoint, data, AcceptHeaders.ReleaseApi); } /// @@ -140,7 +140,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); var endpoint = ApiUrls.ReleaseAssets(owner, name, id); - return ApiConnection.GetAll(endpoint, null, "application/vnd.github.v3"); + return ApiConnection.GetAll(endpoint, null, AcceptHeaders.ReleaseApi); } /// @@ -165,7 +165,7 @@ namespace Octokit return ApiConnection.Post( endpoint, data.RawData, - "application/vnd.github.v3", + AcceptHeaders.ReleaseApi, data.ContentType, data.Timeout.GetValueOrDefault()); } @@ -173,7 +173,7 @@ namespace Octokit return ApiConnection.Post( endpoint, data.RawData, - "application/vnd.github.v3", + AcceptHeaders.ReleaseApi, data.ContentType); } diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index 05ad379d..50405578 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -2,6 +2,14 @@ { public static class AcceptHeaders { + public const string DefaultJson = "application/vnd.github.quicksilver-preview+json; charset=utf-8, application/vnd.github.v3+json; charset=utf-8"; + + public const string DefaultHtml = "application/vnd.github.html"; + + public const string ReleaseApi = "application/vnd.github.v3"; + + public const string LicensesApiPreview = "application/vnd.github.drax-preview+json"; + public const string ProtectedBranchesApiPreview = "application/vnd.github.loki-preview+json"; } } diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 5bcd0700..4dbfa443 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -519,7 +519,7 @@ namespace Octokit async Task> GetHtml(IRequest request) { - request.Headers.Add("Accept", "application/vnd.github.html"); + request.Headers.Add("Accept", AcceptHeaders.DefaultHtml); var response = await RunRequest(request, CancellationToken.None); return new ApiResponse(response, response.Body as string); } diff --git a/Octokit/Http/JsonHttpPipeline.cs b/Octokit/Http/JsonHttpPipeline.cs index f67bd788..167b2686 100644 --- a/Octokit/Http/JsonHttpPipeline.cs +++ b/Octokit/Http/JsonHttpPipeline.cs @@ -11,7 +11,7 @@ namespace Octokit.Internal /// public class JsonHttpPipeline { - private const string v3ApiVersion = "application/vnd.github.quicksilver-preview+json; charset=utf-8, application/vnd.github.v3+json; charset=utf-8"; + private const string v3ApiVersion = AcceptHeaders.DefaultJson; readonly IJsonSerializer _serializer;