Skip to content

Commit

Permalink
Rename WebhookEvent to WebhookEventType
Browse files Browse the repository at this point in the history
Avoid two classes called WebhookEvent, but in different namespaces.
  • Loading branch information
filipetoscano committed Jan 2, 2025
1 parent 5cc0223 commit 6d79a86
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/Resend.Webhooks/EmailEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class EmailEventData : IWebhookData

/// <summary />
/// <remarks>
/// Only set for <see cref="Resend.WebhookEvent.EmailClicked" />, otherwise is null.
/// Only set for <see cref="Resend.WebhookEventType.EmailClicked" />, otherwise is null.
/// </remarks>
[JsonPropertyName( "click" )]
public EmailClickData? Click { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions src/Resend.Webhooks/Json/WebhookEventConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace Resend.Webhooks;
/// <summary />
public class WebhookEventConverter : JsonConverter<WebhookEvent>
{
private readonly JsonStringEnumValueConverter<Resend.WebhookEvent> _wet;
private readonly JsonStringEnumValueConverter<WebhookEventType> _wet;
private readonly JsonUtcDateTimeConverter _utc;

/// <summary />
public WebhookEventConverter()
{
_wet = new JsonStringEnumValueConverter<Resend.WebhookEvent>();
_wet = new JsonStringEnumValueConverter<WebhookEventType>();
_utc = new JsonUtcDateTimeConverter();
}

Expand Down Expand Up @@ -42,7 +42,7 @@ public WebhookEventConverter()
throw new JsonException( "Expected 'type' property" );

reader.Read();
value.EventType = _wet.Read( ref reader, typeof( Resend.WebhookEvent ), options );
value.EventType = _wet.Read( ref reader, typeof( WebhookEventType ), options );

var category = value.EventType.Category();

Expand Down
2 changes: 1 addition & 1 deletion src/Resend.Webhooks/WebhookEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class WebhookEvent
{
/// <summary />
[JsonPropertyName( "type" )]
public Resend.WebhookEvent EventType { get; set; }
public WebhookEventType EventType { get; set; }

/// <summary />
[JsonPropertyName( "created_at" )]
Expand Down
28 changes: 14 additions & 14 deletions src/Resend/ResendExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ public static class ResendExtensions
/// <summary>
/// Returns the event category for a given event type.
/// </summary>
public static WebhookEventTypeCategory Category( this WebhookEvent @event )
public static WebhookEventTypeCategory Category( this WebhookEventType @event )
{
switch ( @event )
{
case WebhookEvent.DomainCreated:
case WebhookEvent.DomainUpdated:
case WebhookEvent.DomainDeleted:
case WebhookEventType.DomainCreated:
case WebhookEventType.DomainUpdated:
case WebhookEventType.DomainDeleted:
return WebhookEventTypeCategory.Domain;

case WebhookEvent.ContactCreated:
case WebhookEvent.ContactUpdated:
case WebhookEvent.ContactDeleted:
case WebhookEventType.ContactCreated:
case WebhookEventType.ContactUpdated:
case WebhookEventType.ContactDeleted:
return WebhookEventTypeCategory.Contact;

case WebhookEvent.EmailBounced:
case WebhookEvent.EmailClicked:
case WebhookEvent.EmailComplained:
case WebhookEvent.EmailDelivered:
case WebhookEvent.EmailDeliveryDelay:
case WebhookEvent.EmailOpened:
case WebhookEvent.EmailSent:
case WebhookEventType.EmailBounced:
case WebhookEventType.EmailClicked:
case WebhookEventType.EmailComplained:
case WebhookEventType.EmailDelivered:
case WebhookEventType.EmailDeliveryDelay:
case WebhookEventType.EmailOpened:
case WebhookEventType.EmailSent:
return WebhookEventTypeCategory.Email;

default:
Expand Down
2 changes: 1 addition & 1 deletion src/Resend/Webhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Webhook

/// <summary />
[JsonPropertyName( "events" )]
public List<WebhookEvent> Events { get; set; } = default!;
public List<WebhookEventType> Events { get; set; } = default!;

/// <summary />
/// <remarks>
Expand Down
4 changes: 2 additions & 2 deletions src/Resend/WebhookEvent.cs → src/Resend/WebhookEventType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Resend;
/// <remarks>
/// See https://www.resend.com/docs/dashboard/webhooks/event-types
/// </remarks>
[JsonConverter( typeof( JsonStringEnumValueConverter<WebhookEvent> ) )]
public enum WebhookEvent
[JsonConverter( typeof( JsonStringEnumValueConverter<WebhookEventType> ) )]
public enum WebhookEventType
{
/// <summary>
/// The API request was successful and Resend will attempt to deliver
Expand Down
9 changes: 4 additions & 5 deletions tests/Resend.Webhooks.Tests/WebhookEventConverterTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Text.Json;
using System.Text.Json;

namespace Resend.Webhooks.Tests;

Expand All @@ -25,7 +24,7 @@ public void EmailEventRoundtrip()
expectedEmail.MomentCreated = utcNow;

var expected = new WebhookEvent();
expected.EventType = Resend.WebhookEvent.EmailSent;
expected.EventType = WebhookEventType.EmailSent;
expected.MomentCreated = utcNow;
expected.Data = expectedEmail;

Expand Down Expand Up @@ -68,7 +67,7 @@ public void ContactEventRoundtrip()
expectedContact.MomentCreated = utcNow;

var expected = new WebhookEvent();
expected.EventType = Resend.WebhookEvent.ContactCreated;
expected.EventType = WebhookEventType.ContactCreated;
expected.MomentCreated = utcNow;
expected.Data = expectedContact;

Expand Down Expand Up @@ -114,7 +113,7 @@ public void DomainEventRoundtrip()
expectedDomain.MomentCreated = utcNow;

var expected = new WebhookEvent();
expected.EventType = Resend.WebhookEvent.DomainCreated;
expected.EventType = WebhookEventType.DomainCreated;
expected.MomentCreated = utcNow;
expected.Data = expectedDomain;

Expand Down

0 comments on commit 6d79a86

Please sign in to comment.