using System; using System.Reactive.Linq; using System.Reactive.Threading.Tasks; namespace Octokit.Reactive { public class ObservableRepositoryTrafficClient : IObservableRepositoryTrafficClient { readonly IRepositoryTrafficClient _client; public ObservableRepositoryTrafficClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Repository.Traffic; } /// /// List the top 10 popular contents over the last 14 days /// /// https://developer.github.com/v3/repos/traffic/#list-paths /// The owner of the repository public IObservable GetPaths(long repositoryId) { return _client.GetPaths(repositoryId).ToObservable().SelectMany(x => x); } /// /// List the top 10 popular contents over the last 14 days /// /// https://developer.github.com/v3/repos/traffic/#list-paths /// The owner of the repository /// The name of the repository public IObservable GetPaths(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.GetPaths(owner, name).ToObservable().SelectMany(x => x); } /// /// List the top 10 referrers over the last 14 days /// /// https://developer.github.com/v3/repos/traffic/#list-referrers /// The owner of the repository public IObservable GetReferrers(long repositoryId) { return _client.GetReferrers(repositoryId).ToObservable().SelectMany(x => x); } /// /// List the top 10 referrers over the last 14 days /// /// https://developer.github.com/v3/repos/traffic/#list-referrers /// The owner of the repository /// The name of the repository public IObservable GetReferrers(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.GetReferrers(owner, name).ToObservable().SelectMany(x => x); } /// /// Get the total number of clones and breakdown per day or week for the last 14 days /// /// https://developer.github.com/v3/repos/traffic/#clones /// The owner of the repository /// Breakdown per day or week public IObservable GetClones(long repositoryId, RepositoryTrafficRequest per) { Ensure.ArgumentNotNull(per, "per"); return _client.GetClones(repositoryId, per).ToObservable(); } /// /// Get the total number of clones and breakdown per day or week for the last 14 days /// /// https://developer.github.com/v3/repos/traffic/#clones /// The owner of the repository /// The name of the repository /// Breakdown per day or week public IObservable GetClones(string owner, string name, RepositoryTrafficRequest per) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(per, "per"); return _client.GetClones(owner, name, per).ToObservable(); } /// /// Get the total number of views and breakdown per day or week for the last 14 days /// /// https://developer.github.com/v3/repos/traffic/#views /// The owner of the repository /// Breakdown per day or week public IObservable GetViews(long repositoryId, RepositoryTrafficRequest per) { Ensure.ArgumentNotNull(per, "per"); return _client.GetViews(repositoryId, per).ToObservable(); } /// /// Get the total number of views and breakdown per day or week for the last 14 days /// /// https://developer.github.com/v3/repos/traffic/#views /// The owner of the repository /// The name of the repository /// Breakdown per day or week public IObservable GetViews(string owner, string name, RepositoryTrafficRequest per) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(per, "per"); return _client.GetViews(owner, name, per).ToObservable(); } } }