using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
///
/// A client for GitHub's Releases API.
///
///
/// See the Releases API documentation for more information.
///
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;
}
///
/// Gets all s for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// Thrown when a general API error occurs.
public IObservable GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAll(owner, name, ApiOptions.None);
}
///
/// Gets all s for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// Thrown when a general API error occurs.
public IObservable GetAll(long repositoryId)
{
return GetAll(repositoryId, ApiOptions.None);
}
///
/// Gets all s for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// Options for changing the API response
/// Thrown when a general API error occurs.
public IObservable GetAll(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.Releases(owner, name), options);
}
///
/// Gets all s for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// Options for changing the API response
/// Thrown when a general API error occurs.
public IObservable GetAll(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.Releases(repositoryId), options);
}
///
/// Gets a single for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// The id of the release
/// Thrown when a general API error occurs.
public IObservable Get(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Get(owner, name, id).ToObservable();
}
///
/// Gets a single for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The id of the release
/// Thrown when a general API error occurs.
public IObservable Get(long repositoryId, int id)
{
return _client.Get(repositoryId, id).ToObservable();
}
///
/// Gets the latest for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// Thrown when a general API error occurs.
public IObservable GetLatest(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.GetLatest(owner, name).ToObservable();
}
///
/// Gets the latest for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// Thrown when a general API error occurs.
public IObservable GetLatest(long repositoryId)
{
return _client.GetLatest(repositoryId).ToObservable();
}
///
/// Creates a new for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// A description of the release to create
/// Thrown when a general API error occurs.
public IObservable 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();
}
///
/// Creates a new for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// A description of the release to create
/// Thrown when a general API error occurs.
public IObservable Create(long repositoryId, NewRelease data)
{
Ensure.ArgumentNotNull(data, "data");
return _client.Create(repositoryId, data).ToObservable();
}
///
/// Edits an existing for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// The id of the release
/// A description of the release to edit
/// Thrown when a general API error occurs.
public IObservable 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();
}
///
/// Edits an existing for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The id of the release
/// A description of the release to edit
/// Thrown when a general API error occurs.
public IObservable Edit(long repositoryId, int id, ReleaseUpdate data)
{
Ensure.ArgumentNotNull(data, "data");
return _client.Edit(repositoryId, id, data).ToObservable();
}
///
/// Deletes an existing for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// The id of the release to delete
/// Thrown when a general API error occurs.
public IObservable Delete(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Delete(owner, name, id).ToObservable();
}
///
/// Deletes an existing for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The id of the release to delete
/// Thrown when a general API error occurs.
public IObservable Delete(long repositoryId, int id)
{
return _client.Delete(repositoryId, id).ToObservable();
}
///
/// Gets all for the specified release of the specified repository.
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// The id of the .
/// Thrown when a general API error occurs.
public IObservable GetAllAssets(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAllAssets(owner, name, id, ApiOptions.None);
}
///
/// Gets all for the specified release of the specified repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The id of the .
/// Thrown when a general API error occurs.
public IObservable GetAllAssets(long repositoryId, int id)
{
return GetAllAssets(repositoryId, id, ApiOptions.None);
}
///
/// Gets all for the specified release of the specified repository.
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// The id of the .
/// Options for changing the API response
/// Thrown when a general API error occurs.
public IObservable GetAllAssets(string owner, string name, int id, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.ReleaseAssets(owner, name, id), options);
}
///
/// Gets all for the specified release of the specified repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The id of the .
/// Options for changing the API response
/// Thrown when a general API error occurs.
public IObservable GetAllAssets(long repositoryId, int id, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.ReleaseAssets(repositoryId, id), options);
}
///
/// Gets the specified for the specified release of the specified repository.
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// The id of the
public IObservable 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();
}
///
/// Gets the specified for the specified release of the specified repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The id of the
public IObservable GetAsset(long repositoryId, int assetId)
{
Ensure.ArgumentNotNull(assetId, "assetId");
return _client.GetAsset(repositoryId, assetId).ToObservable();
}
///
/// Uploads a for the specified release.
///
///
/// See the API documentation for more information.
///
/// The to attach the uploaded asset to
/// Description of the asset with its data
/// Thrown when a general API error occurs.
public IObservable UploadAsset(Release release, ReleaseAssetUpload data)
{
Ensure.ArgumentNotNull(release, "release");
Ensure.ArgumentNotNull(data, "data");
return _client.UploadAsset(release, data).ToObservable();
}
///
/// Edits the for the specified release of the specified repository.
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// The id of the
/// Description of the asset with its amended data
public IObservable 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();
}
///
/// Edits the for the specified release of the specified repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The id of the
/// Description of the asset with its amended data
public IObservable EditAsset(long repositoryId, int assetId, ReleaseAssetUpdate data)
{
Ensure.ArgumentNotNull(data, "data");
return _client.EditAsset(repositoryId, assetId, data).ToObservable();
}
///
/// Deletes the specified from the specified repository
///
///
/// See the API documentation for more information.
///
/// The repository's owner
/// The repository's name
/// The id of the .
public IObservable DeleteAsset(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.DeleteAsset(owner, name, id).ToObservable();
}
///
/// Deletes the specified from the specified repository
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The id of the .
public IObservable DeleteAsset(long repositoryId, int id)
{
return _client.DeleteAsset(repositoryId, id).ToObservable();
}
}
}