Skip to content

Commit

Permalink
feat: modify request
Browse files Browse the repository at this point in the history
  • Loading branch information
jpill committed Jul 22, 2024
1 parent 3b89b48 commit 9488813
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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 @@ -199,6 +204,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

0 comments on commit 9488813

Please sign in to comment.