diff --git a/src/Resend/Contact.cs b/src/Resend/Contact.cs index 768297e..a2d3f9f 100644 --- a/src/Resend/Contact.cs +++ b/src/Resend/Contact.cs @@ -52,5 +52,5 @@ public class Contact /// [JsonPropertyName( "properties" )] [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )] - public Dictionary? Properties { get; set; } + public Dictionary? Properties { get; set; } } \ No newline at end of file diff --git a/src/Resend/ContactPropertyType.cs b/src/Resend/ContactPropertyType.cs index 8bef41b..e43b9bc 100644 --- a/src/Resend/ContactPropertyType.cs +++ b/src/Resend/ContactPropertyType.cs @@ -19,4 +19,10 @@ public enum ContactPropertyType /// [JsonStringValue( "number" )] Number, + + /// + /// Boolean. + /// + [JsonStringValue( "boolean" )] + Boolean, } \ No newline at end of file diff --git a/src/Resend/ContactPropertyValue.cs b/src/Resend/ContactPropertyValue.cs new file mode 100644 index 0000000..e5410ed --- /dev/null +++ b/src/Resend/ContactPropertyValue.cs @@ -0,0 +1,22 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Resend; + +/// +/// Custom property value on a contact. +/// +public class ContactPropertyValue +{ + /// + /// Property value; a string, number, or boolean, depending on . + /// + [JsonPropertyName( "value" )] + public JsonElement Value { get; set; } + + /// + /// Property data-type. + /// + [JsonPropertyName( "type" )] + public ContactPropertyType PropertyType { get; set; } +} diff --git a/tests/Resend.Tests/ResendClientTests.cs b/tests/Resend.Tests/ResendClientTests.cs index 7bcd9ca..5afebd7 100644 --- a/tests/Resend.Tests/ResendClientTests.cs +++ b/tests/Resend.Tests/ResendClientTests.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc.Testing; using Resend.ApiServer; using System.Net; +using System.Text.Json; namespace Resend.Tests; @@ -328,6 +329,11 @@ public async Task ContactRetrieve() var resp = await _resend.ContactRetrieveAsync( Guid.NewGuid() ); Assert.NotNull( resp ); + Assert.NotNull( resp.Content.Properties ); + + var tier = resp.Content.Properties[ "tier" ]; + Assert.Equal( ContactPropertyType.String, tier.PropertyType ); + Assert.Equal( "premium", tier.Value.GetString() ); } diff --git a/tools/Resend.ApiServer/Controllers/ContactController.cs b/tools/Resend.ApiServer/Controllers/ContactController.cs index 0d984d3..b5e5e13 100644 --- a/tools/Resend.ApiServer/Controllers/ContactController.cs +++ b/tools/Resend.ApiServer/Controllers/ContactController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Resend.Payloads; +using System.Text.Json; namespace Resend.ApiServer.Controllers; @@ -47,6 +48,10 @@ public Contact ContactRetrieve( [FromRoute] Guid contactId ) LastName = "Test", MomentCreated = DateTime.UtcNow.AddDays( -1 ), IsUnsubscribed = true, + Properties = new Dictionary() + { + { "tier", new ContactPropertyValue() { Value = JsonDocument.Parse( "\"premium\"" ).RootElement, PropertyType = ContactPropertyType.String } }, + }, }; }