mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 11:40:42 +00:00
Flatten the observables for organizations
This commit is contained in:
@@ -1,18 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using Octokit.Reactive.Helpers;
|
||||
|
||||
namespace Octokit.Reactive.Clients
|
||||
{
|
||||
public class ObservableOrganizationsClient : IObservableOrganizationsClient
|
||||
{
|
||||
readonly IOrganizationsClient _client;
|
||||
readonly IConnection _connection;
|
||||
|
||||
public ObservableOrganizationsClient(IOrganizationsClient client)
|
||||
|
||||
public ObservableOrganizationsClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
_client = client;
|
||||
_client = client.Organization;
|
||||
_connection = client.Connection;
|
||||
}
|
||||
|
||||
public IObservable<Organization> Get(string org)
|
||||
@@ -22,16 +25,16 @@ namespace Octokit.Reactive.Clients
|
||||
return _client.Get(org).ToObservable();
|
||||
}
|
||||
|
||||
public IObservable<IReadOnlyList<Organization>> GetAllForCurrent()
|
||||
public IObservable<Organization> GetAllForCurrent()
|
||||
{
|
||||
return _client.GetAllForCurrent().ToObservable();
|
||||
return _connection.GetAndFlattenAllPages<Organization>(ApiUrls.Organizations());
|
||||
}
|
||||
|
||||
public IObservable<IReadOnlyList<Organization>> GetAll(string user)
|
||||
public IObservable<Organization> GetAll(string user)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return _client.GetAll(user).ToObservable();
|
||||
return _connection.GetAndFlattenAllPages<Organization>(ApiUrls.Organizations(user));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ namespace Octokit.Reactive
|
||||
/// <returns></returns>
|
||||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
|
||||
Justification = "Method makes a network request")]
|
||||
IObservable<IReadOnlyList<Organization>> GetAllForCurrent();
|
||||
IObservable<Organization> GetAllForCurrent();
|
||||
|
||||
/// <summary>
|
||||
/// Returns all the organizations for the specified user
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
IObservable<IReadOnlyList<Organization>> GetAll(string user);
|
||||
IObservable<Organization> GetAll(string user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Octokit.Reactive
|
||||
_gitHubClient = gitHubClient;
|
||||
Authorization = new ObservableAuthorizationsClient(gitHubClient.Authorization);
|
||||
Miscellaneous = new ObservableMiscellaneousClient(gitHubClient.Miscellaneous);
|
||||
Organization = new ObservableOrganizationsClient(gitHubClient.Organization);
|
||||
Organization = new ObservableOrganizationsClient(gitHubClient);
|
||||
Repository = new ObservableRepositoriesClient(gitHubClient);
|
||||
SshKey = new ObservableSshKeysClient(gitHubClient.SshKey);
|
||||
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;
|
||||
|
||||
|
||||
@@ -22,18 +22,14 @@ namespace Octokit
|
||||
|
||||
public async Task<IReadOnlyList<Organization>> GetAllForCurrent()
|
||||
{
|
||||
var endpoint = new Uri("/user/orgs", UriKind.Relative);
|
||||
|
||||
return await Client.GetAll<Organization>(endpoint);
|
||||
return await Client.GetAll<Organization>(ApiUrls.Organizations());
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<Organization>> GetAll(string user)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
var endpoint = "/users/{0}/orgs".FormatUri(user);
|
||||
|
||||
return await Client.GetAll<Organization>(endpoint);
|
||||
return await Client.GetAll<Organization>(ApiUrls.Organizations(user));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user