Skip to content

Commit 5729214

Browse files
Merge pull request #37 from socketlabs/feature/metadata-tags
Feature/metadata tags
2 parents 2a5561f + a5c78c3 commit 5729214

File tree

19 files changed

+461
-14
lines changed

19 files changed

+461
-14
lines changed

Example Projects/dotNetCoreExample/Examples/Basic/BasicComplexExample.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ public SendResponse RunExample()
4848

4949
message.CustomHeaders.Add("x-mycustomheader", "I am a message header");
5050

51+
var metadata = new List<IMetadata>()
52+
{
53+
new Metadata("example-type", "basic-send-complex"),
54+
new Metadata()
55+
{
56+
Key = "message-contains",
57+
Value = "attachments, headers"
58+
}
59+
};
60+
message.Metadata.Add(metadata);
61+
message.Metadata.Add("x-mycustommetadata", "I am custom metadata");
62+
message.Metadata.Add(new Metadata("testMessageHeader", "I am metadata"));
63+
64+
message.Tags.Add("Basic-Complex-Example");
65+
message.Tags.Add("c#-Example");
66+
5167
var attachment = message.Attachments.Add("bus.png", MimeType.PNG, @".\examples\img\bus.png");
5268
attachment.ContentId = "Bus";
5369

Example Projects/dotNetCoreExample/Examples/Bulk/BulkSendComplexExample.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text;
1+
using System.Collections.Generic;
2+
using System.Text;
23
using System.Text.RegularExpressions;
34
using SocketLabs.InjectionApi;
45
using SocketLabs.InjectionApi.Message;
@@ -41,7 +42,23 @@ public SendResponse RunExample()
4142
message.From.Set("from@example.com", "FromMe");
4243
message.ReplyTo.Email = "replyto@example.com";
4344

44-
message.CustomHeaders.Add(new CustomHeader("testMessageHeader", "I am a message header"));
45+
var metadata = new List<IMetadata>()
46+
{
47+
new Metadata("example-type", "bulk-send-complex"),
48+
new Metadata()
49+
{
50+
Key = "message-contains",
51+
Value = "attachments, headers"
52+
}
53+
};
54+
message.Metadata.Add(metadata);
55+
message.Metadata.Add("x-mycustommetadata", "I am custom metadata");
56+
message.Metadata.Add(new Metadata("testMessageHeader", "I am metadata"));
57+
58+
message.Metadata.Add("x-mycustommetadata", "I am custom metadata");
59+
60+
message.Tags.Add("Bulk-Complex-Example");
61+
message.Tags.Add("c#-Example");
4562

4663
// Build the Content (Note the %% symbols used to denote the data to be merged)
4764
var html = new StringBuilder();

Example Projects/dotNetCoreExample/dotNetCoreExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
6-
<Copyright>Copyright © 2018-2022 SocketLabs Acquisition LLC</Copyright>
6+
<Copyright>Copyright © 2018-2023 SocketLabs Acquisition LLC</Copyright>
77
</PropertyGroup>
88

99
<ItemGroup>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ PM> Install-Package SocketLabs.EmailDelivery
3636
Adding a Package Reference to your project:
3737

3838
```
39-
<PackageReference Include="SocketLabs.EmailDelivery" Version="1.2.3" />
39+
<PackageReference Include="SocketLabs.EmailDelivery" Version="1.4.0" />
4040
```
4141

4242
.NET CLI users can also use the following command:

docs/release-notes/latest.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
## 1.3.4
22
* Bump Castle.Core from 5.0.0 to 5.1.0
3-
* Bump Moq from 4.18.1 to 4.18.2
3+
* Bump Moq from 4.18.1 to 4.18.2
4+
5+
## 1.4.0
6+
* Adding Metadata and Tags
7+
* Bump coverlet.collector from 3.1.2 to 3.2.0
8+
* Bump Newtonsoft.Json from 13.0.1 to 13.0.2
9+
* Bump Microsoft.NET.Test.Sdk from 17.2.0 to 17.4.1
10+
* Bump MSTest.TestFramework from 2.2.10 to 3.0.2
11+
* Bump Moq from 4.18.2 to 4.18.4

src/SocketLabs/InjectionApi/Core/InjectionRequestFactory.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ internal virtual MessageJson GenerateBaseMessageJson(IMessageBase message)
9292
CharSet = message.CharSet,
9393
CustomHeaders = PopulateCustomHeaders(message.CustomHeaders),
9494
From = new AddressJson(message.From.Email, message.From.FriendlyName),
95-
Attachments = PopulateList(message.Attachments)
95+
Attachments = PopulateList(message.Attachments),
96+
Metadata = PopulateMetadata(message.Metadata),
97+
Tags = PopulateTags(message.Tags)
9698
};
9799

