mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-05-31 02:05:39 +00:00
Flatten the observables for releases
This commit is contained in:
@@ -1,22 +1,25 @@
|
||||
using System;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using Octokit.Reactive.Helpers;
|
||||
|
||||
namespace Octokit.Reactive.Clients
|
||||
{
|
||||
public class ObservableReleasesClient : IObservableReleasesClient
|
||||
{
|
||||
readonly IReleasesClient _client;
|
||||
readonly IConnection _connection;
|
||||
|
||||
public ObservableReleasesClient(IReleasesClient client)
|
||||
public ObservableReleasesClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
_client = client;
|
||||
_client = client.Release;
|
||||
_connection = client.Connection;
|
||||
}
|
||||
|
||||
public IObservable<IReadOnlyList<Release>> GetAll(string owner, string name)
|
||||
public IObservable<Release> GetAll(string owner, string name)
|
||||
{
|
||||
return _client.GetAll(owner, name).ToObservable();
|
||||
return _connection.GetAndFlattenAllPages<Release>(ApiUrls.Releases(owner, name));
|
||||
}
|
||||
|
||||
public IObservable<Release> CreateRelease(string owner, string name, ReleaseUpdate data)
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Octokit.Reactive
|
||||
{
|
||||
public interface IObservableReleasesClient
|
||||
{
|
||||
IObservable<IReadOnlyList<Release>> GetAll(string owner, string name);
|
||||
IObservable<Release> GetAll(string owner, string name);
|
||||
IObservable<Release> CreateRelease(string owner, string name, ReleaseUpdate data);
|
||||
IObservable<ReleaseAsset> UploadAsset(Release release, ReleaseAssetUpload data);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ namespace Octokit.Reactive
|
||||
Organization = new ObservableOrganizationsClient(gitHubClient);
|
||||
Repository = new ObservableRepositoriesClient(gitHubClient);
|
||||
SshKey = new ObservableSshKeysClient(gitHubClient);
|
||||
User = new ObservableUsersClient(gitHubClient.User);
|
||||
User = new ObservableUsersClient(gitHubClient);
|
||||
Release = new ObservableReleasesClient(gitHubClient);
|
||||
}
|
||||
|
||||
public IConnection Connection { get { return _gitHubClient.Connection; }}
|
||||
@@ -25,6 +26,7 @@ namespace Octokit.Reactive
|
||||
public IObservableMiscellaneousClient Miscellaneous { get; private set; }
|
||||
public IObservableOrganizationsClient Organization { get; private set; }
|
||||
public IObservableRepositoriesClient Repository { get; private set; }
|
||||
public IObservableReleasesClient Release { get; private set; }
|
||||
public IObservableSshKeysClient SshKey { get; private set; }
|
||||
public IObservableUsersClient User { get; private set; }
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Internal;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "repository");
|
||||
|
||||
var endpoint = "/repos/{0}/{1}/releases".FormatUri(owner, name);
|
||||
var endpoint = ApiUrls.Releases(owner, name);
|
||||
return await Client.GetAll<Release>(endpoint, null, "application/vnd.github.manifold-preview");
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "repository");
|
||||
Ensure.ArgumentNotNull(data, "data");
|
||||
|
||||
var endpoint = "/repos/{0}/{1}/releases".FormatUri(owner, name);
|
||||
var endpoint = ApiUrls.Releases(owner, name);
|
||||
return await Client.Post<Release>(endpoint, data, "application/vnd.github.manifold-preview");
|
||||
}
|
||||
|
||||
|
||||
@@ -89,5 +89,16 @@ namespace Octokit
|
||||
{
|
||||
return _currentUserEmailsEndpoint;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns all of the releases for the specified repository.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository.</param>
|
||||
/// <param name="name">The name of the repository.</param>
|
||||
/// <returns></returns>
|
||||
public static Uri Releases(string owner, string name)
|
||||
{
|
||||
return "/repos/{0}/{1}/releases".FormatUri(owner, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ namespace Octokit
|
||||
return new Uri(string.Format(CultureInfo.InvariantCulture, pattern, args), UriKind.Relative);
|
||||
}
|
||||
|
||||
static Regex OptionalQueryStringRegex = new Regex("\\{\\?([^}]+)\\}");
|
||||
static readonly Regex _optionalQueryStringRegex = new Regex("\\{\\?([^}]+)\\}");
|
||||
public static Uri ExpandUriTemplate(this string template, object values)
|
||||
{
|
||||
var optionalQueryStringMatch = OptionalQueryStringRegex.Match(template);
|
||||
var optionalQueryStringMatch = _optionalQueryStringRegex.Match(template);
|
||||
if(optionalQueryStringMatch.Success)
|
||||
{
|
||||
var expansion = "";
|
||||
@@ -39,7 +39,7 @@ namespace Octokit
|
||||
{
|
||||
expansion = "?" + parameterName + "=" + Uri.EscapeDataString("" + parameterProperty.GetValue(values, new object[0]));
|
||||
}
|
||||
template = OptionalQueryStringRegex.Replace(template, expansion);
|
||||
template = _optionalQueryStringRegex.Replace(template, expansion);
|
||||
}
|
||||
return new Uri(template);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user