mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-09 13:01:36 +00:00
Flatten the observables for users
This commit is contained in:
@@ -1,17 +1,20 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Reactive.Threading.Tasks;
|
using System.Reactive.Threading.Tasks;
|
||||||
|
using Octokit.Reactive.Helpers;
|
||||||
|
|
||||||
namespace Octokit.Reactive.Clients
|
namespace Octokit.Reactive.Clients
|
||||||
{
|
{
|
||||||
public class ObservableUsersClient : IObservableUsersClient
|
public class ObservableUsersClient : IObservableUsersClient
|
||||||
{
|
{
|
||||||
readonly IUsersClient _client;
|
readonly IUsersClient _client;
|
||||||
|
readonly IConnection _connection;
|
||||||
|
|
||||||
public ObservableUsersClient(IUsersClient client)
|
public ObservableUsersClient(IGitHubClient client)
|
||||||
{
|
{
|
||||||
Ensure.ArgumentNotNull(client, "client");
|
Ensure.ArgumentNotNull(client, "client");
|
||||||
|
|
||||||
_client = client;
|
_client = client.User;
|
||||||
|
_connection = client.Connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IObservable<User> Get(string login)
|
public IObservable<User> Get(string login)
|
||||||
@@ -33,9 +36,9 @@ namespace Octokit.Reactive.Clients
|
|||||||
return _client.Update(user).ToObservable();
|
return _client.Update(user).ToObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IObservable<IReadOnlyList<EmailAddress>> GetEmails()
|
public IObservable<EmailAddress> GetEmails()
|
||||||
{
|
{
|
||||||
return _client.GetEmails().ToObservable();
|
return _connection.GetAndFlattenAllPages<EmailAddress>(ApiUrls.Emails());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,6 @@ namespace Octokit.Reactive
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
|
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
|
||||||
IObservable<IReadOnlyList<EmailAddress>> GetEmails();
|
IObservable<EmailAddress> GetEmails();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using System.Collections.ObjectModel;
|
|||||||
#endif
|
#endif
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
using Octokit.Internal;
|
|
||||||
using Octokit.Tests.Helpers;
|
using Octokit.Tests.Helpers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ namespace Octokit
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class UsersClient : ApiClient, IUsersClient
|
public class UsersClient : ApiClient, IUsersClient
|
||||||
{
|
{
|
||||||
static readonly Uri userEndpoint = new Uri("/user", UriKind.Relative);
|
static readonly Uri _userEndpoint = new Uri("/user", UriKind.Relative);
|
||||||
static readonly Uri emailsEndpoint = new Uri("/user/emails", UriKind.Relative);
|
|
||||||
|
|
||||||
public UsersClient(IApiConnection client) : base(client)
|
public UsersClient(IApiConnection client) : base(client)
|
||||||
{
|
{
|
||||||
@@ -41,7 +40,7 @@ namespace Octokit
|
|||||||
/// <returns>A <see cref="User"/></returns>
|
/// <returns>A <see cref="User"/></returns>
|
||||||
public async Task<User> Current()
|
public async Task<User> Current()
|
||||||
{
|
{
|
||||||
return await Client.Get<User>(userEndpoint);
|
return await Client.Get<User>(_userEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -54,7 +53,7 @@ namespace Octokit
|
|||||||
{
|
{
|
||||||
Ensure.ArgumentNotNull(user, "user");
|
Ensure.ArgumentNotNull(user, "user");
|
||||||
|
|
||||||
return await Client.Patch<User>(userEndpoint, user);
|
return await Client.Patch<User>(_userEndpoint, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -63,7 +62,7 @@ namespace Octokit
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<IReadOnlyList<EmailAddress>> GetEmails()
|
public async Task<IReadOnlyList<EmailAddress>> GetEmails()
|
||||||
{
|
{
|
||||||
return await Client.Get<ReadOnlyCollection<EmailAddress>>(emailsEndpoint, null);
|
return await Client.Get<ReadOnlyCollection<EmailAddress>>(ApiUrls.Emails(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user