Skip to content

Commit a15e382

Browse files
authored
Merge pull request #55 from socketlabs/usr/matt.soler/threading-issue
Usr/matt.soler/threading issue
2 parents 9509dfd + ea20383 commit a15e382

34 files changed

+277
-234
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ public SendResponse RunExample()
5151
var metadata = new List<IMetadata>()
5252
{
5353
new Metadata("example-type", "basic-send-complex"),
54-
new Metadata()
55-
{
56-
Key = "message-contains",
57-
Value = "attachments, headers"
58-
}
54+
new Metadata("message-contains","attachments, headers")
5955
};
6056
message.Metadata.Add(metadata);
6157
message.Metadata.Add("x-mycustommetadata", "I am custom metadata");

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ public SendResponse RunExample()
4545
var metadata = new List<IMetadata>()
4646
{
4747
new Metadata("example-type", "bulk-send-complex"),
48-
new Metadata()
49-
{
50-
Key = "message-contains",
51-
Value = "attachments, headers"
52-
}
48+
new Metadata("message-contains","attachments, headers")
5349
};
5450
message.Metadata.Add(metadata);
5551
message.Metadata.Add("x-mycustommetadata", "I am custom metadata");

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ The SocketLabs Email Delivery C# library allows you to easily send email message
2121
# Prerequisites and Installation
2222
## Prerequisites
2323
* A supported .NET version
24-
* .NET version 4.5 or higher
25-
* .NET Core 1.0 or higher
26-
* .NET Standard 1.3 or higher
24+
* .NET Framework version 4.8 or higher
25+
* .NET 8.0 or higher
26+
* .NET Standard 2.0 or higher
2727
* A SocketLabs account. If you don't have one yet, you can [sign up for a free account](https://signup.socketlabs.com/step-1?plan=free) to get started.
2828

