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
This commit is contained in:
Ryan Gribble
2015-12-18 00:34:40 +10:00
parent 2ede6e2b26
commit c7b4899d66
5 changed files with 17 additions and 11 deletions
+2 -4
View File
@@ -109,10 +109,9 @@ namespace Octokit
/// <returns>A list of licenses available on the site</returns>
public async Task<IReadOnlyList<LicenseMetadata>> GetAllLicenses()
{
const string previewAcceptsHeader = "application/vnd.github.drax-preview+json";
var endpoint = new Uri("licenses", UriKind.Relative);
var response = await _connection.Get<LicenseMetadata[]>(endpoint, null, previewAcceptsHeader)
var response = await _connection.Get<LicenseMetadata[]>(endpoint, null, AcceptHeaders.LicensesApiPreview)
.ConfigureAwait(false);
return new ReadOnlyCollection<LicenseMetadata>(response.Body);
}
@@ -124,10 +123,9 @@ namespace Octokit
/// <returns>A <see cref="License" /> that includes the license key, text, and attributes of the license.</returns>
public async Task<License> 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<License>(endpoint, null, previewAcceptsHeader)
var response = await _connection.Get<License>(endpoint, null, AcceptHeaders.LicensesApiPreview)
.ConfigureAwait(false);
return response.Body;
}
+5 -5
View File
@@ -37,7 +37,7 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(name, "repository");
var endpoint = ApiUrls.Releases(owner, name);
return ApiConnection.GetAll<Release>(endpoint, null, "application/vnd.github.v3");
return ApiConnection.GetAll<Release>(endpoint, null, AcceptHeaders.ReleaseApi);
}
/// <summary>
@@ -78,7 +78,7 @@ namespace Octokit
Ensure.ArgumentNotNull(data, "data");
var endpoint = ApiUrls.Releases(owner, name);
return ApiConnection.Post<Release>(endpoint, data, "application/vnd.github.v3");
return ApiConnection.Post<Release>(endpoint, data, AcceptHeaders.ReleaseApi);
}
/// <summary>
@@ -140,7 +140,7 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(name, "name");
var endpoint = ApiUrls.ReleaseAssets(owner, name, id);
return ApiConnection.GetAll<ReleaseAsset>(endpoint, null, "application/vnd.github.v3");
return ApiConnection.GetAll<ReleaseAsset>(endpoint, null, AcceptHeaders.ReleaseApi);
}
/// <summary>
@@ -165,7 +165,7 @@ namespace Octokit
return ApiConnection.Post<ReleaseAsset>(
endpoint,
data.RawData,
"application/vnd.github.v3",
AcceptHeaders.ReleaseApi,
data.ContentType,
data.Timeout.GetValueOrDefault());
}
@@ -173,7 +173,7 @@ namespace Octokit
return ApiConnection.Post<ReleaseAsset>(
endpoint,
data.RawData,
"application/vnd.github.v3",
AcceptHeaders.ReleaseApi,
data.ContentType);
}
+8
View File
@@ -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";
}
}
+1 -1
View File
@@ -519,7 +519,7 @@ namespace Octokit
async Task<IApiResponse<string>> 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<string>(response, response.Body as string);
}
+1 -1
View File
@@ -11,7 +11,7 @@ namespace Octokit.Internal
/// </summary>
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;