Files
octokit.net/Octokit.Reactive/Clients/ObservableReleasesClient.cs
Martin Scholz a57fb1278d [WIP] Add repository traffic preview (#1457)
* Add response models

* Supress message

* correct spelling Timestamp

* implement traffic client

* add reactive client

* [WIP] unit tests

* add argument check

* finish unit tests

* add integration tests

* Change repositoryId from int to long
Remove GetAll naming of endpoints and add to PaginationTest exclusions
Rename View and Clone classes to be more specific
Add handling of TimeStamp fields being UtcUnix time
Add integration tests for repositoryId methods
2016-09-29 01:16:58 +10:00

443 lines
21 KiB
C#

using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Releases API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/">Releases API documentation</a> for more information.
/// </remarks>
public class ObservableReleasesClient : IObservableReleasesClient
{
readonly IReleasesClient _client;
readonly IConnection _connection;
public ObservableReleasesClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.Repository.Release;
_connection = client.Connection;
}
/// <summary>
/// Gets all <see cref="Release"/>s for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#list-releases-for-a-repository">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAll(owner, name, ApiOptions.None);
}
/// <summary>
/// Gets all <see cref="Release"/>s for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#list-releases-for-a-repository">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> GetAll(long repositoryId)
{
return GetAll(repositoryId, ApiOptions.None);
}
/// <summary>
/// Gets all <see cref="Release"/>s for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#list-releases-for-a-repository">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="options">Options for changing the API response</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> GetAll(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<Release>(ApiUrls.Releases(owner, name), options);
}
/// <summary>
/// Gets all <see cref="Release"/>s for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#list-releases-for-a-repository">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="options">Options for changing the API response</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> GetAll(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<Release>(ApiUrls.Releases(repositoryId), options);
}
/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#get-a-single-release">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="id">The id of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> Get(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Get(owner, name, id).ToObservable();
}
/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#get-a-single-release">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="id">The id of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> Get(long repositoryId, int id)
{
return _client.Get(repositoryId, id).ToObservable();
}
/// <summary>
/// Gets the latest <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/releases/#get-the-latest-release">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> GetLatest(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.GetLatest(owner, name).ToObservable();
}
/// <summary>
/// Gets the latest <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/releases/#get-the-latest-release">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> GetLatest(long repositoryId)
{
return _client.GetLatest(repositoryId).ToObservable();
}
/// <summary>
/// Creates a new <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#create-a-release">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="data">A description of the release to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> Create(string owner, string name, NewRelease data)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(data, "data");
return _client.Create(owner, name, data).ToObservable();
}
/// <summary>
/// Creates a new <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#create-a-release">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="data">A description of the release to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> Create(long repositoryId, NewRelease data)
{
Ensure.ArgumentNotNull(data, "data");
return _client.Create(repositoryId, data).ToObservable();
}
/// <summary>
/// Edits an existing <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#edit-a-release">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="id">The id of the release</param>
/// <param name="data">A description of the release to edit</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> Edit(string owner, string name, int id, ReleaseUpdate data)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(data, "data");
return _client.Edit(owner, name, id, data).ToObservable();
}
/// <summary>
/// Edits an existing <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#edit-a-release">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="id">The id of the release</param>
/// <param name="data">A description of the release to edit</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Release> Edit(long repositoryId, int id, ReleaseUpdate data)
{
Ensure.ArgumentNotNull(data, "data");
return _client.Edit(repositoryId, id, data).ToObservable();
}
/// <summary>
/// Deletes an existing <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#delete-a-release">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="id">The id of the release to delete</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Unit> Delete(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Delete(owner, name, id).ToObservable();
}
/// <summary>
/// Deletes an existing <see cref="Release"/> for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#delete-a-release">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="id">The id of the release to delete</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Unit> Delete(long repositoryId, int id)
{
return _client.Delete(repositoryId, id).ToObservable();
}
/// <summary>
/// Gets all <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#list-assets-for-a-release">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="id">The id of the <see cref="Release"/>.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<ReleaseAsset> GetAllAssets(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAllAssets(owner, name, id, ApiOptions.None);
}
/// <summary>
/// Gets all <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#list-assets-for-a-release">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="id">The id of the <see cref="Release"/>.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<ReleaseAsset> GetAllAssets(long repositoryId, int id)
{
return GetAllAssets(repositoryId, id, ApiOptions.None);
}
/// <summary>
/// Gets all <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#list-assets-for-a-release">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="id">The id of the <see cref="Release"/>.</param>
/// <param name="options">Options for changing the API response</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<ReleaseAsset> GetAllAssets(string owner, string name, int id, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<ReleaseAsset>(ApiUrls.ReleaseAssets(owner, name, id), options);
}
/// <summary>
/// Gets all <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#list-assets-for-a-release">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="id">The id of the <see cref="Release"/>.</param>
/// <param name="options">Options for changing the API response</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<ReleaseAsset> GetAllAssets(long repositoryId, int id, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<ReleaseAsset>(ApiUrls.ReleaseAssets(repositoryId, id), options);
}
/// <summary>
/// Gets the specified <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#get-a-single-release-asset">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="assetId">The id of the <see cref="ReleaseAsset"/></param>
public IObservable<ReleaseAsset> GetAsset(string owner, string name, int assetId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(assetId, "assetId");
return _client.GetAsset(owner, name, assetId).ToObservable();
}
/// <summary>
/// Gets the specified <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#get-a-single-release-asset">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="assetId">The id of the <see cref="ReleaseAsset"/></param>
public IObservable<ReleaseAsset> GetAsset(long repositoryId, int assetId)
{
Ensure.ArgumentNotNull(assetId, "assetId");
return _client.GetAsset(repositoryId, assetId).ToObservable();
}
/// <summary>
/// Uploads a <see cref="ReleaseAsset"/> for the specified release.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#upload-a-release-asset">API documentation</a> for more information.
/// </remarks>
/// <param name="release">The <see cref="Release"/> to attach the uploaded asset to</param>
/// <param name="data">Description of the asset with its data</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<ReleaseAsset> UploadAsset(Release release, ReleaseAssetUpload data)
{
Ensure.ArgumentNotNull(release, "release");
Ensure.ArgumentNotNull(data, "data");
return _client.UploadAsset(release, data).ToObservable();
}
/// <summary>
/// Edits the <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#edit-a-release-asset">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="assetId">The id of the <see cref="ReleaseAsset"/></param>
/// <param name="data">Description of the asset with its amended data</param>
public IObservable<ReleaseAsset> EditAsset(string owner, string name, int assetId, ReleaseAssetUpdate data)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(data, "data");
return _client.EditAsset(owner, name, assetId, data).ToObservable();
}
/// <summary>
/// Edits the <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#edit-a-release-asset">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="assetId">The id of the <see cref="ReleaseAsset"/></param>
/// <param name="data">Description of the asset with its amended data</param>
public IObservable<ReleaseAsset> EditAsset(long repositoryId, int assetId, ReleaseAssetUpdate data)
{
Ensure.ArgumentNotNull(data, "data");
return _client.EditAsset(repositoryId, assetId, data).ToObservable();
}
/// <summary>
/// Deletes the specified <see cref="ReleaseAsset"/> from the specified repository
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#delete-a-release-asset">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="id">The id of the <see cref="ReleaseAsset"/>.</param>
public IObservable<Unit> DeleteAsset(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.DeleteAsset(owner, name, id).ToObservable();
}
/// <summary>
/// Deletes the specified <see cref="ReleaseAsset"/> from the specified repository
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/releases/#delete-a-release-asset">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="id">The id of the <see cref="ReleaseAsset"/>.</param>
public IObservable<Unit> DeleteAsset(long repositoryId, int id)
{
return _client.DeleteAsset(repositoryId, id).ToObservable();
}
}
}