using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
public class RepositoryContentsClient : ApiClient, IRepositoryContentsClient
{
public RepositoryContentsClient(IApiConnection apiConnection) : base(apiConnection)
{
}
///
/// 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 async Task> GetContents(string owner, string name, string path)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(path, "path");
var url = ApiUrls.RepositoryContent(owner, name, path);
return await ApiConnection.GetAll(url);
}
///
/// Gets the preferred README for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// Thrown when a general API error occurs.
///
public async Task GetReadme(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
var endpoint = ApiUrls.RepositoryReadme(owner, name);
var readmeInfo = await ApiConnection.Get(endpoint, null).ConfigureAwait(false);
return new Readme(readmeInfo, ApiConnection);
}
///
/// Gets the perferred README's HTML for the specified repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// Thrown when a general API error occurs.
///
public Task GetReadmeHtml(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return ApiConnection.GetHtml(ApiUrls.RepositoryReadme(owner, name), null);
}
///
/// 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 Task 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");
var createUrl = ApiUrls.RepositoryContent(owner, name, path);
return ApiConnection.Put(createUrl, request);
}
///
/// 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 Task 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");
var updateUrl = ApiUrls.RepositoryContent(owner, name, path);
return ApiConnection.Put(updateUrl, request);
}
///
/// Creates a commit that deletes 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 delete
public Task 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");
var deleteUrl = ApiUrls.RepositoryContent(owner, name, path);
return ApiConnection.Delete(deleteUrl, request);
}
}
}