Flatten the observables for organizations

This commit is contained in:
Haacked
2013-10-16 16:44:52 -07:00
parent 04958410ea
commit 05255d7236
5 changed files with 15 additions and 17 deletions
@@ -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);
}
}
+1 -1
View File
@@ -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;
+2 -6
View File
@@ -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));
}
}
}