mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-08 20:45:51 +00:00
[feat]: SDKs for ActionsArtifacts APIs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -138,6 +139,15 @@ namespace Octokit
|
||||
var response = await Connection.GetRaw(uri, parameters).ConfigureAwait(false);
|
||||
return response.Body;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<Stream> GetRawStream(Uri uri, IDictionary<string, string> parameters)
|
||||
{
|
||||
Ensure.ArgumentNotNull(uri, nameof(uri));
|
||||
|
||||
var response = await Connection.GetRawStream(uri, parameters).ConfigureAwait(false);
|
||||
return response.Body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all API resources in the list at the specified URI.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
@@ -241,6 +242,19 @@ namespace Octokit
|
||||
Endpoint = uri.ApplyParameters(parameters)
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task<IApiResponse<Stream>> GetRawStream(Uri uri, IDictionary<string, string> parameters)
|
||||
{
|
||||
Ensure.ArgumentNotNull(uri, nameof(uri));
|
||||
|
||||
return GetRawStream(new Request
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
BaseAddress = BaseAddress,
|
||||
Endpoint = uri.ApplyParameters(parameters)
|
||||
});
|
||||
}
|
||||
|
||||
public Task<IApiResponse<T>> Patch<T>(Uri uri, object body)
|
||||
{
|
||||
@@ -686,7 +700,30 @@ namespace Octokit
|
||||
{
|
||||
request.Headers.Add("Accept", AcceptHeaders.RawContentMediaType);
|
||||
var response = await RunRequest(request, CancellationToken.None).ConfigureAwait(false);
|
||||
return new ApiResponse<byte[]>(response, response.Body as byte[]);
|
||||
|
||||
return new ApiResponse<byte[]>(response, await StreamToByteArray(response.Body as Stream));
|
||||
}
|
||||
|
||||
async Task<IApiResponse<Stream>> GetRawStream(IRequest request)
|
||||
{
|
||||
request.Headers.Add("Accept", AcceptHeaders.RawContentMediaType);
|
||||
var response = await RunRequest(request, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
return new ApiResponse<Stream>(response, response.Body as Stream);
|
||||
}
|
||||
|
||||
async Task<byte[]> StreamToByteArray(Stream stream)
|
||||
{
|
||||
if (stream is MemoryStream memoryStream)
|
||||
{
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
await stream.CopyToAsync(ms);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
async Task<IApiResponse<T>> Run<T>(IRequest request, CancellationToken cancellationToken, Func<object, object> preprocessResponseBody = null)
|
||||
|
||||
@@ -83,25 +83,24 @@ namespace Octokit.Internal
|
||||
"application/x-gzip" ,
|
||||
"application/octet-stream"};
|
||||
|
||||
using (var content = responseMessage.Content)
|
||||
var content = responseMessage.Content;
|
||||
if (content != null)
|
||||
{
|
||||
if (content != null)
|
||||
{
|
||||
contentType = GetContentMediaType(responseMessage.Content);
|
||||
contentType = GetContentMediaType(content);
|
||||
|
||||
if (contentType != null && (contentType.StartsWith("image/") || binaryContentTypes
|
||||
if (contentType != null && (contentType.StartsWith("image/") || binaryContentTypes
|
||||
.Any(item => item.Equals(contentType, StringComparison.OrdinalIgnoreCase))))
|
||||
{
|
||||
responseBody = await responseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
responseBody = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (!(preprocessResponseBody is null))
|
||||
responseBody = preprocessResponseBody(responseBody);
|
||||
{
|
||||
responseBody = await content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
responseBody = await content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
content.Dispose();
|
||||
}
|
||||
|
||||
if (!(preprocessResponseBody is null))
|
||||
responseBody = preprocessResponseBody(responseBody);
|
||||
}
|
||||
|
||||
var responseHeaders = responseMessage.Headers.ToDictionary(h => h.Key, h => h.Value.First());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -71,6 +72,15 @@ namespace Octokit
|
||||
/// <exception cref="ApiException">Thrown when an API error occurs.</exception>
|
||||
Task<byte[]> GetRaw(Uri uri, IDictionary<string, string> parameters);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the raw stream of the API resource at the specified URI.
|
||||
/// </summary>
|
||||
/// <param name="uri">URI of the API resource to get</param>
|
||||
/// <param name="parameters">Parameters to add to the API request</param>
|
||||
/// <returns>The API resource's raw stream or <c>null</c> if the <paramref name="uri"/> points to a directory.</returns>
|
||||
/// <exception cref="ApiException">Thrown when an API error occurs.</exception>
|
||||
Task<Stream> GetRawStream(Uri uri, IDictionary<string, string> parameters);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all API resources in the list at the specified URI.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -29,6 +30,15 @@ namespace Octokit
|
||||
/// <returns><seealso cref="IResponse"/> representing the received HTTP response</returns>
|
||||
/// <remarks>The <see cref="IResponse.Body"/> property will be <c>null</c> if the <paramref name="uri"/> points to a directory instead of a file</remarks>
|
||||
Task<IApiResponse<byte[]>> GetRaw(Uri uri, IDictionary<string, string> parameters);
|
||||
|
||||
/// <summary>
|
||||
/// Performs an asynchronous HTTP GET request that expects a <seealso cref="IResponse"/> containing raw data.
|
||||
/// </summary>
|
||||
/// <param name="uri">URI endpoint to send request to</param>
|
||||
/// <param name="parameters">Querystring parameters for the request</param>
|
||||
/// <returns><seealso cref="IResponse"/> representing the received HTTP response</returns>
|
||||
/// <remarks>The <see cref="IResponse.Body"/> property will be <c>null</c> if the <paramref name="uri"/> points to a directory instead of a file</remarks>
|
||||
Task<IApiResponse<Stream>> GetRawStream(Uri uri, IDictionary<string, string> parameters);
|
||||
|
||||
/// <summary>
|
||||
/// Performs an asynchronous HTTP GET request.
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Octokit
|
||||
public interface IResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Raw response body. Typically a string, but when requesting images, it will be a byte array.
|
||||
/// Raw response body. Typically a string, but when requesting images, or binary files, it will be a Stream.
|
||||
/// </summary>
|
||||
object Body { get; }
|
||||
|
||||
|
||||
@@ -35,9 +35,7 @@ namespace Octokit.Internal
|
||||
ContentType = contentType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raw response body. Typically a string, but when requesting images, it will be a byte array.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public object Body { get; private set; }
|
||||
/// <summary>
|
||||
/// Information about the API.
|
||||
|
||||
Reference in New Issue
Block a user