Skip to content

Commit 7c3bf33

Browse files
feat(IStatsApi): implement
1 parent 0226b1b commit 7c3bf33

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

src/CoreApi/StatsApi.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Common.Logging;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Linq;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading;
10+
using System.Threading.Tasks;
11+
using Ipfs.CoreApi;
12+
13+
namespace Ipfs.Http
14+
{
15+
16+
class StatApi : IStatsApi
17+
{
18+
IpfsClient ipfs;
19+
20+
internal StatApi(IpfsClient ipfs)
21+
{
22+
this.ipfs = ipfs;
23+
}
24+
25+
public Task<BandwidthData> BandwidthAsync(CancellationToken cancel = default(CancellationToken))
26+
{
27+
return ipfs.DoCommandAsync<BandwidthData>("stats/bw", cancel);
28+
}
29+
30+
public Task<BitswapData> BitswapAsync(CancellationToken cancel = default(CancellationToken))
31+
{
32+
return ipfs.DoCommandAsync<BitswapData>("stats/bitswap", cancel);
33+
}
34+
35+
public Task<RepositoryData> RepositoryAsync(CancellationToken cancel = default(CancellationToken))
36+
{
37+
return ipfs.DoCommandAsync<RepositoryData>("stats/repo", cancel);
38+
}
39+
40+
41+
}
42+
}

src/IpfsClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public IpfsClient()
7878
Generic = this;
7979
Name = new NameApi(this);
8080
Dns = new DnsApi(this);
81+
Stats = new StatApi(this);
8182
}
8283

8384
/// <summary>
@@ -128,6 +129,9 @@ public IpfsClient(string host)
128129
/// <inheritdoc />
129130
public IDnsApi Dns { get; private set; }
130131

132+
/// <inheritdoc />
133+
public IStatsApi Stats { get; private set; }
134+
131135
/// <inheritdoc />
132136
public INameApi Name { get; private set; }
133137

src/IpfsHttpClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="Ipfs.Core" Version="0.35.2" />
30+
<PackageReference Include="Ipfs.Core" Version="0.38.0" />
3131
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
3232
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'netstandard14'" />
3333
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'net45'" />

test/CoreApi/StatsApiTest.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Ipfs.Http
9+
{
10+
11+
[TestClass]
12+
public class StatsApiTest
13+
{
14+
15+
[TestMethod]
16+
public async Task SmokeTest()
17+
{
18+
var ipfs = TestFixture.Ipfs;
19+
var bandwidth = await ipfs.Stats.BandwidthAsync();
20+
var bitswap = await ipfs.Stats.BitswapAsync();
21+
var repository = await ipfs.Stats.RepositoryAsync();
22+
}
23+
24+
}
25+
}

0 commit comments

Comments
 (0)