Skip to content

Commit 184e2fd

Browse files
update name/value to key/value for Metadata
1 parent 5beea4c commit 184e2fd

File tree

7 files changed

+110
-44
lines changed

7 files changed

+110
-44
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,22 @@ public SendResponse RunExample()
4747
message.MessageId = "MyMsgId";
4848

4949
message.CustomHeaders.Add("x-mycustomheader", "I am a message header");
50-
50+
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);
5161
message.Metadata.Add("x-mycustommetadata", "I am custom metadata");
62+
message.Metadata.Add(new Metadata("testMessageHeader", "I am metadata"));
5263

5364
message.Tags.Add("Basic-Complex-Example");
65+
message.Tags.Add("c#-Example");
5466

5567
var attachment = message.Attachments.Add("bus.png", MimeType.PNG, @".\examples\img\bus.png");
5668
attachment.ContentId = "Bus";

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

Lines changed: 16 additions & 3 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,11 +42,23 @@ public SendResponse RunExample()
4142
message.From.Set("[email protected]", "FromMe");
4243
message.ReplyTo.Email = "[email protected]";
4344

44-
message.CustomHeaders.Add(new CustomHeader("testMessageHeader", "I am a message header"));
45-
45+
var metadata = new List<IMetadata>()
46+
{
47+
new Metadata("example-type", "basic-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+
4658
message.Metadata.Add("x-mycustommetadata", "I am custom metadata");
4759

4860
message.Tags.Add("Basic-Complex-Example");
61+
message.Tags.Add("c#-Example");
4962

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

src/SocketLabs/InjectionApi/Core/InjectionRequestFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ internal virtual List<MergeFieldJson> PopulateMergeData(IDictionary<string, stri
203203
/// <returns>A <c><![CDATA[ List<MetadataHeaderJson> ]]></c> used in generating an InjectionRequest</returns>
204204
internal virtual List<MetadataHeaderJson> PopulateMetadata(IList<IMetadata> metadata)
205205
{
206-
var result = metadata?.Select(item => new MetadataHeaderJson(item.Name, item.Value));
206+
var result = metadata?.Select(item => new MetadataHeaderJson(item.Key, item.Value));
207207
return result?.ToList();
208208
}
209209

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
namespace SocketLabs.InjectionApi.Core.Serialization
22
{
33
/// <summary>
4-
/// Represents a custom header as a name and value pair.
4+
/// Represents a metadata item as a key and value pair.
55
/// To be serialized into JSON string before sending to the Injection Api.
66
/// </summary>
77
internal class MetadataHeaderJson
88
{
99
/// <summary>
10-
/// Creates a new instance of the CustomHeaderJson class and sets the name and value pair.
10+
/// Creates a new instance of the MetadataHeaderJson class and sets the key and value pair.
1111
/// </summary>
12-
/// <param name="name">The name of your custom header.</param>
12+
/// <param name="key">The key of your custom header.</param>
1313
/// <param name="value">The value for your custom header.</param>
14-
public MetadataHeaderJson(string name, string value)
14+
public MetadataHeaderJson(string key, string value)
1515
{
16-
Name = name;
16+
Key = key;
1717
Value = value;
1818
}
1919

2020
/// <summary>
21-
/// Gets or sets the custom header name.
21+
/// Gets or sets the metadata key.
2222
/// </summary>
23-
public string Name { get; set; }
23+
public string Key { get; set; }
2424

2525
/// <summary>
26-
/// Gets or sets the custom header value.
26+
/// Gets or sets the metadata value.
2727
/// </summary>
2828
public string Value { get; set; }
2929
}

src/SocketLabs/InjectionApi/Message/IMetadata.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22
{
33

44
/// <summary>
5-
/// Represents a metadata header as a name and value pair.
5+
/// Represents a metadata item as a key and value pair.
66
/// </summary>
77
/// <example>
88
/// Using extension methods
99
/// <code>
1010
/// var metadata = new <![CDATA[ List<IMetadata> ]]>();
11-
/// metadata.Add("name1", "value1");
12-
/// metadata.Add("name2", "value2");
11+
/// metadata.Add("key1", "value1");
12+
/// metadata.Add("key2", "value2");
1313
/// </code>
1414
/// </example>
1515
/// <seealso cref="Metadata"/>
1616
/// <seealso cref="SocketLabsExtensions"/>
1717
public interface IMetadata
1818
{
1919
/// <summary>
20-
/// Gets or sets the metadata header name.
20+
/// Gets or sets the metadata key.
2121
/// </summary>
22-
string Name { get; set; }
22+
string Key { get; set; }
2323

2424
/// <summary>
25-
/// Gets or sets the metadata header value.
25+
/// Gets or sets the metadata value.
2626
/// </summary>
2727
string Value { get; set; }
2828

2929
/// <summary>
30-
/// A quick check to ensure that the metadata header is valid.
30+
/// A quick check to ensure that the metadata item is valid.
3131
/// </summary>
3232
bool IsValid { get; }
3333
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
namespace SocketLabs.InjectionApi.Message
22
{
33
/// <summary>
4-
/// Represents a metadata header as a name and value pair.
4+
/// Represents a metadata item as a key and value pair.
55
/// </summary>
66
/// <example>
77
/// Using the constructors
88
/// <code>
99
/// var metadata1 = new Metadata();
10-
/// metadata1.Name = "name1";
10+
/// metadata1.Key = "key1";
1111
/// metadata1.Value = "value1";
1212
///
13-
/// var metadata2 = new Metadata("name1", "value1");
13+
/// var metadata2 = new Metadata("key1", "value1");
1414
/// </code>
1515
/// Using extension methods
1616
/// <code>
1717
/// var metadata = new <![CDATA[ List<IMetadata> ]]>();
18-
/// metadata.Add("name1", "value1");
19-
/// metadata.Add("name2", "value2");
18+
/// metadata.Add("key1", "value1");
19+
/// metadata.Add("key2", "value2");
2020
/// </code>
2121
/// </example>
2222
/// <seealso cref="IMetadata"/>
@@ -29,7 +29,7 @@ public class Metadata : IMetadata
2929
/// <example>
3030
/// <code>
3131
/// var metadata = new Metadata();
32-
/// metadata.Name = "name1";
32+
/// metadata.Name = "key1";
3333
/// metadata.Value = "value1";
3434
/// </code>
3535
/// </example>
@@ -38,41 +38,41 @@ public Metadata() { }
3838
/// <summary>
3939
/// Creates a new instance of the Metadata class and sets the name and value pair.
4040
/// </summary>
41-
/// <param name="name">The name of your metadata header.</param>
41+
/// <param name="key">The name of your metadata header.</param>
4242
/// <param name="value">The value for your metadata header.</param>
4343
/// <example>
4444
/// <code>
4545
/// var metadata = new Metadata("name1", "value1");
4646
/// </code>
4747
/// </example>
48-
public Metadata(string name, string value)
48+
public Metadata(string key, string value)
4949
{
50-
Name = name;
50+
Key = key;
5151
Value = value;
5252
}
5353

5454
/// <summary>
55-
/// Gets or sets the metadata header name.
55+
/// Gets or sets the metadata key.
5656
/// </summary>
57-
public string Name { get; set; }
57+
public string Key { get; set; }
5858

5959
/// <summary>
60-
/// Gets or sets the metadata header value.
60+
/// Gets or sets the metadata value.
6161
/// </summary>
6262
public string Value { get; set; }
6363

6464
/// <summary>
65-
/// A quick check to ensure that the metadata header is valid.
65+
/// A quick check to ensure that the metadata entry is valid.
6666
/// </summary>
67-
public bool IsValid => !(string.IsNullOrEmpty(Value) || string.IsNullOrEmpty(Name));
67+
public bool IsValid => !(string.IsNullOrEmpty(Value) || string.IsNullOrEmpty(Key));
6868

6969
/// <summary>
70-
/// Returns the metadata header as a name-value pair, useful for debugging.
70+
/// Returns the metadata header as a key-value pair, useful for debugging.
7171
/// </summary>
7272
/// <returns></returns>
7373
public override string ToString()
7474
{
75-
return $"{Name ?? "null"}: {Value ?? "null"}";
75+
return $"{Key ?? "null"}: {Value ?? "null"}";
7676
}
7777
}
7878
}

src/SocketLabs/InjectionApi/SocketLabsExtensions.cs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.IO;
33
using System.Threading.Tasks;
4+
using Newtonsoft.Json.Linq;
45
using SocketLabs.InjectionApi.Message;
56

67
namespace SocketLabs.InjectionApi
@@ -402,26 +403,66 @@ public static ICustomHeader Add(this IList<ICustomHeader> source, string name, s
402403
#region List of Metadata
403404

404405
/// <summary>
405-
/// Adds a new metadata header to an existing list of metadata headers.
406+
/// Adds a new metadata item to an existing list of metadata items.
406407
/// </summary>
407-
/// <param name="source">The existing list of metadata headers.</param>
408-
/// <param name="name">The name of the new metadata header.</param>
409-
/// <param name="value">The value for the new metadata header.</param>
408+
/// <param name="source">The existing list of metadata item.</param>
409+
/// <param name="key">The key of the new metadata item.</param>
410+
/// <param name="value">The value for the new metadata item.</param>
410411
/// <returns>Instance of <see cref="IMetadata"/></returns>
411412
/// <example>
412413
/// <code>
413414
/// var metadata = new <![CDATA[ List<IMetadata> ]]>();
414-
/// metadata.Add("name1", "value1");
415-
/// metadata.Add("name2", "value2");
415+
/// metadata.Add("key1", "value1");
416+
/// metadata.Add("key2", "value2");
416417
/// </code>
417418
/// </example>
418-
public static IMetadata Add(this IList<IMetadata> source, string name, string value)
419+
public static IMetadata Add(this IList<IMetadata> source, string key, string value)
419420
{
420-
var metadata = new Metadata(name, value);
421+
var metadata = new Metadata(key, value);
421422
source.Add(metadata);
422423
return metadata;
423424
}
424425

426+
/// <summary>
427+
/// Adds a new metadata item to an existing list of metadata items.
428+
/// </summary>
429+
/// <param name="source">The existing list of metadata item.</param>
430+
/// <param name="list">The list of new metadata items to add.</param>
431+
/// <returns>Instance of <see cref="IMetadata"/></returns>
432+
/// <example>
433+
/// <code>
434+
/// var metadata = new <![CDATA[ List<IMetadata> ]]>();
435+
/// metadata.Add("key1", "value1");
436+
/// metadata.Add("key2", "value2");
437+
/// </code>
438+
/// </example>
439+
public static IList<IMetadata> Add(this IList<IMetadata> source, List<IMetadata> list)
440+
{
441+
foreach (var metadata in list)
442+
{
443+
source.Add(metadata);
444+
}
445+
return list;
446+
}
447+
448+
/// <summary>
449+
/// Adds a new metadata item to an existing list of metadata items.
450+
/// </summary>
451+
/// <param name="source">The existing list of metadata item.</param>
452+
/// <param name="item">A new metadata items to add.</param>
453+
/// <returns>Instance of <see cref="IMetadata"/></returns>
454+
/// <example>
455+
/// <code>
456+
/// var metadata = new <![CDATA[ List<IMetadata> ]]>();
457+
/// metadata.Add("key1", "value1");
458+
/// metadata.Add("key2", "value2");
459+
/// </code>
460+
/// </example>
461+
public static IMetadata Add(this IList<IMetadata> source, IMetadata item)
462+
{
463+
source.Add(item);
464+
return item;
465+
}
425466
#endregion
426467
}
427468
}

0 commit comments

Comments
 (0)