Skip to content

Commit

Permalink
Add the WebhookSettings.GetSignedEventWebhookPublicKeyAsync method
Browse files Browse the repository at this point in the history
Resolves #329
  • Loading branch information
Jericho committed Nov 28, 2020
1 parent 4b6f834 commit fc69cf5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Source/StrongGrid.IntegrationTests/Tests/WebhookSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ public async Task RunAsync(IBaseClient client, TextWriter log, CancellationToken

// GET THE EVENT SETTINGS
var eventWebhookSettings = await client.WebhookSettings.GetEventWebhookSettingsAsync(null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync("The event webhooks settings have been retrieved.").ConfigureAwait(false);
await log.WriteLineAsync("The event webhook settings have been retrieved.").ConfigureAwait(false);

// GET THE INBOUND PARSE SETTINGS
var inboundParseWebhookSettings = await client.WebhookSettings.GetAllInboundParseWebhookSettingsAsync(null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync("The inbound parse webhooks settings have been retrieved.").ConfigureAwait(false);
await log.WriteLineAsync("The inbound parse webhook settings have been retrieved.").ConfigureAwait(false);

// GET THE SIGNED EVENTS PUBLIC KEY
var publicKey = await client.WebhookSettings.GetSignedEventsPublicKeyAsync(cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"The signed events public key is: {publicKey}").ConfigureAwait(false);
}
}
}
9 changes: 9 additions & 0 deletions Source/StrongGrid/Resources/IWebhookSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,14 @@ Task<EventWebhookSettings> UpdateEventWebhookSettingsAsync(
/// The async task.
/// </returns>
Task DeleteInboundParseWebhookSettingsAsync(string hostname, string onBehalfOf = null, CancellationToken cancellationToken = default);

/// <summary>
/// Get the signed events public key.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The public key.
/// </returns>
Task<string> GetSignedEventsPublicKeyAsync(CancellationToken cancellationToken = default);
}
}
15 changes: 15 additions & 0 deletions Source/StrongGrid/Resources/WebhookSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ public Task DeleteInboundParseWebhookSettingsAsync(string hostname, string onBeh
.AsMessage();
}

/// <summary>
/// Get the signed event webhook public key.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The public key.
/// </returns>
public Task<string> GetSignedEventWebhookPublicKeyAsync(CancellationToken cancellationToken = default)
{
return _client
.GetAsync($"{_eventWebhookEndpoint}/settings/signed")
.WithCancellationToken(cancellationToken)
.AsSendGridObject<string>("public_key");
}

private static JObject CreateJObject(string hostname, Parameter<string> url, Parameter<bool> spamCheck, Parameter<bool> sendRaw)
{
var result = new JObject
Expand Down

0 comments on commit fc69cf5

Please sign in to comment.