Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Resend/Contact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ public class Contact
/// </summary>
[JsonPropertyName( "properties" )]
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
public Dictionary<string,string>? Properties { get; set; }
public Dictionary<string, ContactPropertyValue>? Properties { get; set; }
}
6 changes: 6 additions & 0 deletions src/Resend/ContactPropertyType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ public enum ContactPropertyType
/// </summary>
[JsonStringValue( "number" )]
Number,

/// <summary>
/// Boolean.
/// </summary>
[JsonStringValue( "boolean" )]
Boolean,
}
22 changes: 22 additions & 0 deletions src/Resend/ContactPropertyValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Resend;

/// <summary>
/// Custom property value on a contact.
/// </summary>
public class ContactPropertyValue
{
/// <summary>
/// Property value; a string, number, or boolean, depending on <see cref="PropertyType"/>.
/// </summary>
[JsonPropertyName( "value" )]
public JsonElement Value { get; set; }

/// <summary>
/// Property data-type.
/// </summary>
[JsonPropertyName( "type" )]
public ContactPropertyType PropertyType { get; set; }
}
6 changes: 6 additions & 0 deletions tests/Resend.Tests/ResendClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
锘縰sing Microsoft.AspNetCore.Mvc.Testing;
using Resend.ApiServer;
using System.Net;
using System.Text.Json;

namespace Resend.Tests;

Expand Down Expand Up @@ -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() );
}


Expand Down
5 changes: 5 additions & 0 deletions tools/Resend.ApiServer/Controllers/ContactController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Resend.Payloads;
using System.Text.Json;

namespace Resend.ApiServer.Controllers;

Expand Down Expand Up @@ -47,6 +48,10 @@ public Contact ContactRetrieve( [FromRoute] Guid contactId )
LastName = "Test",
MomentCreated = DateTime.UtcNow.AddDays( -1 ),
IsUnsubscribed = true,
Properties = new Dictionary<string, ContactPropertyValue>()
{
{ "tier", new ContactPropertyValue() { Value = JsonDocument.Parse( "\"premium\"" ).RootElement, PropertyType = ContactPropertyType.String } },
},
};
}

Expand Down
Loading