Skip to content

Commit 5eb0518

Browse files
committed
Add configurator for network
1 parent d4289fe commit 5eb0518

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

GeometryDashAPI/GeometryDashAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<RepositoryUrl>https://github.com/Folleach/GeometryDashAPI</RepositoryUrl>
1212
<RepositoryType>git</RepositoryType>
1313
<PackageTags>api, geometry, dash</PackageTags>
14-
<PackageVersion>0.1.12</PackageVersion>
14+
<PackageVersion>0.1.13</PackageVersion>
1515
<LangVersion>9</LangVersion>
1616
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1717
</PropertyGroup>

GeometryDashAPI/Server/GameServer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ public class GameServer
1010
{
1111
private readonly IdentifierQuery identifierQuery;
1212
private readonly OnlineQuery onlineQuery;
13-
private readonly Network network = new();
13+
private readonly Network network;
1414

15-
public GameServer()
15+
public GameServer() : this(null)
1616
{
1717
}
1818

19-
public GameServer(IdentifierQuery identifierQuery = null, OnlineQuery onlineQuery = null)
19+
public GameServer(IdentifierQuery identifierQuery = null, OnlineQuery onlineQuery = null, Network network = null)
2020
{
2121
this.identifierQuery = identifierQuery;
2222
this.onlineQuery = onlineQuery;
23+
this.network = network ?? new Network();
2324
}
2425

2526
public async Task<ServerResponse<TopResponse>> GetTop(TopType type, int count)

GeometryDashAPI/Server/Network.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Net;
34
using System.Text;
45
using System.Threading.Tasks;
56

67
namespace GeometryDashAPI.Server
78
{
8-
internal class Network
9+
public class Network
910
{
11+
private readonly Action<HttpWebRequest> configurator;
1012
public Encoding DataEncoding { get; }
1113
public int Timeout { get; set; } = 30_000;
1214

1315
public Network() : this(Encoding.ASCII)
1416
{
1517
}
1618

17-
public Network(Encoding encoding)
19+
public Network(Encoding encoding, Action<HttpWebRequest> configurator = null)
1820
{
1921
DataEncoding = encoding;
22+
this.configurator = configurator;
2023
}
2124

2225
public async Task<(HttpStatusCode statusCode, string body)> GetAsync(string path, IQuery query)
@@ -31,6 +34,7 @@ public Network(Encoding encoding)
3134
client.Method = "POST";
3235
client.Timeout = Timeout;
3336
client.Accept = "*/*";
37+
configurator?.Invoke(client);
3438
var data = DataEncoding.GetBytes(properties.ToString());
3539
var requestStream = await client.GetRequestStreamAsync();
3640
await requestStream.WriteAsync(data, 0, data.Length);

0 commit comments

Comments
 (0)