mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-09 13:01:36 +00:00
Flatten the observables for SSH keys
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using Octokit.Reactive.Helpers;
|
||||
|
||||
namespace Octokit.Reactive.Clients
|
||||
{
|
||||
public class ObservableSshKeysClient : IObservableSshKeysClient
|
||||
{
|
||||
readonly ISshKeysClient _client;
|
||||
readonly IConnection _connection;
|
||||
|
||||
public ObservableSshKeysClient(ISshKeysClient client)
|
||||
public ObservableSshKeysClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
_client = client;
|
||||
_client = client.SshKey;
|
||||
_connection = client.Connection;
|
||||
}
|
||||
|
||||
public IObservable<SshKey> Get(int id)
|
||||
@@ -21,16 +23,16 @@ namespace Octokit.Reactive.Clients
|
||||
return _client.Get(id).ToObservable();
|
||||
}
|
||||
|
||||
public IObservable<IReadOnlyList<SshKey>> GetAll(string user)
|
||||
public IObservable<SshKey> GetAll(string user)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return _client.GetAll(user).ToObservable();
|
||||
return _connection.GetAndFlattenAllPages<SshKey>(ApiUrls.SshKeys(user));
|
||||
}
|
||||
|
||||
public IObservable<IReadOnlyList<SshKey>> GetAllForCurrent()
|
||||
public IObservable<SshKey> GetAllForCurrent()
|
||||
{
|
||||
return _client.GetAllForCurrent().ToObservable();
|
||||
return _connection.GetAndFlattenAllPages<SshKey>(ApiUrls.SshKeys());
|
||||
}
|
||||
|
||||
public IObservable<SshKey> Create(SshKeyUpdate key)
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Octokit.Reactive
|
||||
/// </summary>
|
||||
/// <param name="user">The login of the user.</param>
|
||||
/// <returns>A <see cref="IReadOnlyPagedCollection{SshKey}"/> of <see cref="SshKey"/>.</returns>
|
||||
IObservable<IReadOnlyList<SshKey>> GetAll(string user);
|
||||
IObservable<SshKey> GetAll(string user);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="SshKey"/> for the specified id.
|
||||
@@ -29,7 +29,7 @@ namespace Octokit.Reactive
|
||||
/// <returns>A <see cref="IReadOnlyPagedCollection{SshKey}"/> of <see cref="SshKey"/>.</returns>
|
||||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
|
||||
Justification = "Makes a network request")]
|
||||
IObservable<IReadOnlyList<SshKey>> GetAllForCurrent();
|
||||
IObservable<SshKey> GetAllForCurrent();
|
||||
|
||||
/// <summary>
|
||||
/// Update the specified <see cref="UserUpdate"/>.
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Octokit.Reactive
|
||||
Miscellaneous = new ObservableMiscellaneousClient(gitHubClient.Miscellaneous);
|
||||
Organization = new ObservableOrganizationsClient(gitHubClient);
|
||||
Repository = new ObservableRepositoriesClient(gitHubClient);
|
||||
SshKey = new ObservableSshKeysClient(gitHubClient.SshKey);
|
||||
SshKey = new ObservableSshKeysClient(gitHubClient);
|
||||
User = new ObservableUsersClient(gitHubClient.User);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Internal;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
using System.Collections.Generic;
|
||||
#endif
|
||||
using System.Threading.Tasks;
|
||||
using Octokit.Internal;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
@@ -24,24 +23,19 @@ namespace Octokit
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
var endpoint = "/users/{0}/keys".FormatUri(user);
|
||||
|
||||
return await Client.GetAll<SshKey>(endpoint);
|
||||
return await Client.GetAll<SshKey>(ApiUrls.SshKeys(user));
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<SshKey>> GetAllForCurrent()
|
||||
{
|
||||
var endpoint = new Uri("/user/keys", UriKind.Relative);
|
||||
|
||||
return await Client.GetAll<SshKey>(endpoint);
|
||||
return await Client.GetAll<SshKey>(ApiUrls.SshKeys());
|
||||
}
|
||||
|
||||
public async Task<SshKey> Create(SshKeyUpdate key)
|
||||
{
|
||||
Ensure.ArgumentNotNull(key, "key");
|
||||
|
||||
var endpoint = new Uri("/user/keys", UriKind.Relative);
|
||||
return await Client.Post<SshKey>(endpoint, key);
|
||||
return await Client.Post<SshKey>(ApiUrls.SshKeys(), key);
|
||||
}
|
||||
|
||||
public async Task<SshKey> Update(int id, SshKeyUpdate key)
|
||||
|
||||
Reference in New Issue
Block a user