Skip to content

Commit 255f705

Browse files
Adding json parsing for Metadata and tags
1 parent 2922a88 commit 255f705

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

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.Name, 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/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 custom header as a name 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 CustomHeaderJson class and sets the name and value pair.
11+
/// </summary>
12+
/// <param name="name">The name of your custom header.</param>
13+
/// <param name="value">The value for your custom header.</param>
14+
public MetadataHeaderJson(string name, string value)
15+
{
16+
Name = name;
17+
Value = value;
18+
}
19+
20+
/// <summary>
21+
/// Gets or sets the custom header name.
22+
/// </summary>
23+
public string Name { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the custom header value.
27+
/// </summary>
28+
public string Value { get; set; }
29+
}
30+
}

0 commit comments

Comments
 (0)