98100
if (message.ReplyTo != null)
@@ -192,5 +194,28 @@ internal virtual List<MergeFieldJson> PopulateMergeData(IDictionary<string, stri
192194
var result = mergeData?.Select(item => new MergeFieldJson(item.Key, item.Value));
193195
return result?.ToList();
194196
}
197+
198+
199+
/// <summary>
200+
/// Converting a <c><![CDATA[ IList<IMetadata> ]]></c> to a <c><![CDATA[ List<MetadataHeaderJson> ]]></c>
201+
/// </summary>
202+
/// <param name="metadata">A <c><![CDATA[ IList<IMetadata> ]]></c> from the message</param>
203+
/// <returns>A <c><![CDATA[ List<MetadataHeaderJson> ]]></c> used in generating an InjectionRequest</returns>
204+
internal virtual List<MetadataHeaderJson> PopulateMetadata(IList<IMetadata> metadata)
205+
{
206+
var result = metadata?.Select(item => new MetadataHeaderJson(item.Key, item.Value));
207+
return result?.ToList();
208+
}
209+
210+
/// <summary>
211+
/// Converting a <c><![CDATA[ IList<ICustomHeader> ]]></c> to a <c><![CDATA[ List<CustomHeadersJson> ]]></c>
212+
/// </summary>
213+
/// <param name="tags">A <c><![CDATA[ IList<ICustomHeader> ]]></c> from the message</param>
214+
/// <returns>A <c><![CDATA[ List<CustomHeadersJson> ]]></c> used in generating an InjectionRequest</returns>
215+
internal virtual List<string> PopulateTags(IList<string> tags)
216+
{
217+
var result = tags.ToList();
218+
return result?.ToList();
219+
}
195220
}
196221
}

src/SocketLabs/InjectionApi/Core/SendValidator.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ internal virtual SendResult ValidateIMessageBase(IMessageBase message)
7878
if (message.CustomHeaders != null && message.CustomHeaders.Any())
7979
if (!HasValidCustomHeaders(message.CustomHeaders)) return SendResult.MessageValidationInvalidCustomHeaders;
8080

81+
if (message.Metadata != null && message.Metadata.Any())
82+
if (!HasValidMetadata(message.Metadata)) return SendResult.MessageValidationInvalidMetadata;
83+
8184
return SendResult.Success;
8285
}
8386

@@ -334,5 +337,16 @@ internal virtual bool HasValidCustomHeaders(IList<ICustomHeader> customHeaders)
334337
var result = customHeaders?.Where(item => !item.IsValid);
335338
return result == null || !result.Any();
336339
}
340+
341+
/// <summary>
342+
/// Check if <c>IMetadata</c> in List are valid
343+
/// </summary>
344+
/// <param name="metadata"><c><![CDATA[ IList<IMetadata> ]]></c> to validate</param>
345+
/// <returns><c>bool</c> result</returns>
346+
internal virtual bool HasValidMetadata(IList<IMetadata> metadata)
347+
{
348+
var result = metadata?.Where(item => !item.IsValid);
349+
return result == null || !result.Any();
350+
}
337351
}
338352
}

src/SocketLabs/InjectionApi/Core/Serialization/MessageJson.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public MessageJson()
1919
Bcc = new List<AddressJson>();
2020
MergeData = new MergeDataJson();
2121
Attachments = new List<AttachmentJson>();
22+
Metadata = new List<MetadataHeaderJson>();
23+
Tags = new List<string>();
2224
}
2325

2426
/// <summary>
@@ -101,6 +103,16 @@ public MessageJson()
101103
/// Gets or sets the list of merge data.
102104
/// </summary>
103105
public MergeDataJson MergeData { get; set; }
106+
107+
/// <summary>
108+
/// A list of metadata headers added to the message.
109+
/// </summary>
110+
public List<MetadataHeaderJson> Metadata { get; set; }
111+
112+
/// <summary>
113+
/// A list of tag headers added to the message.
114+
/// </summary>
115+
public List<string> Tags { get; set; }
104116

105117
#region Conditional Property Serialization
106118

@@ -170,5 +182,6 @@ public bool ShouldSerializeAttachment()
170182
}
171183

172184
#endregion
185+
173186
}
174187
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace SocketLabs.InjectionApi.Core.Serialization
2+
{
3+
/// <summary>
4+
/// Represents a metadata item as a key and value pair.
5+
/// To be serialized into JSON string before sending to the Injection Api.
6+
/// </summary>
7+
internal class MetadataHeaderJson
8+
{
9+
/// <summary>
10+
/// Creates a new instance of the MetadataHeaderJson class and sets the key and value pair.
11+
/// </summary>
12+
/// <param name="key">The key of your custom header.</param>
13+
/// <param name="value">The value for your custom header.</param>
14+
public MetadataHeaderJson(string key, string value)
15+
{
16+
Key = key;
17+
Value = value;
18+
}
19+
20+
/// <summary>
21+
/// Gets or sets the metadata key.
22+
/// </summary>
23+
public string Key { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the metadata value.
27+
/// </summary>
28+
public string Value { get; set; }
29+
}
30+
}

src/SocketLabs/InjectionApi/Message/BasicMessage.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ public class BasicMessage : IBasicMessage
170170
/// </remarks>
171171
public IList<ICustomHeader> CustomHeaders { get; set; } = new List<ICustomHeader>();
172172

173+
/// <summary>
174+
/// A list of metadata headers added to the message.
175+
/// </summary>
176+
/// <remarks>
177+
/// (Optional)
178+
/// </remarks>
179+
public IList<IMetadata> Metadata { get; set; } = new List<IMetadata>();
180+
181+
/// <summary>
182+
/// A list of tag headers added to the message.
183+
/// </summary>
184+
/// <remarks>
185+
/// (Optional)
186+
/// </remarks>
187+
public IList<string> Tags { get; set; } = new List<string>();
188+
173189
/// <summary>
174190
/// Returns the number of recipients and subject for the message, useful for debugging.
175191
/// </summary>

0 commit comments

Comments
 (0)