Skip to content

Commit c354600

Browse files
Adding Metadata and Tags to Message
1 parent d04944a commit c354600

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed

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>

src/SocketLabs/InjectionApi/Message/BulkMessage.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,22 @@ public class BulkMessage : IBulkMessage
167167
/// </remarks>
168168
public IList<ICustomHeader> CustomHeaders { get; set; } = new List<ICustomHeader>();
169169

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

src/SocketLabs/InjectionApi/Message/IMessageBase.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,22 @@ public interface IMessageBase
108108
/// (Optional)
109109
/// </remarks>
110110
IList<ICustomHeader> CustomHeaders { get; set; }
111+
112+
113+
/// <summary>
114+
/// A list of metadata headers added to the message.
115+
/// </summary>
116+
/// <remarks>
117+
/// (Optional)
118+
/// </remarks>
119+
IList<IMetadata> Metadata { get; set; }
120+
121+
/// <summary>
122+
/// A list of tag headers added to the message.
123+
/// </summary>
124+
/// <remarks>
125+
/// (Optional)
126+
/// </remarks>
127+
IList<string> Tags { get; set; }
111128
}
112129
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace SocketLabs.InjectionApi.Message
2+
{
3+
4+
/// <summary>
5+
/// Represents a metadata header as a name and value pair.
6+
/// </summary>
7+
/// <example>
8+
/// Using extension methods
9+
/// <code>
10+
/// var metadata = new <![CDATA[ List<IMetadata> ]]>();
11+
/// metadata.Add("name1", "value1");
12+
/// metadata.Add("name2", "value2");
13+
/// </code>
14+
/// </example>
15+
/// <seealso cref="Metadata"/>
16+
/// <seealso cref="SocketLabsExtensions"/>
17+
public interface IMetadata
18+
{
19+
/// <summary>
20+
/// Gets or sets the metadata header name.
21+
/// </summary>
22+
string Name { get; set; }
23+
24+
/// <summary>
25+
/// Gets or sets the metadata header value.
26+
/// </summary>
27+
string Value { get; set; }
28+
29+
/// <summary>
30+
/// A quick check to ensure that the metadata header is valid.
31+
/// </summary>
32+
bool IsValid { get; }
33+
}
34+
35+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
namespace SocketLabs.InjectionApi.Message
2+
{
3+
/// <summary>
4+
/// Represents a metadata header as a name and value pair.
5+
/// </summary>
6+
/// <example>
7+
/// Using the constructors
8+
/// <code>
9+
/// var metadata1 = new Metadata();
10+
/// metadata1.Name = "name1";
11+
/// metadata1.Value = "value1";
12+
///
13+
/// var metadata2 = new Metadata("name1", "value1");
14+
/// </code>
15+
/// Using extension methods
16+
/// <code>
17+
/// var metadata = new <![CDATA[ List<IMetadata> ]]>();
18+
/// metadata.Add("name1", "value1");
19+
/// metadata.Add("name2", "value2");
20+
/// </code>
21+
/// </example>
22+
/// <seealso cref="IMetadata"/>
23+
/// <seealso cref="SocketLabsExtensions"/>
24+
public class Metadata : IMetadata
25+
{
26+
/// <summary>
27+
/// Creates a new instance of the Metadata class.
28+
/// </summary>
29+
/// <example>
30+
/// <code>
31+
/// var metadata = new Metadata();
32+
/// metadata.Name = "name1";
33+
/// metadata.Value = "value1";
34+
/// </code>
35+
/// </example>
36+
public Metadata() { }
37+
38+
/// <summary>
39+
/// Creates a new instance of the Metadata class and sets the name and value pair.
40+
/// </summary>
41+
/// <param name="name">The name of your metadata header.</param>
42+
/// <param name="value">The value for your metadata header.</param>
43+
/// <example>
44+
/// <code>
45+
/// var metadata = new Metadata("name1", "value1");
46+
/// </code>
47+
/// </example>
48+
public Metadata(string name, string value)
49+
{
50+
Name = name;
51+
Value = value;
52+
}
53+
54+
/// <summary>
55+
/// Gets or sets the metadata header name.
56+
/// </summary>
57+
public string Name { get; set; }
58+
59+
/// <summary>
60+
/// Gets or sets the metadata header value.
61+
/// </summary>
62+
public string Value { get; set; }
63+
64+
/// <summary>
65+
/// A quick check to ensure that the metadata header is valid.
66+
/// </summary>
67+
public bool IsValid => !(string.IsNullOrEmpty(Value) || string.IsNullOrEmpty(Name));
68+
69+
/// <summary>
70+
/// Returns the metadata header as a name-value pair, useful for debugging.
71+
/// </summary>
72+
/// <returns></returns>
73+
public override string ToString()
74+
{
75+
return $"{Name ?? "null"}: {Value ?? "null"}";
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)