Skip to content

Commit

Permalink
Merge branch 'release/0.59.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Jun 21, 2019
2 parents e814dc7 + 954afd8 commit b3a32ea
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Source/StrongGrid.UnitTests/StrongGrid.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="Moq" Version="4.11.0" />
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="RichardSzalay.MockHttp" Version="5.0.0" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand Down
14 changes: 13 additions & 1 deletion Source/StrongGrid/Models/Webhooks/OpenEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace StrongGrid.Models.Webhooks
{
Expand Down Expand Up @@ -26,5 +26,17 @@ public class OpenEvent : EngagementEvent
/// </value>
[JsonProperty("newsletter", NullValueHandling = NullValueHandling.Ignore)]
public Newsletter Newsletter { get; set; }

/// <summary>
/// Gets or sets the content type.
/// </summary>
/// <remarks>
/// Possible values: "html" or "amp".
/// </remarks>
/// <value>
/// The content type.
/// </value>
[JsonProperty("sg_content_type", NullValueHandling = NullValueHandling.Ignore)]
public string ContentType { get; set; }
}
}
8 changes: 7 additions & 1 deletion Source/StrongGrid/Models/Webhooks/UrlType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Runtime.Serialization;

Expand All @@ -22,6 +22,12 @@ public enum UrlType
[EnumMember(Value = "html")]
Html,

/// <summary>
/// AMP.
/// </summary>
[EnumMember(Value = "amp")]
Amp,

/// <summary>
/// Header.
/// </summary>
Expand Down
115 changes: 114 additions & 1 deletion Source/StrongGrid/Resources/IMail.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using StrongGrid.Models;
using StrongGrid.Models;
using System;
using System.Collections.Generic;
using System.Threading;
Expand Down Expand Up @@ -179,6 +179,63 @@ Task<string> SendToSingleRecipientAsync(
MailSettings mailSettings = null,
CancellationToken cancellationToken = default);

/// <summary>
/// Send an AMP email to a single recipient without using a template (which means you must provide the subject, html content and text content).
/// </summary>
/// <param name="to">To.</param>
/// <param name="from">From.</param>
/// <param name="subject">The subject.</param>
/// <param name="ampContent">Content of the AMP.</param>
/// <param name="htmlContent">Content of the HTML.</param>
/// <param name="textContent">Content of the text.</param>
/// <param name="trackOpens">if set to <c>true</c> [track opens].</param>
/// <param name="trackClicks">if set to <c>true</c> [track clicks].</param>
/// <param name="subscriptionTracking">The subscription tracking.</param>
/// <param name="replyTo">The reply to.</param>
/// <param name="attachments">The attachments.</param>
/// <param name="sections">The sections.</param>
/// <param name="headers">The headers.</param>
/// <param name="categories">The categories.</param>
/// <param name="customArgs">The custom arguments.</param>
/// <param name="sendAt">The send at.</param>
/// <param name="batchId">The batch identifier.</param>
/// <param name="unsubscribeOptions">The unsubscribe options.</param>
/// <param name="ipPoolName">Name of the ip pool.</param>
/// <param name="mailSettings">The mail settings.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The message id.
/// </returns>
/// <remarks>
/// This overload is ideal when sending an email without using a template.
/// This is a convenience method with simplified parameters.
/// If you need more options, use the <see cref="SendAsync" /> method.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">Too many recipients.</exception>
/// <exception cref="Exception">Email exceeds the size limit.</exception>
Task<string> SendAmpEmailToSingleRecipientAsync(
MailAddress to,
MailAddress from,
string subject,
string ampContent,
string htmlContent,
string textContent,
bool trackOpens = true,
bool trackClicks = true,
SubscriptionTrackingSettings subscriptionTracking = null,
MailAddress replyTo = null,
IEnumerable<Attachment> attachments = null,
IEnumerable<KeyValuePair<string, string>> sections = null,
IEnumerable<KeyValuePair<string, string>> headers = null,
IEnumerable<string> categories = null,
IEnumerable<KeyValuePair<string, string>> customArgs = null,
DateTime? sendAt = null,
string batchId = null,
UnsubscribeOptions unsubscribeOptions = null,
string ipPoolName = null,
MailSettings mailSettings = null,
CancellationToken cancellationToken = default);

/// <summary>
/// Send the same email to multiple recipients without using a template (which means you must provide the subject, html content and text content).
/// </summary>
Expand Down Expand Up @@ -343,6 +400,62 @@ Task<string> SendToMultipleRecipientsAsync(
MailSettings mailSettings = null,
CancellationToken cancellationToken = default);

