Skip to content

Commit

Permalink
feat: add constructors to allow custom http client (#5)
Browse files Browse the repository at this point in the history
Add extra constructors to `Connection` and `Client` to allow customizing the http client.
  • Loading branch information
Thundernerd authored Feb 17, 2024
1 parent 533d4a5 commit cfc56c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Modio/Client.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;

using Modio.Models;
Expand Down Expand Up @@ -50,6 +51,13 @@ public Client(Credentials credentials) : this(new Connection(ModioApiUrl, creden
public Client(Uri baseUrl, Credentials credentials) : this(new Connection(FixBaseUrl(baseUrl), credentials))
{
}

/// <summary>
/// Initializes a new instance of <see cref="Client"/> with a custom host, custom <paramref name="credentials"/>, and a custom <paramref name="httpClient"/>.
/// </summary>
public Client(Uri baseUrl, Credentials credentials, HttpClient httpClient) : this(new Connection(FixBaseUrl(baseUrl), credentials, httpClient))
{
}

private Client(IConnection connection)
{
Expand Down
8 changes: 6 additions & 2 deletions Modio/Http/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ internal class Connection : IConnection

public Credentials Credentials { get; set; }

public Connection(Uri baseAddress, Credentials credentials)
public Connection(Uri baseAddress, Credentials credentials) : this(baseAddress, credentials, new HttpClient())
{
http = new HttpClient();
}

public Connection(Uri baseAddress, Credentials credentials, HttpClient httpClient)
{
http = httpClient;
BaseAddress = baseAddress;
Credentials = credentials;
}
Expand Down

0 comments on commit cfc56c9

Please sign in to comment.