mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 03:30:34 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user