Skip to content

Commit

Permalink
Merge pull request #1060 from daveaglick/star-creation-timestamps
Browse files Browse the repository at this point in the history
Adds support for alternate accept header to retrieve star creation timestamps
  • Loading branch information
shiftkey committed Jan 25, 2016
2 parents da45d9e + dcb83fc commit bf3a56b
Show file tree
Hide file tree
Showing 15 changed files with 390 additions and 1 deletion.
51 changes: 51 additions & 0 deletions Octokit.Reactive/Clients/IObservableStarredClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ public interface IObservableStarredClient
/// <returns>A <see cref="IObservable{User}"/> of <see cref="User"/>s starring the passed repository</returns>
IObservable<User> GetAllStargazers(string owner, string name);

/// <summary>
/// Retrieves all of the stargazers for the passed repository with star creation timestamps.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="IObservable{UserStar}"/> of <see cref="User"/>s starring the passed repository with star creation timestamps.</returns>
IObservable<UserStar> GetAllStargazersWithTimestamps(string owner, string name);

/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user
/// </summary>
Expand All @@ -22,6 +31,15 @@ public interface IObservableStarredClient
/// </returns>
IObservable<Repository> GetAllForCurrent();

/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user with star creation timestamps.
/// </summary>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IObservable{RepoStar}"/> of <see cref="Repository"/>(ies) starred by the current authenticated user with star creation timestamps.
/// </returns>
IObservable<RepositoryStar> GetAllForCurrentWithTimestamps();

/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user
/// </summary>
Expand All @@ -33,6 +51,17 @@ public interface IObservableStarredClient
/// </returns>
IObservable<Repository> GetAllForCurrent(StarredRequest request);

/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user with star creation timestamps.
/// </summary>
/// <param name="request">Star-specific request parameters that sort the results</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IObservable{RepoStar}"/> of <see cref="Repository"/>(ies) starred by the current user,
/// sorted according to the passed request parameters and with star creation timestamps.
/// </returns>
IObservable<RepositoryStar> GetAllForCurrentWithTimestamps(StarredRequest request);

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user
/// </summary>
Expand All @@ -41,6 +70,16 @@ public interface IObservableStarredClient
/// <returns>A <see cref="IObservable{Repository}"/> starred by the specified user</returns>
IObservable<Repository> GetAllForUser(string user);

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user with star creation timestamps.
/// </summary>
/// <param name="user">The login of the user</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IObservable{RepoStar}"/>(ies) starred by the specified user with star creation timestamps.
/// </returns>
IObservable<RepositoryStar> GetAllForUserWithTimestamps(string user);

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user
/// </summary>
Expand All @@ -50,6 +89,18 @@ public interface IObservableStarredClient
/// <returns>A <see cref="IObservable{Repository}"/> starred by the specified user</returns>
IObservable<Repository> GetAllForUser(string user, StarredRequest request);

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user with star creation timestamps.
/// </summary>
/// <param name="user">The login of the user</param>
/// <param name="request">Star-specific request parameters that sort the results</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IObservable{RepoStar}"/> of <see cref="Repository"/>(ies) starred by the specified user,
/// sorted according to the passed request parameters and with star creation timestamps.
/// </returns>
IObservable<RepositoryStar> GetAllForUserWithTimestamps(string user, StarredRequest request);

/// <summary>
/// Check if a repository is starred by the current authenticated user
/// </summary>
Expand Down
78 changes: 78 additions & 0 deletions Octokit.Reactive/Clients/ObservableStarredClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ public IObservable<User> GetAllStargazers(string owner, string name)
return _connection.GetAndFlattenAllPages<User>(ApiUrls.Stargazers(owner, name));
}

/// <summary>
/// Retrieves all of the stargazers for the passed repository with star creation timestamps.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="IObservable{UserStar}"/> of <see cref="User"/>s starring the passed repository with star creation timestamps.</returns>
public IObservable<UserStar> GetAllStargazersWithTimestamps(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return _connection.GetAndFlattenAllPages<UserStar>(ApiUrls.Stargazers(owner, name), null, AcceptHeaders.StarCreationTimestamps);
}

