using System;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
///
/// Client for accessing contents of files within a repository as base64 encoded content.
///
public class ObservableRepositoryContentsClient : IObservableRepositoryContentsClient
{
readonly IGitHubClient _client;
///
/// Creates an instance of .
///
///
public ObservableRepositoryContentsClient(IGitHubClient client)
{
_client = client;
}
///
/// Returns the HTML rendered README.
///
/// The owner of the repository
/// The name of the repository
///
public IObservable GetReadme(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Repository.Content.GetReadme(owner, name).ToObservable();
}
///
/// Returns just the HTML portion of the README without the surrounding HTML document.
///
/// The owner of the repository
/// The name of the repository
///
public IObservable GetReadmeHtml(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Repository.Content.GetReadmeHtml(owner, name).ToObservable();
}
///
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
/// Location header to make a second GET request.
/// Note: For private repositories, these links are temporary and expire quickly.
///
/// https://developer.github.com/v3/repos/contents/#get-archive-link
/// The owner of the repository
/// The name of the repository
///
public IObservable GetArchiveLink(string owner, string name)
{
return GetArchiveLink(owner, name, ArchiveFormat.Tarball, string.Empty);
}
///
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
/// Location header to make a second GET request.
/// Note: For private repositories, these links are temporary and expire quickly.
///
/// https://developer.github.com/v3/repos/contents/#get-archive-link
/// The owner of the repository
/// The name of the repository
/// The format of the archive. Can be either tarball or zipball
///
public IObservable GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat)
{
return GetArchiveLink(owner, name, archiveFormat, String.Empty);
}
///
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
/// Location header to make a second GET request.
/// Note: For private repositories, these links are temporary and expire quickly.
///
/// https://developer.github.com/v3/repos/contents/#get-archive-link
/// The owner of the repository
/// The name of the repository
/// The format of the archive. Can be either tarball or zipball
/// A valid Git reference.
///
public IObservable GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Repository.Content.GetArchiveLink(owner, name, archiveFormat, reference).ToObservable();
}
///
/// Returns the contents of a file or directory in a repository.
///
///
/// If given a path to a single file, this method returns a collection containing only that file.
///
/// The owner of the repository
/// The name of the repository
/// The content path
///
/// A collection of representing the content at the specified path
///
public IObservable GetAllContents(string owner, string name, string path)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(path, "path");
return _client
.Connection
.GetAndFlattenAllPages(ApiUrls.RepositoryContent(owner, name, path));
}
///
/// Creates a commit that creates a new file in a repository.
///
/// The owner of the repository
/// The name of the repository
/// The path to the file
/// Information about the file to create
///
public IObservable CreateFile(string owner, string name, string path, CreateFileRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(path, "path");
Ensure.ArgumentNotNull(request, "request");
return _client.Repository.Content.CreateFile(owner, name, path, request).ToObservable();
}
///
/// Creates a commit that updates the contents of a file in a repository.
///
/// The owner of the repository
/// The name of the repository
/// The path to the file
/// Information about the file to update
/// The updated content
public IObservable UpdateFile(string owner, string name, string path, UpdateFileRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(path, "path");
Ensure.ArgumentNotNull(request, "request");
return _client.Repository.Content.UpdateFile(owner, name, path, request).ToObservable();
}
public IObservable DeleteFile(string owner, string name, string path, DeleteFileRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(path, "path");
Ensure.ArgumentNotNull(request, "request");
return _client.Repository.Content.DeleteFile(owner, name, path, request).ToObservable();
}
}
}