/// <summary>
/// Send the same AMP email to multiple recipients without using a template (which means you must provide the subject, html content and text content).
/// </summary>
/// <param name="recipients">The recipients.</param>
/// <param name="from">From.</param>
/// <param name="subject">The subject.</param>
/// <param name="ampContent">Content of the AMP.</param>
/// <param name="htmlContent">Content of the HTML.</param>
/// <param name="textContent">Content of the text.</param>
/// <param name="trackOpens">if set to <c>true</c> [track opens].</param>
/// <param name="trackClicks">if set to <c>true</c> [track clicks].</param>
/// <param name="subscriptionTracking">The subscription tracking.</param>
/// <param name="replyTo">The reply to.</param>
/// <param name="attachments">The attachments.</param>
/// <param name="sections">The sections.</param>
/// <param name="headers">The headers.</param>
/// <param name="categories">The categories.</param>
/// <param name="customArgs">The custom arguments.</param>
/// <param name="sendAt">The send at.</param>
/// <param name="batchId">The batch identifier.</param>
/// <param name="unsubscribeOptions">The unsubscribe options.</param>
/// <param name="ipPoolName">Name of the ip pool.</param>
/// <param name="mailSettings">The mail settings.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The message id.
/// </returns>
/// <remarks>
/// This is a convenience method with simplified parameters.
/// If you need more options, use the <see cref="SendAsync" /> method.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">Too many recipients.</exception>
/// <exception cref="Exception">Email exceeds the size limit.</exception>
Task<string> SendAmpEmailToMultipleRecipientsAsync(
IEnumerable<MailAddress> recipients,
MailAddress from,
string subject,
string ampContent,
string htmlContent,
string textContent,
bool trackOpens = true,
bool trackClicks = true,
SubscriptionTrackingSettings subscriptionTracking = null,
MailAddress replyTo = null,
IEnumerable<Attachment> attachments = null,
IEnumerable<KeyValuePair<string, string>> sections = null,
IEnumerable<KeyValuePair<string, string>> headers = null,
IEnumerable<string> categories = null,
IEnumerable<KeyValuePair<string, string>> customArgs = null,
DateTime? sendAt = null,
string batchId = null,
UnsubscribeOptions unsubscribeOptions = null,
string ipPoolName = null,
MailSettings mailSettings = null,
CancellationToken cancellationToken = default);

/// <summary>
/// Send email(s) over SendGrid’s v3 Web API.
/// </summary>
Expand Down
5 changes: 2 additions & 3 deletions Source/StrongGrid/Resources/ITemplates.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using StrongGrid.Models;
using StrongGrid.Models;
using StrongGrid.Utilities;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -122,14 +122,13 @@ public interface ITemplates
/// <param name="htmlContent">Content of the HTML.</param>
/// <param name="textContent">Content of the text.</param>
/// <param name="isActive">if set to <c>true</c> [is active].</param>
/// <param name="editorType">The type of editor.</param>
/// <param name="testData">For dynamic templates only, the mock data that will be used for template preview and test sends.</param>
/// <param name="onBehalfOf">The user to impersonate.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The <see cref="TemplateVersion" />.
/// </returns>
Task<TemplateVersion> UpdateVersionAsync(string templateId, string versionId, Parameter<string> name = default, Parameter<string> subject = default, Parameter<string> htmlContent = default, Parameter<string> textContent = default, Parameter<bool> isActive = default, Parameter<EditorType?> editorType = default, Parameter<object> testData = default, string onBehalfOf = null, CancellationToken cancellationToken = default);
Task<TemplateVersion> UpdateVersionAsync(string templateId, string versionId, Parameter<string> name = default, Parameter<string> subject = default, Parameter<string> htmlContent = default, Parameter<string> textContent = default, Parameter<bool> isActive = default, Parameter<object> testData = default, string onBehalfOf = null, CancellationToken cancellationToken = default);

/// <summary>
/// Delete a template version.
Expand Down
145 changes: 145 additions & 0 deletions Source/StrongGrid/Resources/Mail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,67 @@ public Task<string> SendToSingleRecipientAsync(
return SendToMultipleRecipientsAsync(recipients, from, dynamicTemplateId, dynamicData, trackOpens, trackClicks, subscriptionTracking, replyTo, attachments, sections, headers, categories, customArgs, sendAt, batchId, unsubscribeOptions, ipPoolName, mailSettings, cancellationToken);
}