/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user
/// </summary>
Expand All @@ -44,6 +59,18 @@ public IObservable<Repository> GetAllForCurrent()
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.Starred());
}

/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user with star creation timestamps.
/// </summary>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IObservable{RepoStar}"/> of <see cref="Repository"/>(ies) starred by the current authenticated user with star creation timestamps.
/// </returns>
public IObservable<RepositoryStar> GetAllForCurrentWithTimestamps()
{
return _connection.GetAndFlattenAllPages<RepositoryStar>(ApiUrls.Starred(), null, AcceptHeaders.StarCreationTimestamps);
}

/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user
/// </summary>
Expand All @@ -61,6 +88,23 @@ public IObservable<Repository> GetAllForCurrent(StarredRequest request)
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.Starred(), request.ToParametersDictionary());
}

/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user with star creation timestamps.
/// </summary>
/// <param name="request">Star-specific request parameters that sort the results</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IObservable{RepoStar}"/> of <see cref="Repository"/>(ies) starred by the current user,
/// sorted according to the passed request parameters and with star creation timestamps.
/// </returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public IObservable<RepositoryStar> GetAllForCurrentWithTimestamps(StarredRequest request)
{
Ensure.ArgumentNotNull(request, "request");

return _connection.GetAndFlattenAllPages<RepositoryStar>(ApiUrls.Starred(), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps);
}

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user
/// </summary>
Expand All @@ -74,6 +118,21 @@ public IObservable<Repository> GetAllForUser(string user)
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.StarredByUser(user));
}

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user with star creation timestamps.
/// </summary>
/// <param name="user">The login of the user</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IObservable{RepoStar}"/>(ies) starred by the specified user with star creation timestamps.
/// </returns>
public IObservable<RepositoryStar> GetAllForUserWithTimestamps(string user)
{
Ensure.ArgumentNotNullOrEmptyString(user, "user");

return _connection.GetAndFlattenAllPages<RepositoryStar>(ApiUrls.StarredByUser(user), null, AcceptHeaders.StarCreationTimestamps);
}

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user
/// </summary>
Expand All @@ -90,6 +149,25 @@ public IObservable<Repository> GetAllForUser(string user, StarredRequest request
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.StarredByUser(user), request.ToParametersDictionary());
}

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user with star creation timestamps.
/// </summary>
/// <param name="user">The login of the user</param>
/// <param name="request">Star-specific request parameters that sort the results</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IObservable{RepoStar}"/> of <see cref="Repository"/>(ies) starred by the specified user,
/// sorted according to the passed request parameters and with star creation timestamps.
/// </returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public IObservable<RepositoryStar> GetAllForUserWithTimestamps(string user, StarredRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(user, "user");
Ensure.ArgumentNotNull(request, "request");

return _connection.GetAndFlattenAllPages<RepositoryStar>(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps);
}

