Skip to content

Commit

Permalink
Merge pull request #141 from ActiveCampaign/unsubscribe-handling
Browse files Browse the repository at this point in the history
Add SubscriptionManagementConfiguration to PostmarkMessageStream
  • Loading branch information
MariuszTrybus authored Aug 8, 2024
2 parents 19fbb04 + 8336e1e commit a53dc11
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Postmark/Model/MessageStreams/PostmarkMessageStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ public class PostmarkMessageStream
/// The date when this message stream has been archived. If null, this message stream is not in an archival state.
/// </summary>
public DateTime? ArchivedAt { get; set; }

/// <summary>
/// Subscription management options for the Stream.
/// </summary>
public PostmarkSubscriptionManagementConfiguration SubscriptionManagementConfiguration { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Postmark.Model.MessageStreams
{
public class PostmarkSubscriptionManagementConfiguration
{
/// <summary>
/// The unsubscribe management option used for the Stream. Broadcast Message Streams require unsubscribe management, Postmark is default. For Inbound and Transactional Streams default is none.
/// </summary>
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter<UnsubscribeHandlingType>))]
public UnsubscribeHandlingType UnsubscribeHandlingType { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/Postmark/Model/MessageStreams/UnsubscribeHandlingType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Postmark.Model.MessageStreams
{
public enum UnsubscribeHandlingType
{
None,
Custom,
Postmark,
}
}
22 changes: 20 additions & 2 deletions src/Postmark/PostmarkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,9 @@ public async Task<PostmarkBulkReactivationResult> DeleteSuppressions(IEnumerable
/// <param name="type">Type of the message stream. E.g.: Transactional or Broadcasts.</param>
/// <param name="name">Friendly name for your message stream.</param>
/// <param name="description">Friendly description for your message stream. (optional)</param>
/// <param name="unsubscriptionHandlingType">The unsubscribe management option for the stream. (optional)</param>
/// <remarks>Currently, you cannot create multiple inbound streams.</remarks>
public async Task<PostmarkMessageStream> CreateMessageStream(string id, MessageStreamType type, string name, string description = null)
public async Task<PostmarkMessageStream> CreateMessageStream(string id, MessageStreamType type, string name, string description = null, UnsubscribeHandlingType? unsubscriptionHandlingType = null)
{
var body = new Dictionary<string, object>
{
Expand All @@ -1139,6 +1140,14 @@ public async Task<PostmarkMessageStream> CreateMessageStream(string id, MessageS
["MessageStreamType"] = type.ToString()
};

if (unsubscriptionHandlingType.HasValue)
{
body["SubscriptionManagementConfiguration"] = new Dictionary<string, object>
{
["UnsubscribeHandlingType"] = unsubscriptionHandlingType.ToString()
};
}

var apiUrl = "/message-streams/";

return await ProcessRequestAsync<Dictionary<string, object>, PostmarkMessageStream>(apiUrl, HttpMethod.Post, body);
Expand All @@ -1150,14 +1159,23 @@ public async Task<PostmarkMessageStream> CreateMessageStream(string id, MessageS
/// <param name="id">The identifier for the stream you are trying to update.</param>
/// <param name="name">New friendly name to use. (optional)</param>
/// <param name="description">New description to use. (optional)</param>
public async Task<PostmarkMessageStream> EditMessageStream(string id, string name = null, string description = null)
/// <param name="unsubscriptionHandlingType">New unsubscribe management option for the stream. (optional)</param>
public async Task<PostmarkMessageStream> EditMessageStream(string id, string name = null, string description = null, UnsubscribeHandlingType? unsubscriptionHandlingType = null)
{
var body = new Dictionary<string, object>
{
["Name"] = name,
["Description"] = description
};

if (unsubscriptionHandlingType.HasValue)
{
body["SubscriptionManagementConfiguration"] = new Dictionary<string, object>
{
["UnsubscribeHandlingType"] = unsubscriptionHandlingType.ToString()
};
}

var apiUrl = $"/message-streams/{id}";

return await ProcessRequestAsync<Dictionary<string, object>, PostmarkMessageStream>(apiUrl, new HttpMethod("PATCH"), body);
Expand Down

0 comments on commit a53dc11

Please sign in to comment.