/// <summary>
/// Send an AMP email to a single recipient without using a template (which means you must provide the subject, html content and text content).
/// </summary>
/// <param name="to">To.</param>
/// <param name="from">From.</param>
/// <param name="subject">The subject.</param>
/// <param name="ampContent">Content of the AMP.</param>
/// <param name="htmlContent">Content of the HTML.</param>
/// <param name="textContent">Content of the text.</param>
/// <param name="trackOpens">if set to <c>true</c> [track opens].</param>
/// <param name="trackClicks">if set to <c>true</c> [track clicks].</param>
/// <param name="subscriptionTracking">The subscription tracking.</param>
/// <param name="replyTo">The reply to.</param>
/// <param name="attachments">The attachments.</param>
/// <param name="sections">The sections.</param>
/// <param name="headers">The headers.</param>
/// <param name="categories">The categories.</param>
/// <param name="customArgs">The custom arguments.</param>
/// <param name="sendAt">The send at.</param>
/// <param name="batchId">The batch identifier.</param>
/// <param name="unsubscribeOptions">The unsubscribe options.</param>
/// <param name="ipPoolName">Name of the ip pool.</param>
/// <param name="mailSettings">The mail settings.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The message id.
/// </returns>
/// <remarks>
/// This overload is ideal when sending an email without using a template.
/// This is a convenience method with simplified parameters.
/// If you need more options, use the <see cref="SendAsync" /> method.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">Too many recipients.</exception>
/// <exception cref="Exception">Email exceeds the size limit.</exception>
public Task<string> SendAmpEmailToSingleRecipientAsync(
MailAddress to,
MailAddress from,
string subject,
string ampContent,
string htmlContent,
string textContent,
bool trackOpens = true,
bool trackClicks = true,
SubscriptionTrackingSettings subscriptionTracking = null,
MailAddress replyTo = null,
IEnumerable<Attachment> attachments = null,
IEnumerable<KeyValuePair<string, string>> sections = null,
IEnumerable<KeyValuePair<string, string>> headers = null,
IEnumerable<string> categories = null,
IEnumerable<KeyValuePair<string, string>> customArgs = null,
DateTime? sendAt = null,
string batchId = null,
UnsubscribeOptions unsubscribeOptions = null,
string ipPoolName = null,
MailSettings mailSettings = null,
CancellationToken cancellationToken = default)
{
var recipients = new[] { to };
return SendAmpEmailToMultipleRecipientsAsync(recipients, from, subject, ampContent, htmlContent, textContent, trackOpens, trackClicks, subscriptionTracking, replyTo, attachments, sections, headers, categories, customArgs, sendAt, batchId, unsubscribeOptions, ipPoolName, mailSettings, cancellationToken);
}

/// <summary>
/// Send the same email to multiple recipients without using a template (which means you must provide the subject, html content and text content).
/// </summary>
Expand Down Expand Up @@ -460,6 +521,90 @@ public Task<string> SendToMultipleRecipientsAsync(
return SendAsync(personalizations, null, null, from, replyTo, attachments, dynamicTemplateId, sections, headers, categories, customArgs, sendAt, batchId, unsubscribeOptions, ipPoolName, mailSettings, trackingSettings, cancellationToken);
}

