aboutsummaryrefslogtreecommitdiff
path: root/Emails.Transactional.Client/TransactionalEmailConfig.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emails.Transactional.Client/TransactionalEmailConfig.cs')
-rw-r--r--Emails.Transactional.Client/TransactionalEmailConfig.cs62
1 files changed, 62 insertions, 0 deletions
diff --git a/Emails.Transactional.Client/TransactionalEmailConfig.cs b/Emails.Transactional.Client/TransactionalEmailConfig.cs
new file mode 100644
index 0000000..9efeba4
--- /dev/null
+++ b/Emails.Transactional.Client/TransactionalEmailConfig.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+
+namespace Emails.Transactional.Client
+{
+ /// <summary>
+ /// A global configuration object for transactional email clients
+ /// </summary>
+ public class TransactionalEmailConfig
+ {
+ /// <summary>
+ /// The server transaction endpoint location
+ /// </summary>
+ public Uri ServiceLocation { get; private set; }
+
+ /// <summary>
+ /// An email id template/translation table for email template-ids
+ /// </summary>
+ public IReadOnlyDictionary<string, string> TemplateIdLookup { get; private set; }
+
+ /// <summary>
+ /// Adds the mail service location to the current instance
+ /// </summary>
+ /// <param name="serviceLocation">The address of the remote server transaction endpoint</param>
+ /// <returns>A referrence to the current object (fluent api)</returns>
+ /// <exception cref="ArgumentNullException"></exception>
+ public TransactionalEmailConfig WithUrl(Uri serviceLocation)
+ {
+ ServiceLocation = serviceLocation ?? throw new ArgumentNullException(nameof(serviceLocation));
+ return this;
+ }
+ /// <summary>
+ /// Sets the template lookup table for the current instance
+ /// </summary>
+ /// <param name="templates">The template-id lookup table to referrence</param>
+ /// <returns>A referrence to the current object (fluent api)</returns>
+ /// <exception cref="ArgumentNullException"></exception>
+ public TransactionalEmailConfig WithTemplates(IReadOnlyDictionary<string, string> templates)
+ {
+ TemplateIdLookup = templates ?? throw new ArgumentNullException(nameof(templates));
+ return this;
+ }
+
+ /// <summary>
+ /// Gets a new <see cref="EmailTransactionRequest"/> from the specifed
+ /// template name.
+ /// </summary>
+ /// <param name="templateName"></param>
+ /// <returns></returns>
+ /// <exception cref="KeyNotFoundException"></exception>
+ /// <exception cref="ArgumentNullException"></exception>
+ public EmailTransactionRequest GetTemplateRequest(string templateName)
+ {
+ //get the template from its template name
+ string templateId = TemplateIdLookup[templateName];
+ return new EmailTransactionRequest(templateId)
+ {
+ Endpoint = this.ServiceLocation
+ };
+ }
+ }
+}