Skip to content

Commit

Permalink
feat(client): DoCommand variants
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Dec 6, 2016
1 parent f16adeb commit 89487c7
Showing 1 changed file with 60 additions and 3 deletions.
63 changes: 60 additions & 3 deletions src/IpfsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,23 @@ WebClient Api()
return api;
}

protected internal string DoCommand(string command, string arg = null, params string[] options)
/// <summary>
/// Perform an <see href="https://ipfs.io/docs/api/">IPFS API command</see> returning a string.
/// </summary>
/// <param name="command">
/// The <see href="https://ipfs.io/docs/api/">IPFS API command</see>, such as
/// <see href="https://ipfs.io/docs/api/#apiv0filels">"file/ls"</see>.
/// </param>
/// <param name="arg">
/// The optional argument to the command.
/// </param>
/// <param name="options">
/// The optional flags to the command.
/// </param>
/// <returns>
/// A string representation of the command's result.
/// </returns>
public string DoCommand(string command, string arg = null, params string[] options)
{
try
{
Expand All @@ -140,13 +156,54 @@ protected internal string DoCommand(string command, string arg = null, params st
}
}

protected internal T DoCommand<T>(string command, string arg = null, params string[] options)
/// <summary>
/// Perform an <see href="https://ipfs.io/docs/api/">IPFS API command</see> returning
/// a specific <see cref="Type"/>.
/// </summary>
/// <typeparam name="T">
/// The <see cref="Type"/> of object to return.
/// </typeparam>
/// <param name="command">
/// The <see href="https://ipfs.io/docs/api/">IPFS API command</see>, such as
/// <see href="https://ipfs.io/docs/api/#apiv0filels">"file/ls"</see>.
/// </param>
/// <param name="arg">
/// The optional argument to the command.
/// </param>
/// <param name="options">
/// The optional flags to the command.
/// </param>
/// <returns>
/// A <typeparamref name="T"/>.
/// </returns>
/// <remarks>
/// The command's response is converted to <typeparamref name="T"/> using
/// <c>JsonConvert</c>.
/// </remarks>
public T DoCommand<T>(string command, string arg = null, params string[] options)
{
var json = DoCommand(command, arg, options);
return JsonConvert.DeserializeObject<T>(json);
}

protected internal Stream Download(string command, string arg = null, params string[] options)
/// <summary>
/// Perform an <see href="https://ipfs.io/docs/api/">IPFS API command</see> returning a
/// <see cref="Stream"/>.
/// </summary>
/// <param name="command">
/// The <see href="https://ipfs.io/docs/api/">IPFS API command</see>, such as
/// <see href="https://ipfs.io/docs/api/#apiv0filels">"file/ls"</see>.
/// </param>
/// <param name="arg">
/// The optional argument to the command.
/// </param>
/// <param name="options">
/// The optional flags to the command.
/// </param>
/// <returns>
/// A <see cref="Stream"/> containing the command's result.
/// </returns>
public Stream Download(string command, string arg = null, params string[] options)
{
try
{
Expand Down

0 comments on commit 89487c7

Please sign in to comment.