Skip to content

Commit

Permalink
feat: Implement IBlockRepositoryApi
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed May 29, 2019
1 parent 0996705 commit f5f81ba
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/articles/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ string text = await ipfs.FileSystem.ReadAllTextAsync(filename);
| ------- | ------- |
| [Bitswap](xref:Ipfs.CoreApi.IBitswapApi) | Data trading module for IPFS; requests blocks from and sends blocks to other peers |
| [Block](xref:Ipfs.CoreApi.IBlockApi) | Manages the blocks |
| [BlockRepository](xref:Ipfs.CoreApi.IBlockRepositoryApi) | Manages the repository of blocks |
| [Bootstrap](xref:Ipfs.CoreApi.IBootstrapApi) | Trusted peers |
| [Config](xref:Ipfs.CoreApi.IConfigApi) | Manages the configuration of the local peer |
| [Dag](xref:Ipfs.CoreApi.IDagApi) | Manages the IPLD (linked data) Directed Acrylic Graph |
Expand Down
47 changes: 47 additions & 0 deletions src/CoreApi/BlockRepositoryApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Ipfs.CoreApi;
using System.IO;

namespace Ipfs.Http
{

class BlockRepositoryApi : IBlockRepositoryApi
{
IpfsClient ipfs;

internal BlockRepositoryApi(IpfsClient ipfs)
{
this.ipfs = ipfs;
}

public async Task RemoveGarbageAsync(CancellationToken cancel = default(CancellationToken))
{
await ipfs.DoCommandAsync("repo/gc", cancel);
}

public Task<RepositoryData> StatisticsAsync(CancellationToken cancel = default(CancellationToken))
{
return ipfs.DoCommandAsync<RepositoryData>("repo/stat", cancel);
}

public async Task VerifyAsync(CancellationToken cancel = default(CancellationToken))
{
await ipfs.DoCommandAsync("repo/verify", cancel);
}

public async Task<string> VersionAsync(CancellationToken cancel = default(CancellationToken))
{
var json = await ipfs.DoCommandAsync("repo/version", cancel);
var info = JObject.Parse(json);
return (string)info["Version"];
}
}
}
4 changes: 4 additions & 0 deletions src/IpfsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public IpfsClient()
Bootstrap = new BootstrapApi(this);
Bitswap = new BitswapApi(this);
Block = new BlockApi(this);
BlockRepository = new BlockRepositoryApi(this);
Config = new ConfigApi(this);
Pin = new PinApi(this);
Dht = new DhtApi(this);
Expand Down Expand Up @@ -138,6 +139,9 @@ public IpfsClient(string host)
/// <inheritdoc />
public IBlockApi Block { get; private set; }

/// <inheritdoc />
public IBlockRepositoryApi BlockRepository { get; private set; }

/// <inheritdoc />
public IConfigApi Config { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion src/IpfsHttpClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Ipfs.Core" Version="0.50.0" />
<PackageReference Include="Ipfs.Core" Version="0.51.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'netstandard14'" />
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'net45'" />
Expand Down
32 changes: 32 additions & 0 deletions test/CoreApi/BlockRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ipfs.Http
{

[TestClass]
public class BlockRepositoryTest
{

[TestMethod]
public async Task Stats()
{
var ipfs = TestFixture.Ipfs;
var stats = await ipfs.BlockRepository.StatisticsAsync();
Assert.IsNotNull(stats);
}

[TestMethod]
public async Task Version()
{
var ipfs = TestFixture.Ipfs;
var version = await ipfs.BlockRepository.VersionAsync();
Assert.IsFalse(string.IsNullOrWhiteSpace(version));
}

}
}

0 comments on commit f5f81ba

Please sign in to comment.