mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 11:40:42 +00:00
make Upload a generic POST
The Releases API-specific part of uploading (the accept header) is now in the Releases client and the API connection just has a generic POST method. /cc @spraints
This commit is contained in:
@@ -75,9 +75,10 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
releasesClient.UploadAsset(release, upload);
|
||||
|
||||
client.Received().Upload<ReleaseAsset>(Arg.Is<Uri>(u => u.ToString() == "https://uploads.test.dev/does/not/matter/releases/1/assets?name=example.zip"),
|
||||
client.Received().Post<ReleaseAsset>(Arg.Is<Uri>(u => u.ToString() == "https://uploads.test.dev/does/not/matter/releases/1/assets?name=example.zip"),
|
||||
rawData,
|
||||
Arg.Is<string>(contentType => contentType == "application/zip"));
|
||||
Arg.Is<string>(contentType => contentType == "application/zip"),
|
||||
"application/vnd.github.manifold-preview");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace Octokit.Tests.Http
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
var rawData = new MemoryStream();
|
||||
|
||||
await apiConnection.Upload<string>(uploadUrl, rawData, "B");
|
||||
await apiConnection.Post<string>(uploadUrl, rawData, "B", "anAccept");
|
||||
|
||||
connection.Received().PostAsync<string>(uploadUrl, rawData, Args.String, Args.String);
|
||||
}
|
||||
@@ -197,9 +197,10 @@ namespace Octokit.Tests.Http
|
||||
public async Task EnsuresArgumentNotNull()
|
||||
{
|
||||
var connection = new ApiConnection(Substitute.For<IConnection>());
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await connection.Upload<object>(null, Stream.Null, "some-content-type"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await connection.Upload<object>(new Uri("/ok", UriKind.Relative), null, "some-content-type"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await connection.Upload<object>(new Uri("/ok", UriKind.Relative), null, null));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await connection.Post<object>(null, new MemoryStream(), "some-content-type", "anAccept"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await connection.Post<object>(new Uri("/ok", UriKind.Relative), null, "some-content-type", "anAccept"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await connection.Post<object>(new Uri("/ok", UriKind.Relative), new MemoryStream(), null, "anAccept"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await connection.Post<object>(new Uri("/ok", UriKind.Relative), new MemoryStream(), "some-content-type", null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#if NET_45
|
||||
using System.Collections.Generic;
|
||||
#endif
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
@@ -38,7 +40,12 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNull(data, "data");
|
||||
|
||||
var endpoint = release.UploadUrl.ExpandUriTemplate(new { name = data.FileName });
|
||||
return await Client.Upload<ReleaseAsset>(endpoint, data.RawData, data.ContentType);
|
||||
return await Client.Post<ReleaseAsset>(
|
||||
endpoint,
|
||||
data.RawData,
|
||||
data.ContentType,
|
||||
"application/vnd.github.manifold-preview");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,17 +96,18 @@ namespace Octokit
|
||||
await Connection.DeleteAsync<T>(endpoint);
|
||||
}
|
||||
|
||||
public async Task<TOther> Upload<TOther>(Uri uri, Stream rawData, string contentType)
|
||||
public async Task<T> Post<T>(Uri uri, Stream rawData, string contentType, string accepts)
|
||||
{
|
||||
Ensure.ArgumentNotNull(uri, "uri");
|
||||
Ensure.ArgumentNotNull(rawData, "rawData");
|
||||
Ensure.ArgumentNotNull(contentType, "contentType");
|
||||
Ensure.ArgumentNotNull(accepts, "accepts");
|
||||
|
||||
var response = await Connection.PostAsync<TOther>(
|
||||
var response = await Connection.PostAsync<T>(
|
||||
uri,
|
||||
rawData,
|
||||
contentType,
|
||||
"application/vnd.github.manifold-preview");
|
||||
accepts);
|
||||
return response.BodyAsObject;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,6 @@ namespace Octokit
|
||||
Task<T> Update<T>(Uri endpoint, object data);
|
||||
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification="Legitimate, but I'm not fixing it just yet.")]
|
||||
Task Delete<T>(Uri endpoint);
|
||||
Task<T> Upload<T>(Uri uri, Stream rawData, string contentType);
|
||||
Task<T> Post<T>(Uri uri, Stream rawData, string contentType, string accepts);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user