Skip to content

Commit

Permalink
Merge pull request #104 from ShipEngine/jpill/modify-request-from-client
Browse files Browse the repository at this point in the history
feat: allow modify request
  • Loading branch information
jpill authored Aug 1, 2024
2 parents 827664c + 579c013 commit 464cfc9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,7 @@ Updated nuget package dependencies
### Changed

Fixed handling of No Content responses

### Added

- Added basic ability to modify the HttpClient in a request
11 changes: 11 additions & 0 deletions ShipEngineSDK/ShipEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ public ShipEngine(HttpClient httpClient) : base()
_client = httpClient;
}

/// <summary>
/// Modifies the request before it is sent to the ShipEngine API
/// </summary>
/// <param name="modifyRequest"></param>
/// <returns></returns>
public ShipEngine ModifyRequest(Action<HttpRequestMessage> modifyRequest)

Check warning on line 233 in ShipEngineSDK/ShipEngine.cs

View workflow job for this annotation

GitHub Actions / .Net 8.0 on ubuntu-latest

'ShipEngine.ModifyRequest(Action<HttpRequestMessage>)' hides inherited member 'ShipEngineClient.ModifyRequest'. Use the new keyword if hiding was intended.

Check warning on line 233 in ShipEngineSDK/ShipEngine.cs

View workflow job for this annotation

GitHub Actions / .Net 8.0 on ubuntu-latest

'ShipEngine.ModifyRequest(Action<HttpRequestMessage>)' hides inherited member 'ShipEngineClient.ModifyRequest'. Use the new keyword if hiding was intended.

Check warning on line 233 in ShipEngineSDK/ShipEngine.cs

View workflow job for this annotation

GitHub Actions / .Net 8.0 on windows-latest

'ShipEngine.ModifyRequest(Action<HttpRequestMessage>)' hides inherited member 'ShipEngineClient.ModifyRequest'. Use the new keyword if hiding was intended.

Check warning on line 233 in ShipEngineSDK/ShipEngine.cs

View workflow job for this annotation

GitHub Actions / .Net 8.0 on windows-latest

'ShipEngine.ModifyRequest(Action<HttpRequestMessage>)' hides inherited member 'ShipEngineClient.ModifyRequest'. Use the new keyword if hiding was intended.
{
base.ModifyRequest = modifyRequest;
return this;
}

/// <summary>
/// Dispose of the ShipEngine client
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions ShipEngineSDK/ShipEngineClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class ShipEngineClient
/// </summary>
public CancellationToken CancellationToken { get; set; }

/// <summary>
/// Modifies the client request before it is sent
/// </summary>
public Action<HttpRequestMessage>? ModifyRequest { get; set; }

Check warning on line 51 in ShipEngineSDK/ShipEngineClient.cs

View workflow job for this annotation

GitHub Actions / .Net 8.0 on windows-latest

Symbol 'ModifyRequest.set' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

/// <summary>
/// Sets the HttpClient User agent, the json media type, and the API key to be used
/// for all ShipEngine API calls unless overrwritten at the method level.
Expand Down Expand Up @@ -204,6 +209,7 @@ public virtual async Task<T> SendHttpRequestAsync<T>(HttpMethod method, string p
try
{
var request = BuildRequest(method, path, jsonContent);
ModifyRequest?.Invoke(request);
response = await client.SendAsync(request, cancellationToken);

var deserializedResult = await DeserializedResultOrThrow<T>(response);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shipengine-dotnet",
"version": "2.2.0",
"version": "2.2.1",
"description": "Package primarily used to generate the API and models from OpenApi spec\"",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit 464cfc9

Please sign in to comment.