/// <summary>
/// Send the same AMP email to multiple recipients.
/// </summary>
/// <param name="recipients">The recipients.</param>
/// <param name="from">From.</param>
/// <param name="subject">The subject.</param>
/// <param name="ampContent">Content of the AMP.</param>
/// <param name="htmlContent">Content of the HTML.</param>
/// <param name="textContent">Content of the text.</param>
/// <param name="trackOpens">if set to <c>true</c> [track opens].</param>
/// <param name="trackClicks">if set to <c>true</c> [track clicks].</param>
/// <param name="subscriptionTracking">The subscription tracking.</param>
/// <param name="replyTo">The reply to.</param>
/// <param name="attachments">The attachments.</param>
/// <param name="sections">The sections.</param>
/// <param name="headers">The headers.</param>
/// <param name="categories">The categories.</param>
/// <param name="customArgs">The custom arguments.</param>
/// <param name="sendAt">The send at.</param>
/// <param name="batchId">The batch identifier.</param>
/// <param name="unsubscribeOptions">The unsubscribe options.</param>
/// <param name="ipPoolName">Name of the ip pool.</param>
/// <param name="mailSettings">The mail settings.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The message id.
/// </returns>
/// <remarks>
/// This is a convenience method with simplified parameters.
/// If you need more options, use the <see cref="SendAsync" /> method.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">Too many recipients.</exception>
/// <exception cref="Exception">Email exceeds the size limit.</exception>
public Task<string> SendAmpEmailToMultipleRecipientsAsync(
IEnumerable<MailAddress> recipients,
MailAddress from,
string subject,
string ampContent,
string htmlContent,
string textContent,
bool trackOpens = true,
bool trackClicks = true,
SubscriptionTrackingSettings subscriptionTracking = null,
MailAddress replyTo = null,
IEnumerable<Attachment> attachments = null,
IEnumerable<KeyValuePair<string, string>> sections = null,
IEnumerable<KeyValuePair<string, string>> headers = null,
IEnumerable<string> categories = null,
IEnumerable<KeyValuePair<string, string>> customArgs = null,
DateTime? sendAt = null,
string batchId = null,
UnsubscribeOptions unsubscribeOptions = null,
string ipPoolName = null,
MailSettings mailSettings = null,
CancellationToken cancellationToken = default)
{
var personalizations = new[]
{
new MailPersonalization
{
To = recipients.ToArray()
}
};

var contents = new List<MailContent>();
if (!string.IsNullOrEmpty(textContent)) contents.Add(new MailContent("text/plain", textContent));
if (!string.IsNullOrEmpty(ampContent)) contents.Add(new MailContent("text/x-amp-html", ampContent));
if (!string.IsNullOrEmpty(htmlContent)) contents.Add(new MailContent("text/html", htmlContent));

var trackingSettings = new TrackingSettings
{
ClickTracking = new ClickTrackingSettings
{
EnabledInHtmlContent = trackClicks,
EnabledInTextContent = trackClicks
},
OpenTracking = new OpenTrackingSettings { Enabled = trackOpens },
GoogleAnalytics = new GoogleAnalyticsSettings { Enabled = false },
SubscriptionTracking = subscriptionTracking
};

return SendAsync(personalizations, subject, contents, from, replyTo, attachments, null, sections, headers, categories, customArgs, sendAt, batchId, unsubscribeOptions, ipPoolName, mailSettings, trackingSettings, cancellationToken);
}

/// <summary>
/// Send email(s) over SendGrid’s v3 Web API.
/// </summary>
Expand Down
6 changes: 2 additions & 4 deletions Source/StrongGrid/Resources/Templates.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pathoschild.Http.Client;
using StrongGrid.Models;
Expand Down Expand Up @@ -219,22 +219,20 @@ public Task<TemplateVersion> GetVersionAsync(string templateId, string versionId
/// <param name="htmlContent">Content of the HTML.</param>
/// <param name="textContent">Content of the text.</param>
/// <param name="isActive">The is active.</param>
/// <param name="editorType">The type of editor.</param>
/// <param name="testData">For dynamic templates only, the mock data that will be used for template preview and test sends.</param>
/// <param name="onBehalfOf">The user to impersonate.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The <see cref="TemplateVersion" />.
/// </returns>
public Task<TemplateVersion> UpdateVersionAsync(string templateId, string versionId, Parameter<string> name = default, Parameter<string> subject = default, Parameter<string> htmlContent = default, Parameter<string> textContent = default, Parameter<bool> isActive = default, Parameter<EditorType?> editorType = default, Parameter<object> testData = default, string onBehalfOf = null, CancellationToken cancellationToken = default)
public Task<TemplateVersion> UpdateVersionAsync(string templateId, string versionId, Parameter<string> name = default, Parameter<string> subject = default, Parameter<string> htmlContent = default, Parameter<string> textContent = default, Parameter<bool> isActive = default, Parameter<object> testData = default, string onBehalfOf = null, CancellationToken cancellationToken = default)
{
var data = new JObject();
data.AddPropertyIfValue("name", name);
data.AddPropertyIfValue("subject", subject);
data.AddPropertyIfValue("html_content", htmlContent);
data.AddPropertyIfValue("plain_content", textContent);
data.AddPropertyIfValue("active", isActive, value => JToken.FromObject(value ? 1 : 0));
data.AddPropertyIfEnumValue("editor", editorType);
data.AddPropertyIfValue("test_data", testData);

return _client
Expand Down
Loading

0 comments on commit b3a32ea

Please sign in to comment.