2929
## Installation
@@ -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.4.3" />
39+
<PackageReference Include="SocketLabs.EmailDelivery" Version="2.0.0" />
4040
```
4141

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

docs/release-notes/2.0.0.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## 2.0.0
2+
3+
* Fix issue with ApiKey being unset for bearer type keys
4+
* Add explicit support for .NET 8.0 and .NET 9.0
5+
* Update dependencies
6+
* Implement nullable pattern
7+
8+
```note
9+
This is a breaking change. Some objects require constructor initialization now.
10+
```

src/SocketLabs/InjectionApi/AddressResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class AddressResult
88
/// <summary>
99
/// The recipient's email address.
1010
/// </summary>
11-
public string EmailAddress { get; set; }
11+
public string? EmailAddress { get; set; }
1212

1313
/// <summary>
1414
/// Whether the recipient was accepted for delivery.
@@ -18,7 +18,7 @@ public class AddressResult
1818
/// <summary>
1919
/// An error code detailing why the recipient was not accepted.
2020
/// </summary>
21-
public string ErrorCode { get; set; }
21+
public string? ErrorCode { get; set; }
2222

2323
/// <summary>
2424
/// Represents the <c>AddressResult</c> as a string. Useful for debugging.

src/SocketLabs/InjectionApi/Core/ApiKeyParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace SocketLabs.InjectionApi.Core
55
/// <summary>
66
/// Parses a provided api key and provides a result
77
/// </summary>
8-
public class ApiKeyParser : IApiKeyParser
8+
internal class ApiKeyParser : IApiKeyParser
99
{
1010
/// <summary>
1111
/// Parses the provided Api key.

src/SocketLabs/InjectionApi/Core/IApiKeyParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace SocketLabs.InjectionApi.Core
44
{
5-
public interface IApiKeyParser
5+
internal interface IApiKeyParser
66
{
77
ApiKeyParseResult Parse(string wholeApiKey);
88
}

src/SocketLabs/InjectionApi/Core/InjectionRequestFactory.cs

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ namespace SocketLabs.InjectionApi.Core
1212
internal class InjectionRequestFactory : IInjectionRequestFactory
1313
{
1414
private readonly int _serverId;
15-
private readonly string _apiKey;
15+
private readonly string? _apiKey;
1616

1717
/// <summary>
1818
/// Creates a new instance of the <c>InjectionRequestFactory</c>.
1919
/// </summary>
2020
/// <param name="serverId">Your SocketLabs ServerId number.</param>
21-
/// <param name="apiKey">Your SocketLabs Injection API key.</param>
22-
public InjectionRequestFactory(int serverId, string apiKey)
21+
/// <param name="apiKey">Your SocketLabs Injection API key. Set to null if using Bearer token.</param>
22+
public InjectionRequestFactory(int serverId, string? apiKey)
2323
{
2424
_serverId = serverId;
2525
_apiKey = apiKey;
@@ -41,7 +41,7 @@ public InjectionRequest GenerateRequest(IBasicMessage message)
4141

4242
request.Messages.Add(jsonMsg);
4343

44-
if (message.ReplyTo != null)
44+
if (message.ReplyTo?.Email is not null)
4545
jsonMsg.ReplyTo = new AddressJson(message.ReplyTo.Email, message.ReplyTo.FriendlyName);
4646

4747
return request;
@@ -63,10 +63,13 @@ public InjectionRequest GenerateRequest(IBulkMessage message)
6363

6464
// handle merge data per recipient for message
6565
var mergeDataForEmail = GetBulkMergeFields(message.To);
66-
jsonMsg.MergeData.PerMessage = mergeDataForEmail;
66+
jsonMsg.MergeData = new()
67+
{
68+
PerMessage = mergeDataForEmail,
6769

68-
// handle global (per message) merge data
69-
jsonMsg.MergeData.Global = PopulateMergeData(message.GlobalMergeData);
70+
// handle global (per message) merge data
71+
Global = PopulateMergeData(message.GlobalMergeData)
72+
};
7073

7174
request.Messages.Add(jsonMsg);
7275

@@ -90,18 +93,19 @@ internal virtual MessageJson GenerateBaseMessageJson(IMessageBase message)
9093
MailingId = message.MailingId,
9194
MessageId = message.MessageId,
9295
CharSet = message.CharSet,
93-
CustomHeaders = PopulateCustomHeaders(message.CustomHeaders),
94-
From = new AddressJson(message.From.Email, message.From.FriendlyName),
96+
CustomHeaders = PopulateCustomHeaders(message.CustomHeaders),
9597
Attachments = PopulateList(message.Attachments),
9698
Metadata = PopulateMetadata(message.Metadata),
9799
Tags = PopulateTags(message.Tags)
98100
};
101+
if (message.From?.Email is not null)
102+
jsonMsg.From = new AddressJson(message.From.Email, message.From.FriendlyName);
99103

100-
if (message.ReplyTo != null)
104+
if (message.ReplyTo?.Email is not null)
101105
jsonMsg.ReplyTo = new AddressJson(message.ReplyTo.Email, message.ReplyTo.FriendlyName);
102106

103107
if (message.ApiTemplate.HasValue)
104-
jsonMsg.ApiTemplate = message.ApiTemplate.ToString();
108+
jsonMsg.ApiTemplate = message.ApiTemplate?.ToString();
105109

106110
return jsonMsg;
107111
}
@@ -113,9 +117,6 @@ internal virtual MessageJson GenerateBaseMessageJson(IMessageBase message)
113117
/// <returns>A <c><![CDATA[ List<AttachmentJson> ]]></c> used in generating an InjectionRequest</returns>
114118
internal virtual List<AttachmentJson> PopulateList(IEnumerable<IAttachment> attachments)
115119
{
116-
if (attachments == null)
117-
return null;
118-
119120
var results = new List<AttachmentJson>();
120121

121122
foreach (var attachment in attachments)
@@ -140,8 +141,8 @@ internal virtual List<AttachmentJson> PopulateList(IEnumerable<IAttachment> atta
140141
/// <returns>A <c><![CDATA[ List<CustomHeadersJson> ]]></c> used in generating an InjectionRequest</returns>
141142
internal virtual List<CustomHeadersJson> PopulateCustomHeaders(IList<ICustomHeader> customHeaders)
142143
{
143-
var result = customHeaders?.Select(item => new CustomHeadersJson(item.Name, item.Value));
144-
return result?.ToList();
144+
var result = customHeaders.Select(item => new CustomHeadersJson(item.Name, item.Value));
145+
return result.ToList();
145146
}
146147

147148
/// <summary>
@@ -151,33 +152,37 @@ internal virtual List<CustomHeadersJson> PopulateCustomHeaders(IList<ICustomHead
151152
/// <returns>A <c><![CDATA[ List<AddressJson> ]]></c> used in generating an InjectionRequest</returns>
152153
internal virtual List<AddressJson> PopulateList(IEnumerable<IEmailAddress> recipients)
153154
{
154-
var result = recipients?.Select(item => new AddressJson(item.Email, item.FriendlyName));
155-
return result?.ToList();
155+
var result = recipients.Where(x => x.Email is not null)
156+
.Select(item => new AddressJson(item.Email!, item.FriendlyName));
157+
158+
return result.ToList();
156159
}
157160

158161
/// <summary>
159162
/// Converting a <c><![CDATA[ IEnumerable<IBulkRecipient> ]]></c> to a <c><![CDATA[ List<List<MergeFieldJson>> ]]></c>
160163
/// </summary>
161164
/// <param name="recipients">A <c><![CDATA[ IEnumerable<IBulkRecipient> ]]></c> from the message</param>
162165
/// <returns>A <c><![CDATA[ List<List<MergeFieldJson>> ]]></c> used in generating an InjectionRequest</returns>
163-
internal virtual List<List<MergeFieldJson>> GetBulkMergeFields(IEnumerable<IBulkRecipient> recipients)
166+
internal virtual List<List<MergeFieldJson>> GetBulkMergeFields(IEnumerable<IBulkRecipient>? recipients)
164167
{
165168
var result = new List<List<MergeFieldJson>>();
166-
167-
//each recipient get's their own list of merge fields
168-
foreach (var recipient in recipients)
169+
if (recipients is not null)
169170
{
170-
// Get any merge data associated with the Recipients and put it in the MergeData section
171-
var recipientMergeFields = recipient.MergeData?.Select(mergeField => new MergeFieldJson(mergeField.Key, mergeField.Value)).ToList() ??
172-
new List<MergeFieldJson>();
171+
//each recipient get's their own list of merge fields
172+
foreach (var recipient in recipients)
173+
{
174+
// Get any merge data associated with the Recipients and put it in the MergeData section
175+
var recipientMergeFields = recipient.MergeData?.Select(mergeField => new MergeFieldJson(mergeField.Key, mergeField.Value)).ToList() ??
176+
new List<MergeFieldJson>();
173177

174-
recipientMergeFields.Add(new MergeFieldJson("DeliveryAddress", recipient.Email));
178+
recipientMergeFields.Add(new MergeFieldJson("DeliveryAddress", recipient.Email));
175179

176-
//don't include friendly name if it hasn't been provided
177-
if (!string.IsNullOrWhiteSpace(recipient.FriendlyName))
178-
recipientMergeFields.Add(new MergeFieldJson("RecipientName", recipient.FriendlyName));
180+
//don't include friendly name if it hasn't been provided
181+
if (!string.IsNullOrWhiteSpace(recipient.FriendlyName))
182+
recipientMergeFields.Add(new MergeFieldJson("RecipientName", recipient.FriendlyName!));
179183

180-
result.Add(recipientMergeFields);
184+
result.Add(recipientMergeFields);
185+
}
181186
}
182187

183188
return result;
@@ -191,8 +196,8 @@ internal virtual List<List<MergeFieldJson>> GetBulkMergeFields(IEnumerable<IBulk
191196
internal virtual List<MergeFieldJson> PopulateMergeData(IDictionary<string, string> mergeData)
192197
{
193198

194-
var result = mergeData?.Select(item => new MergeFieldJson(item.Key, item.Value));
195-
return result?.ToList();
199+
var result = mergeData.Select(item => new MergeFieldJson(item.Key, item.Value));
200+
return result.ToList();
196201
}
197202

198203

@@ -203,8 +208,8 @@ internal virtual List<MergeFieldJson> PopulateMergeData(IDictionary<string, stri
203208
/// <returns>A <c><![CDATA[ List<MetadataHeaderJson> ]]></c> used in generating an InjectionRequest</returns>
204209
internal virtual List<MetadataHeaderJson> PopulateMetadata(IList<IMetadata> metadata)
205210
{
206-
var result = metadata?.Select(item => new MetadataHeaderJson(item.Key, item.Value));
207-
return result?.ToList();
211+
var result = metadata.Select(item => new MetadataHeaderJson(item.Key, item.Value));
212+
return result.ToList();
208213
}
209214

210215
/// <summary>
@@ -215,7 +220,7 @@ internal virtual List<MetadataHeaderJson> PopulateMetadata(IList<IMetadata> meta
215220
internal virtual List<string> PopulateTags(IList<string> tags)
216221
{
217222
var result = tags.ToList();
218-
return result?.ToList();
223+
return result;
219224
}
220225
}
221226
}

src/SocketLabs/InjectionApi/Core/InjectionResponseParser.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ public SendResponse Parse(HttpResponseMessage httpResponse)
2323

2424
var injectionResponse = JsonConvert.DeserializeObject<InjectionResponseDto>(contentString);
2525

26+
if (injectionResponse is null)
27+
{
28+
return new SendResponse()
29+
{
30+
Result = SendResult.UnknownError
31+
};
32+
}
33+
2634
var resultEnum = DetermineSendResult(injectionResponse, httpResponse);
2735
var newResponse = new SendResponse
2836
{

src/SocketLabs/InjectionApi/Core/SendValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ internal virtual List<AddressResult> HasInvalidRecipients(IBulkMessage message)
290290
/// <returns>A <c><![CDATA[ List<AddressResult> ]]></c> if an invalid email address is found.</returns>
291291
/// <see cref="IEmailAddress"/>
292292
/// <see cref="AddressResult"/>
293-
internal virtual List<AddressResult> FindInvalidRecipients(IList<IEmailAddress> recipients)
293+
internal virtual List<AddressResult>? FindInvalidRecipients(IList<IEmailAddress>? recipients)
294294
{
295295
var invalid = recipients?.Where(item => !item.IsValid).Select(x => new AddressResult()
296296
{
@@ -312,7 +312,7 @@ internal virtual List<AddressResult> FindInvalidRecipients(IList<IEmailAddress>
312312
/// <returns>A <c><![CDATA[ List<AddressResult> ]]></c> if an invalid email address is found.</returns>
313313
/// <see cref="IBulkRecipient"/>
314314
/// <see cref="AddressResult"/>
315-
internal virtual List<AddressResult> FindInvalidRecipients(IList<IBulkRecipient> recipients)
315+
internal virtual List<AddressResult>? FindInvalidRecipients(IList<IBulkRecipient> recipients)
316316
{
317317
var invalid = recipients?.Where(item => !item.IsValid).Select(x => new AddressResult()
318318
{

0 commit comments

Comments
 (0)