/// <summary>
/// Check if a repository is starred by the current authenticated user
/// </summary>
Expand Down
35 changes: 35 additions & 0 deletions Octokit.Tests.Integration/Clients/StarredClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using Octokit.Tests.Integration.Helpers;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Octokit.Tests.Integration.Clients
{
public class StarredClientTests
{
private readonly IGitHubClient _client;
private readonly IStarredClient _fixture;

public StarredClientTests()
{
_client = Helper.GetAuthenticatedClient();
_fixture = _client.Activity.Starring;
}

[IntegrationTest]
public async Task CanCreateAndRetrieveStarsWithTimestamps()
{
using (var context = await _client.CreateRepositoryContext("public-repo"))
{
await _fixture.RemoveStarFromRepo(context.RepositoryOwner, context.RepositoryName);
await _fixture.StarRepo(context.RepositoryOwner, context.RepositoryName);
var currentUser = await _client.User.Current();
var userStars = await _fixture.GetAllStargazersWithTimestamps(context.RepositoryOwner, context.RepositoryName);
var userStar = userStars.SingleOrDefault(x => x.User.Id == currentUser.Id);
Assert.NotNull(userStar);
Assert.True(DateTimeOffset.UtcNow.Subtract(userStar.StarredAt) < TimeSpan.FromMinutes(5));
}
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="Clients\RepositoryForksClientTests.cs" />
<Compile Include="Clients\RepositoryHooksClientTests.cs" />
<Compile Include="Clients\SearchClientTests.cs" />
<Compile Include="Clients\StarredClientTests.cs" />
<Compile Include="Clients\StatisticsClientTests.cs" />
<Compile Include="Clients\TreeClientTests.cs" />
<Compile Include="Clients\UserEmailsClientTests.cs" />
Expand Down
53 changes: 52 additions & 1 deletion Octokit/Clients/IStarredClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public interface IStarredClient
/// <returns>A <see cref="IReadOnlyPagedCollection{User}"/> of <see cref="User"/>s starring the passed repository.</returns>
Task<IReadOnlyList<User>> GetAllStargazers(string owner, string name);

/// <summary>
/// Retrieves all of the stargazers for the passed repository with star creation timestamps.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{UserStar}"/> of <see cref="User"/>s starring the passed repository with star creation timestamps.</returns>
Task<IReadOnlyList<UserStar>> GetAllStargazersWithTimestamps(string owner, string name);

/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user.
/// </summary>
Expand All @@ -29,6 +38,15 @@ public interface IStarredClient
/// </returns>
Task<IReadOnlyList<Repository>> GetAllForCurrent();

/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user with star creation timestamps.
/// </summary>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IReadOnlyPagedCollection{RepoStar}"/> of <see cref="Repository"/>(ies) starred by the current authenticated user with star creation timestamps.
/// </returns>
Task<IReadOnlyList<RepositoryStar>> GetAllForCurrentWithTimestamps();

/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user.
/// </summary>
Expand All @@ -39,7 +57,18 @@ public interface IStarredClient
/// sorted according to the passed request parameters.
/// </returns>
Task<IReadOnlyList<Repository>> GetAllForCurrent(StarredRequest request);


/// <summary>
/// Retrieves all of the starred <see cref="Repository"/>(ies) for the current user with star creation timestamps.
/// </summary>
/// <param name="request">Star-specific request parameters that sort the results</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IReadOnlyPagedCollection{RepoStar}"/> of <see cref="Repository"/>(ies) starred by the current user,
/// sorted according to the passed request parameters and with star creation timestamps.
/// </returns>
Task<IReadOnlyList<RepositoryStar>> GetAllForCurrentWithTimestamps(StarredRequest request);

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user.
/// </summary>
Expand All @@ -50,6 +79,16 @@ public interface IStarredClient
/// </returns>
Task<IReadOnlyList<Repository>> GetAllForUser(string user);

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user with star creation timestamps.
/// </summary>
/// <param name="user">The login of the user</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IReadOnlyPagedCollection{RepoStar}"/>(ies) starred by the specified user with star creation timestamps.
/// </returns>
Task<IReadOnlyList<RepositoryStar>> GetAllForUserWithTimestamps(string user);

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user.
/// </summary>
Expand All @@ -58,6 +97,18 @@ public interface IStarredClient
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> starred by the specified user.</returns>
Task<IReadOnlyList<Repository>> GetAllForUser(string user, StarredRequest request);

/// <summary>
/// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user with star creation timestamps.
/// </summary>
/// <param name="user">The login of the user</param>
/// <param name="request">Star-specific request parameters that sort the results</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>
/// A <see cref="IReadOnlyPagedCollection{RepoStar}"/> of <see cref="Repository"/>(ies) starred by the specified user,
/// sorted according to the passed request parameters and with star creation timestamps.
/// </returns>
Task<IReadOnlyList<RepositoryStar>> GetAllForUserWithTimestamps(string user, StarredRequest request);

/// <summary>
/// Check if a repository is starred by the current authenticated user.
Expand Down
Loading

0 comments on commit bf3a56b

Please sign in to comment.