Skip to content

Commit

Permalink
Add PusherRestClient constructor to accept an externally supplied Htt…
Browse files Browse the repository at this point in the history
…pClient (#90)

add PusherRestClient constructor to accept an externally supplied HttpClient
  • Loading branch information
agatav authored Jan 19, 2023
1 parent b4da785 commit d0c2449
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 4.7.0-beta.2
* [ADDED] Constructor for PusherRestClient accepting an externally supplied HttpClient

## 4.7.0-beta
* [ADDED] AuthenticateUser
* [ADDED] AuthorizeChannel
Expand Down
52 changes: 33 additions & 19 deletions PusherServer/RestfulClient/PusherRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,32 @@ public PusherRestClient(string baseAddress, string libraryName, Version version)
{}

/// <summary>
/// Constructs a new instance of the PusherRestClient
/// Constructs a new instance of the PusherRestClient with a supplied HttpClient
/// </summary>
/// <param name="baseAddress">The base address of the Pusher API</param>
/// <param name="libraryName">The name of the Pusher Library</param>
/// <param name="version">The version of the Pusher library</param>
public PusherRestClient(Uri baseAddress, string libraryName, Version version)
public PusherRestClient(Uri baseAddress, string libraryName, Version version):this(CreateDefaultHttpClient(baseAddress), libraryName, version)
{}

private static HttpClient CreateDefaultHttpClient(Uri baseAddress)
{
_httpClient = new HttpClient
return new HttpClient
{
BaseAddress = baseAddress,
Timeout = TimeSpan.FromSeconds(30),
};
}

/// <summary>
/// Constructs a new instance of the PusherRestClient with a supplied HttpClient
/// </summary>
/// <param name="httpClient">An externally configured HttpClient</param>
/// <param name="libraryName">The name of the Pusher Library</param>
/// <param name="version">The version of the Pusher library</param>
public PusherRestClient(HttpClient httpClient, string libraryName, Version version)
{
_httpClient = httpClient;
_libraryName = libraryName;
_version = version.ToString(3);
_httpClient.DefaultRequestHeaders.Clear();
Expand All @@ -48,22 +62,22 @@ public PusherRestClient(Uri baseAddress, string libraryName, Version version)
///<inheritDoc/>
public Uri BaseUrl {
get { return _httpClient.BaseAddress; }
}

///<inheritDoc/>
public TimeSpan Timeout
{
get
{
return _httpClient.Timeout;
}

set
{
_httpClient.Timeout = value;
}
}

}

///<inheritDoc/>
public TimeSpan Timeout
{
get
{
return _httpClient.Timeout;
}

set
{
_httpClient.Timeout = value;
}
}

///<inheritDoc/>
public async Task<GetResult<T>> ExecuteGetAsync<T>(IPusherRestRequest pusherRestRequest)
{
Expand Down
2 changes: 1 addition & 1 deletion Root.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageTags>pusher channels realtime websocket</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>icon-128.png</PackageIcon>
<Version>4.7.0-beta</Version>
<Version>4.7.0-beta.2</Version>
<AssemblyVersion>4.7.0.0</AssemblyVersion>
<FileVersion>4.7.0.0</FileVersion>
</PropertyGroup>
Expand Down

0 comments on commit d0c2449

Please sign in to comment.