Skip to content

Commit

Permalink
feat(IStatsApi): implement
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Dec 10, 2018
1 parent 0226b1b commit 7c3bf33
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/CoreApi/StatsApi.cs
@@ -0,0 +1,42 @@
using Common.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Ipfs.CoreApi;

namespace Ipfs.Http
{

class StatApi : IStatsApi
{
IpfsClient ipfs;

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

public Task<BandwidthData> BandwidthAsync(CancellationToken cancel = default(CancellationToken))
{
return ipfs.DoCommandAsync<BandwidthData>("stats/bw", cancel);
}

public Task<BitswapData> BitswapAsync(CancellationToken cancel = default(CancellationToken))
{
return ipfs.DoCommandAsync<BitswapData>("stats/bitswap", cancel);
}

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


}
}
4 changes: 4 additions & 0 deletions src/IpfsClient.cs
Expand Up @@ -78,6 +78,7 @@ public IpfsClient()
Generic = this;
Name = new NameApi(this);
Dns = new DnsApi(this);
Stats = new StatApi(this);
}

/// <summary>
Expand Down Expand Up @@ -128,6 +129,9 @@ public IpfsClient(string host)
/// <inheritdoc />
public IDnsApi Dns { get; private set; }

/// <inheritdoc />
public IStatsApi Stats { get; private set; }

/// <inheritdoc />
public INameApi Name { get; private set; }

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

<ItemGroup>
<PackageReference Include="Ipfs.Core" Version="0.35.2" />
<PackageReference Include="Ipfs.Core" Version="0.38.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<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
25 changes: 25 additions & 0 deletions test/CoreApi/StatsApiTest.cs
@@ -0,0 +1,25 @@
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 StatsApiTest
{

[TestMethod]
public async Task SmokeTest()
{
var ipfs = TestFixture.Ipfs;
var bandwidth = await ipfs.Stats.BandwidthAsync();
var bitswap = await ipfs.Stats.BitswapAsync();
var repository = await ipfs.Stats.RepositoryAsync();
}

}
}

0 comments on commit 7c3bf33

Please sign in to comment.