diff --git a/src/Postmark.Tests/ClientBaseFixture.cs b/src/Postmark.Tests/ClientBaseFixture.cs index 16b14ca..f640b7e 100644 --- a/src/Postmark.Tests/ClientBaseFixture.cs +++ b/src/Postmark.Tests/ClientBaseFixture.cs @@ -2,10 +2,10 @@ using PostmarkDotNet; using System; using System.IO; -using Newtonsoft.Json; using System.Collections.Generic; using System.Reflection; using System.Linq; +using System.Text.Json; namespace Postmark.Tests { @@ -58,7 +58,7 @@ private static string ConfigVariable(string variableName) componentsCount--; } - var values = JsonConvert.DeserializeObject>(File.ReadAllText(keyPath)); + var values = JsonSerializer.Deserialize>(File.ReadAllText(keyPath)); retval = values[variableName]; } catch diff --git a/src/Postmark.Tests/ClientWebhookTests.cs b/src/Postmark.Tests/ClientWebhookTests.cs index 886eeb1..9a0e51c 100644 --- a/src/Postmark.Tests/ClientWebhookTests.cs +++ b/src/Postmark.Tests/ClientWebhookTests.cs @@ -42,7 +42,6 @@ public async Task ClientCanCreateConfiguration() Delivery = new WebhookConfigurationDeliveryTrigger {Enabled = true}, SpamComplaint = new WebhookConfigurationSpamComplaintTrigger {Enabled = true, IncludeContent = true}, SubscriptionChange = new WebhookConfigurationSubscriptionChangeTrigger {Enabled = true}, - }; var newConfiguration = await Client.CreateWebhookConfigurationAsync(url, messageStream, httpAuth, httpHeaders, triggers); diff --git a/src/Postmark/Convenience/SystemMailExtensions.cs b/src/Postmark/Convenience/SystemMailExtensions.cs deleted file mode 100644 index db82118..0000000 --- a/src/Postmark/Convenience/SystemMailExtensions.cs +++ /dev/null @@ -1,224 +0,0 @@ -#if NET20 -using PostmarkDotNet; -using PostmarkDotNet.Model; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net.Mail; -using System.Net.Mime; -using System.Text; -using System.Threading.Tasks; - -namespace PostmarkDotNet -{ - public static class SystemMailExtensions - { - /// - /// Send a System.Net.MailMessage (transparently converts to the PostmarkMessage). - /// - /// - /// - /// - public static async Task SendMessageAsync - (this PostmarkClient client, MailMessage message) - { - return await client.SendMessageAsync(ConvertSystemMailMessage(message)); - } - - /// - /// Send a System.Net.MailMessage(s) (transparently converts to the PostmarkMessages). - /// - /// - /// - /// - public static async Task> SendMessagesAsync - (this PostmarkClient client, params MailMessage[] messages) - { - return await client.SendMessagesAsync(messages.Select(ConvertSystemMailMessage)); - } - - /// - /// Initializes a new instance of the class - /// based on an existing instance. - /// - /// Only the first recipient of the message is added to the - /// instance. - /// - /// The existing message. - private static PostmarkMessage ConvertSystemMailMessage(MailMessage message) - { - var pm = new PostmarkMessage(); - - if (message.From != null) - pm.From = !string.IsNullOrEmpty(message.From.DisplayName) - ? string.Format("{0} <{1}>", message.From.DisplayName, message.From.Address) - : message.From.Address; - - GetMailMessageRecipients(pm, message); - - pm.Subject = message.Subject; - pm.HtmlBody = message.IsBodyHtml ? message.Body : null; - pm.TextBody = message.IsBodyHtml ? null : message.Body; - - GetHtmlBodyFromAlternateViews(pm, message); - - //Disabling "ReplyTo" obsolecense warning, as we need to continue to map this for users of the API that cannot upgrade." -#pragma warning disable 0618 - - if (message.ReplyTo != null) - { - pm.ReplyTo = !string.IsNullOrEmpty(message.ReplyTo.DisplayName) - ? string.Format("{0} <{1}>", message.ReplyTo.DisplayName, message.ReplyTo.Address) - : message.ReplyTo.Address; - } -#pragma warning restore 0618 - // We include the coalescing of 'X-PostmarkTag' here because it was historically - // in the library, and clients may rely upon it, but "X-PM-Tag" is the header that matches - // Our SMTP docs, and therefore the "correct" header. - var header = message.Headers.Get("X-PM-Tag") ?? message.Headers.Get("X-PostmarkTag"); - if (header != null) - { - pm.Tag = header; - } - - pm.Headers = new HeaderCollection(); - - if (message.Headers != null) - { - foreach (var h in message.Headers.AllKeys) - { - pm.Headers.Add(h, message.Headers[h]); - } - } - - pm.Attachments = new List(0); - - foreach (var item in from attachment in message.Attachments - where attachment.ContentStream != null - let content = ReadStream(attachment.ContentStream, 8192) - select new PostmarkMessageAttachment - { - Name = attachment.Name, - ContentType = attachment.ContentType.ToString(), - Content = Convert.ToBase64String(content) - }) - { - pm.Attachments.Add(item); - } - return pm; - } - - private static void GetMailMessageRecipients(PostmarkMessage m, MailMessage message) - { - GetMailMessageTo(m, message); - GetMailMessageCc(m, message); - GetMailMessageBcc(m, message); - } - - private static void GetMailMessageCc(PostmarkMessage m, MailMessage message) - { - var sb = new StringBuilder(0); - - if (message.CC.Count > 0) - { - foreach (var cc in message.CC) - { - sb.AppendFormat("{0},", cc.Address); - } - } - - m.Cc = sb.ToString(); - } - - private static void GetMailMessageBcc(PostmarkMessage m, MailMessage message) - { - var sb = new StringBuilder(0); - - if (message.Bcc.Count > 0) - { - foreach (var bcc in message.Bcc) - { - sb.AppendFormat("{0},", bcc.Address); - } - } - - m.Bcc = sb.ToString(); - } - - private static void GetMailMessageTo(PostmarkMessage m, MailMessage message) - { - var sb = new StringBuilder(0); - foreach (var to in message.To) - { - if (!string.IsNullOrEmpty(to.DisplayName)) - { - sb.AppendFormat("{0} <{1}>,", to.DisplayName, to.Address); - } - else - { - sb.AppendFormat("{0},", to.Address); - } - } - m.To = sb.ToString(); - } - - private static void GetHtmlBodyFromAlternateViews(PostmarkMessage m, MailMessage message) - { - if (message.AlternateViews.Count <= 0) - { - return; - } - - var plainTextView = message.AlternateViews.Where(v => v.ContentType.MediaType.Equals(MediaTypeNames.Text.Plain)).FirstOrDefault(); - if (plainTextView != null) - { - m.TextBody = GetStringFromView(plainTextView); - } - - var htmlView = message.AlternateViews.Where(v => v.ContentType.MediaType.Equals(MediaTypeNames.Text.Html)).FirstOrDefault(); - if (htmlView != null) - { - m.HtmlBody = GetStringFromView(htmlView); - } - } - - private static string GetStringFromView(AttachmentBase view) - { - - Encoding encoding = resolveViewEncoding(view, Encoding.ASCII); - - var data = new byte[view.ContentStream.Length]; - view.ContentStream.Read(data, 0, data.Length); - return encoding.GetString(data); - } - - private static Encoding resolveViewEncoding(AttachmentBase view, Encoding fallbackEncoding) - { - String charSet = view.ContentType.CharSet; - try - { - return Encoding.GetEncoding(charSet); - } - catch - { - return fallbackEncoding; - } - } - - private static byte[] ReadStream(Stream input, int bufferSize) - { - var buffer = new byte[bufferSize]; - using (var ms = new MemoryStream()) - { - int read; - while ((read = input.Read(buffer, 0, buffer.Length)) > 0) - { - ms.Write(buffer, 0, read); - } - return ms.ToArray(); - } - } - } -} -#endif \ No newline at end of file diff --git a/src/Postmark/Converters/DateTimeConverter.cs b/src/Postmark/Converters/DateTimeConverter.cs new file mode 100644 index 0000000..7772835 --- /dev/null +++ b/src/Postmark/Converters/DateTimeConverter.cs @@ -0,0 +1,24 @@ +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace PostmarkDotNet.Converters +{ + public class DateTimeConverter : JsonConverter + { + public override bool CanConvert(Type typeToConvert) + { + return typeToConvert == typeof(DateTime); + } + + public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return DateTime.Parse(reader.GetString()); + } + + public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) + { + writer.WriteStringValue(value.ToString("O")); + } + } +} \ No newline at end of file diff --git a/src/Postmark/Converters/JsonNetExtensions.cs b/src/Postmark/Converters/JsonExtensions.cs similarity index 61% rename from src/Postmark/Converters/JsonNetExtensions.cs rename to src/Postmark/Converters/JsonExtensions.cs index 308ab8c..ce5200c 100644 --- a/src/Postmark/Converters/JsonNetExtensions.cs +++ b/src/Postmark/Converters/JsonExtensions.cs @@ -1,8 +1,8 @@ -using Newtonsoft.Json; +using System.Text.Json; namespace PostmarkDotNet.Converters { - internal static class JsonNetExtensions + internal static class JsonExtensions { /// /// Attempt to deserialize a string to the specified type. @@ -17,15 +17,14 @@ internal static bool TryDeserializeObject(string json, out T result) result = default(T); try { - var settings = new JsonSerializerSettings() - { - MissingMemberHandling = MissingMemberHandling.Ignore, - NullValueHandling = NullValueHandling.Include, - DefaultValueHandling = DefaultValueHandling.Include - }; - - settings.Converters.Add(new UnicodeJsonStringConverter()); - result = JsonConvert.DeserializeObject(json); + result = JsonSerializer.Deserialize(json, new JsonSerializerOptions + { + Converters = + { + new UnicodeJsonStringConverter(), + new DateTimeConverter() + } + }); retval = true; } catch diff --git a/src/Postmark/Converters/PostmarkConverter.Net20.cs b/src/Postmark/Converters/PostmarkConverter.Net20.cs deleted file mode 100644 index f1f8977..0000000 --- a/src/Postmark/Converters/PostmarkConverter.Net20.cs +++ /dev/null @@ -1,83 +0,0 @@ -#if NET20 -using System; -using System.IO; -using System.Text; -using Newtonsoft.Json; -using Hammock; -using Hammock.Serialization; - -namespace PostmarkDotNet.Converters -{ - internal class PostmarkConverter : ISerializer, IDeserializer - { - private readonly JsonSerializer _serializer; - - public PostmarkConverter(JsonSerializerSettings settings) - { - _serializer = new JsonSerializer - { - ConstructorHandling = settings.ConstructorHandling, - ContractResolver = settings.ContractResolver, - ObjectCreationHandling = settings.ObjectCreationHandling, - MissingMemberHandling = settings.MissingMemberHandling, - DefaultValueHandling = settings.DefaultValueHandling, - NullValueHandling = settings.NullValueHandling - }; - - foreach (var converter in settings.Converters) - { - _serializer.Converters.Add(converter); - } - } - - public virtual object Deserialize(RestResponseBase response, Type type) - { - using (var stringReader = new StringReader(response.Content)) - { - using (var jsonTextReader = new JsonTextReader(stringReader)) - { - return _serializer.Deserialize(jsonTextReader, type); - } - } - } - - public virtual T Deserialize(RestResponseBase response) - { - using (var stringReader = new StringReader(response.Content)) - { - using (var jsonTextReader = new JsonTextReader(stringReader)) - { - return _serializer.Deserialize(jsonTextReader); - } - } - } - - public virtual string Serialize(object instance, Type type) - { - using (var stringWriter = new StringWriter()) - { - using (var jsonTextWriter = new JsonTextWriter(stringWriter)) - { - jsonTextWriter.Formatting = Formatting.Indented; - jsonTextWriter.QuoteChar = '"'; - - _serializer.Serialize(jsonTextWriter, instance); - - var result = stringWriter.ToString(); - return result; - } - } - } - - public virtual string ContentType - { - get { return "application/json"; } - } - - public Encoding ContentEncoding - { - get { return Encoding.UTF8; } - } - } -} -#endif \ No newline at end of file diff --git a/src/Postmark/Converters/UnicodeJsonStringConverter.cs b/src/Postmark/Converters/UnicodeJsonStringConverter.cs index a400e6a..bdc9518 100644 --- a/src/Postmark/Converters/UnicodeJsonStringConverter.cs +++ b/src/Postmark/Converters/UnicodeJsonStringConverter.cs @@ -1,76 +1,71 @@ using System; using System.Text; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; namespace PostmarkDotNet.Converters { - internal class UnicodeJsonStringConverter : JsonConverter + public class UnicodeJsonStringConverter : JsonConverter { - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + public override bool CanConvert(Type objectType) + { + return objectType == typeof(string); + } + + public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return reader.GetString(); + } + + public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) { - var buffer = new StringBuilder(); - buffer.Append("\""); - var stringValue = (string) value; - foreach (var c in stringValue) + var stringBuilder = new StringBuilder(); + stringBuilder.Append("\""); + + foreach (char c in value) { - var code = (int) c; + int num = c; switch (c) { - case '\"': - buffer.Append("\\\""); - break; + case '"': + stringBuilder.Append("\\\""); + continue; case '\\': - buffer.Append("\\\\"); - break; + stringBuilder.Append("\\\\"); + continue; case '\r': - buffer.Append("\\r"); - break; + stringBuilder.Append("\\r"); + continue; case '\n': - buffer.Append("\\n"); - break; + stringBuilder.Append("\\n"); + continue; case '\t': - buffer.Append("\\t"); - break; + stringBuilder.Append("\\t"); + continue; case '\b': - buffer.Append("\\b"); - break; + stringBuilder.Append("\\b"); + continue; case '/': - buffer.Append("\\/"); - break; + stringBuilder.Append("\\/"); + continue; case '\f': - buffer.Append("\\f"); - break; - default: - if (code > 127) - { - buffer.AppendFormat("\\u{0:x4}", code); - } - else - { - buffer.Append(c); - } - break; + stringBuilder.Append("\\f"); + continue; } - } - buffer.Append("\""); - - writer.WriteRawValue(buffer.ToString()); - } - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - // Automatic conversion to string from other types - if (reader.ValueType != objectType && objectType == typeof(string)) - { - return reader.Value.ToString(); + if (num < 32 || num > 127) + { + stringBuilder.AppendFormat("\\u{0:x4}", num); + } + else + { + stringBuilder.Append(c); + } } - return reader.Value; - } + stringBuilder.Append("\""); - public override bool CanConvert(Type objectType) - { - return objectType == typeof (string); + writer.WriteRawValue(stringBuilder.ToString()); } } } \ No newline at end of file diff --git a/src/Postmark/IPostmarkClient.Net20.Async.cs b/src/Postmark/IPostmarkClient.Net20.Async.cs deleted file mode 100644 index 758b96a..0000000 --- a/src/Postmark/IPostmarkClient.Net20.Async.cs +++ /dev/null @@ -1,554 +0,0 @@ -#if NET20 -using System; -using System.Collections.Generic; -using PostmarkDotNet.Model; - -namespace PostmarkDotNet -{ - public partial interface IPostmarkClient - { - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// An email address for a sender. - /// An email address for a recipient. - /// The message subject line. - /// The plain text message body. May be null if htmlBody is set. - /// The html text message body. May be null if textBody is set. - /// A collection of additional mail headers to send with the message - /// A with details about the transaction. - IAsyncResult BeginSendMessage(string from, string to, string subject, string textBody, string htmlBody, HeaderCollection headers = null); - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message instance - /// - IAsyncResult BeginSendMessage(PostmarkMessage message); - - /// - /// Send a templated message through the Postmark API. - /// - /// - /// - IAsyncResult BeginSendMessage(TemplatedPostmarkMessage message); - - /// - /// Sends a batch of up to messages through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message batch. - /// - IAsyncResult BeginSendMessages(IEnumerable messages); - - /// - /// Sends a batch of up to messages through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message batch. - /// - IAsyncResult BeginSendMessages(params PostmarkMessage[] messages); - - /// - /// Completes an asynchronous request to send a message batch. - /// - ///An for the desired response - /// - IEnumerable EndSendMessages(IAsyncResult asyncResult); - - /// - /// Completes an asynchronous request to send a message. - /// - ///An for the desired response - /// - PostmarkResponse EndSendMessage(IAsyncResult asyncResult); - - /// - /// Retrieves the bounce-related results for the - /// associated mail server. - /// - /// - IAsyncResult BeginGetDeliveryStats(); - - /// - /// Completes a request for the bounce-related results for the - /// associated mail server. - /// - /// - /// - PostmarkDeliveryStats EndGetDeliveryStats(IAsyncResult asyncResult); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(PostmarkBounceType type, bool? inactive, string emailFilter, string tag, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(bool? inactive, string emailFilter, string tag, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(PostmarkBounceType type, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(PostmarkBounceType type, bool? inactive, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(bool? inactive, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(PostmarkBounceType type, string emailFilter, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(string emailFilter, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(PostmarkBounceType type, string emailFilter, string tag, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(string emailFilter, string tag, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(PostmarkBounceType type, bool? inactive, string emailFilter, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - IAsyncResult BeginGetBounces(bool? inactive, string emailFilter, int offset, int count); - - /// - /// Completes an asynchronous request for a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - ///An for the desired response - /// - PostmarkBounces EndGetBounces(IAsyncResult asyncResult); - - /// - /// Retrieves a single based on a specified ID. - /// - /// The bounce ID - /// - /// - IAsyncResult BeginGetBounce(string bounceId); - - /// - /// Completes an asynchronous request for a single based on a specified ID. - /// - /// An for the desired response - /// - PostmarkBounce EndGetBounce(IAsyncResult asyncResult); - - /// - /// Returns the raw source of the bounce we accepted. - /// If Postmark does not have a dump for that bounce, it will return an empty string. - /// - /// The bounce ID - /// - /// - IAsyncResult BeginGetBounceDump(string bounceId); - - /// - /// Completes an asynchronous request for the raw source of the bounce we accepted. - /// - /// An for the desired response - /// - PostmarkBounceDump EndGetBounceDump(IAsyncResult asyncResult); - - /// - /// Activates a deactivated bounce. - /// - /// The bounce ID - /// - /// - IAsyncResult BeginActivateBounce(string bounceId); - - /// - /// Completes an asynchronous request for a deactivated bounce. - /// - /// - /// - PostmarkBounceActivation EndActivateBounce(IAsyncResult asyncResult); - - - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Filter by message subject. - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - IAsyncResult BeginGetOutboundMessages(int count, string subject, int offset); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// Filter by the recipient(s) of the message. - /// IAsyncResult - /// - IAsyncResult BeginGetOutboundMessages(int count, int offset, string recipient); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - IAsyncResult BeginGetOutboundMessages(int count, int offset); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - IAsyncResult BeginGetOutboundMessages(string recipient, string fromemail, - int count, int offset); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - IAsyncResult BeginGetOutboundMessages(string subject, int count, int offset); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Filter by a tag used for the message (messages sent directly through the API only) - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - IAsyncResult BeginGetOutboundMessages(string fromemail, string tag, - string subject, int count, int offset); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by a tag used for the message (messages sent directly through the API only) - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - IAsyncResult BeginGetOutboundMessages(string recipient, string fromemail, string tag, - string subject, int count, int offset); - - /// - /// Completes an asynchronous request for a instances along - /// with a sum total of messages recorded by the server, based on filter parameters. - /// - ///An for the desired response - /// PostmarkOutboundMessageList - PostmarkOutboundMessageList EndGetOutboundMessages(IAsyncResult asyncResult); - - - /// - /// Get the full details of a sent message including all fields, raw body, attachment names, etc - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetOutboundMessages call. - /// IAsyncResult - /// - IAsyncResult BeginGetOutboundMessageDetail(string messageID); - - /// - /// Get the full details of a sent message including all fields, raw body, attachment names, etc - /// - ///An for the desired response - /// OutboundMessageDetail - /// - OutboundMessageDetail EndGetOutboundMessageDetail(IAsyncResult asyncResult); - - - /// - /// Get the original raw message dump of on outbound message including all SMTP headers and data. - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetOutboundMessages call. - /// MessageDump - /// - IAsyncResult BeginGetOutboundMessageDump(string messageID); - - /// - /// Get the original raw message dump of on outbound message including all SMTP headers and data. - /// - ///An for the desired response - /// MessageDump - /// - MessageDump EndGetOutboundMessageDump(IAsyncResult asyncResult); - - - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - IAsyncResult BeginGetInboundMessages(int count, int offset); - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - IAsyncResult BeginGetInboundMessages(string fromemail, int count, int offset); - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - IAsyncResult BeginGetInboundMessages(string fromemail, string subject, int count, int offset); - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - IAsyncResult BeginGetInboundMessages(string recipient, string fromemail, string subject, - int count, int offset); - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Filter by mailbox hash that was parsed from the inbound message. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - IAsyncResult BeginGetInboundMessages(string recipient, string fromemail, string subject, - string mailboxhash, int count, int offset); - - /// - /// Completes an asynchronous request for a instances along - /// with a sum total of messages recorded by the server, based on filter parameters. - /// - /// An for the desired response - /// PostmarkInboundMessageList - /// - PostmarkInboundMessageList EndGetInboundMessages(IAsyncResult asyncResult); - - /// - /// Get the full details of a processed inbound message including all fields, attachment names, etc. - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetInboundMessages call. - /// IAsyncResult - /// - IAsyncResult BeginGetInboundMessageDetail(string messageID); - - /// - /// Completes an asynchronous request for a instance - /// - /// An for the desired response - /// InboundMessageDetail - /// - InboundMessageDetail EndGetInboundMessageDetail(IAsyncResult asyncResult); - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// An email address for a sender. - /// An email address for a recipient. - /// The message subject line. - /// The plain text message body. May be null if htmlBody is set. - /// The html text message body. May be null if textBody is set. - /// The callback invoked when a is received from the API - void SendMessage(string from, string to, string subject, string textBody, string htmlBody, Action callback); - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// An email address for a sender - /// An email address for a recipient - /// The message subject line - /// The plain text message body. May be null if htmlBody is set. - /// The html text message body. May be null if textBody is set. - /// A collection of additional mail headers to send with the message - /// The callback invoked when a response is received from the API - /// A with details about the transaction - void SendMessage(string from, string to, string subject, string textBody, string htmlBody, HeaderCollection headers, Action callback); - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message instance - /// The callback invoked when a response is received from the API - void SendMessage(PostmarkMessage message, Action callback); - - /// - /// Sends a batch of up to messages through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message batch. - /// The callback invoked when a response is received from the API - void SendMessages(IEnumerable messages, Action> callback); - } -} -#endif \ No newline at end of file diff --git a/src/Postmark/IPostmarkClient.Net20.cs b/src/Postmark/IPostmarkClient.Net20.cs deleted file mode 100644 index 2e6bdb6..0000000 --- a/src/Postmark/IPostmarkClient.Net20.cs +++ /dev/null @@ -1,414 +0,0 @@ -#if NET20 -using System.Collections.Generic; -using PostmarkDotNet.Model; - -namespace PostmarkDotNet -{ - /// - /// Defines the contract for the Postmark API. - /// - public partial interface IPostmarkClient - { - /// - /// Override the REST API endpoint by specifying your own address, if necessary. - /// - string Authority { get; set; } - - /// - /// Gets the server token issued with your Postmark email server configuration. - /// - /// The server token. - string ServerToken { get; } - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// An email address for a sender. - /// An email address for a recipient. - /// The message subject line. - /// The plain text message body. May be null if htmlBody is set. - /// The html text message body. May be null if textBody is set. - /// A with details about the transaction. - PostmarkResponse SendMessage(string from, string to, string subject, string textBody, string htmlBody); - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// An email address for a sender. - /// An email address for a recipient. - /// The message subject line. - /// The plain text message body. May be null if htmlBody is set. - /// The html text message body. May be null if textBody is set. - /// A collection of additional mail headers to send with the message. - /// A with details about the transaction. - PostmarkResponse SendMessage(string from, string to, string subject, string textBody, string htmlBody, HeaderCollection headers); - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message instance. - /// - PostmarkResponse SendMessage(PostmarkMessage message); - - /// - /// Send an email using a template associated with your Server. - /// - /// - /// - PostmarkResponse SendMessage(TemplatedPostmarkMessage message); - - /// - /// Sends a batch of up to 500 messages through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message batch. - /// - IEnumerable SendMessages(params PostmarkMessage[] messages); - - /// - /// Sends a batch of up to messages through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message batch. - /// - IEnumerable SendMessages(IEnumerable messages); - - /// - /// Retrieves the bounce-related results for the - /// associated mail server. - /// - /// - PostmarkDeliveryStats GetDeliveryStats(); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(bool? inactive, string emailFilter, string tag, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(PostmarkBounceType type, bool? inactive, string emailFilter, string tag, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(PostmarkBounceType type, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(PostmarkBounceType type, bool? inactive, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(bool? inactive, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(PostmarkBounceType type, string emailFilter, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(string emailFilter, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(PostmarkBounceType type, string emailFilter, string tag, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(string emailFilter, string tag, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(PostmarkBounceType type, bool? inactive, string emailFilter, int offset, int count); - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - PostmarkBounces GetBounces(bool? inactive, string emailFilter, int offset, int count); - - /// - /// Retrieves a single based on a specified ID. - /// - /// The bounce ID - /// - /// - PostmarkBounce GetBounce(string bounceId); - - /// - /// Returns the raw source of the bounce we accepted. - /// If Postmark does not have a dump for that bounce, it will return an empty string. - /// - /// The bounce ID - /// - /// - PostmarkBounceDump GetBounceDump(string bounceId); - - /// - /// Activates a deactivated bounce. - /// - /// The bounce ID - /// - /// - PostmarkBounceActivation ActivateBounce(string bounceId); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Filter by message subject. - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - PostmarkOutboundMessageList GetOutboundMessages(int count, string subject, int offset); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// Filter by the recipient(s) of the message. - /// PostmarkOutboundMessageList - PostmarkOutboundMessageList GetOutboundMessages(int count, int offset, string recipient); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - PostmarkOutboundMessageList GetOutboundMessages(int count, int offset); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - PostmarkOutboundMessageList GetOutboundMessages(string recipient, string fromemail, int count, int offset); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - PostmarkOutboundMessageList GetOutboundMessages(string subject, int count, int offset); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Filter by a tag used for the message (messages sent directly through the API only) - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - PostmarkOutboundMessageList GetOutboundMessages(string fromemail, string tag, - string subject, int count, int offset); - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by a tag used for the message (messages sent directly through the API only) - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - PostmarkOutboundMessageList GetOutboundMessages(string recipient, string fromemail, string tag, - string subject, int count, int offset); - - /// - /// Get the full details of a sent message including all fields, raw body, attachment names, etc - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetOutboundMessages call. - /// OutboundMessageDetail - OutboundMessageDetail GetOutboundMessageDetail(string messageID); - - /// - /// Get the original raw message dump of on outbound message including all SMTP headers and data. - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetOutboundMessages call. - /// MessageDump - MessageDump GetOutboundMessageDump(string messageID); - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkInboundMessageList - PostmarkInboundMessageList GetInboundMessages(int count, int offset); - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkInboundMessageList - PostmarkInboundMessageList GetInboundMessages(string fromemail, int count, int offset); - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkInboundMessageList - PostmarkInboundMessageList GetInboundMessages(string fromemail, string subject, int count, int offset); - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkInboundMessageList - PostmarkInboundMessageList GetInboundMessages(string recipient, string fromemail, string subject, - int count, int offset); - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Filter by mailbox hash that was parsed from the inbound message. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkInboundMessageList - PostmarkInboundMessageList GetInboundMessages(string recipient, string fromemail, string subject, - string mailboxhash, int count, int offset); - - /// - /// Get the full details of a processed inbound message including all fields, attachment names, etc. - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetInboundMessages call. - /// InboundMessageDetail - InboundMessageDetail GetInboundMessageDetail(string messageID); - } -} -#endif \ No newline at end of file diff --git a/src/Postmark/ISimpleHttpClient.cs b/src/Postmark/ISimpleHttpClient.cs index 730e429..5cdd2fd 100644 --- a/src/Postmark/ISimpleHttpClient.cs +++ b/src/Postmark/ISimpleHttpClient.cs @@ -1,5 +1,4 @@ -using System; -using System.Net.Http; +using System.Net.Http; using System.Threading.Tasks; namespace PostmarkDotNet diff --git a/src/Postmark/Model/LinkTrackingOptions.cs b/src/Postmark/Model/LinkTrackingOptions.cs index 5b0f22b..d13b018 100644 --- a/src/Postmark/Model/LinkTrackingOptions.cs +++ b/src/Postmark/Model/LinkTrackingOptions.cs @@ -1,6 +1,5 @@ namespace PostmarkDotNet { - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] public enum LinkTrackingOptions { diff --git a/src/Postmark/Model/MessageStreams/PostmarkMessageStream.cs b/src/Postmark/Model/MessageStreams/PostmarkMessageStream.cs index 2ed1530..01c06a4 100644 --- a/src/Postmark/Model/MessageStreams/PostmarkMessageStream.cs +++ b/src/Postmark/Model/MessageStreams/PostmarkMessageStream.cs @@ -1,5 +1,4 @@ using System; -using PostmarkDotNet; namespace Postmark.Model.MessageStreams { @@ -32,26 +31,22 @@ public class PostmarkMessageStream /// /// The type of this message Stream. Can be Transactional, Inbound or Broadcasts. /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] public MessageStreamType MessageStreamType { get; set; } /// /// The date when the message stream was created. /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.IsoDateTimeConverter))] public DateTime CreatedAt { get; set; } /// /// The date when the message stream was last updated. If null, this message stream was never updated. /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.IsoDateTimeConverter))] public DateTime? UpdatedAt { get; set; } /// /// The date when this message stream has been archived. If null, this message stream is not in an archival state. /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.IsoDateTimeConverter))] public DateTime? ArchivedAt { get; set; } } } diff --git a/src/Postmark/Model/PostmarkAgentInfo.cs b/src/Postmark/Model/PostmarkAgentInfo.cs index d3c791a..864e223 100644 --- a/src/Postmark/Model/PostmarkAgentInfo.cs +++ b/src/Postmark/Model/PostmarkAgentInfo.cs @@ -1,5 +1,3 @@ -using System; - namespace PostmarkDotNet.Model { public class PostmarkAgentInfo diff --git a/src/Postmark/Model/PostmarkBounce.cs b/src/Postmark/Model/PostmarkBounce.cs index 65c0374..fce0025 100644 --- a/src/Postmark/Model/PostmarkBounce.cs +++ b/src/Postmark/Model/PostmarkBounce.cs @@ -18,7 +18,6 @@ public class PostmarkBounce /// The for this bounce. /// /// The type - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] public PostmarkBounceType Type { get; set; } diff --git a/src/Postmark/Model/PostmarkBounceSummary.cs b/src/Postmark/Model/PostmarkBounceSummary.cs index 64e87cd..ae672f8 100644 --- a/src/Postmark/Model/PostmarkBounceSummary.cs +++ b/src/Postmark/Model/PostmarkBounceSummary.cs @@ -9,7 +9,6 @@ public class PostmarkBounceSummary /// An summary for a . /// /// The type. - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] public PostmarkBounceType Type { get; set; } diff --git a/src/Postmark/Model/PostmarkClicksList.cs b/src/Postmark/Model/PostmarkClicksList.cs index 9755cad..ce643a5 100644 --- a/src/Postmark/Model/PostmarkClicksList.cs +++ b/src/Postmark/Model/PostmarkClicksList.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace PostmarkDotNet.Model { diff --git a/src/Postmark/Model/PostmarkCompleteDomain.cs b/src/Postmark/Model/PostmarkCompleteDomain.cs index 7509314..92b846e 100644 --- a/src/Postmark/Model/PostmarkCompleteDomain.cs +++ b/src/Postmark/Model/PostmarkCompleteDomain.cs @@ -14,6 +14,6 @@ public class PostmarkCompleteDomain : PostmarkBaseDomain public string DKIMUpdateStatus { get; set; } public string ReturnPathDomain { get; set; } public string ReturnPathDomainCNAMEValue { get; set; } - public string SafeToRemoveRevokedKeyFromDNS { get; set; } + public bool SafeToRemoveRevokedKeyFromDNS { get; set; } } } \ No newline at end of file diff --git a/src/Postmark/Model/PostmarkDeliveryWebhookMessage.cs b/src/Postmark/Model/PostmarkDeliveryWebhookMessage.cs index 7bc0786..825a986 100644 --- a/src/Postmark/Model/PostmarkDeliveryWebhookMessage.cs +++ b/src/Postmark/Model/PostmarkDeliveryWebhookMessage.cs @@ -1,6 +1,6 @@ -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace PostmarkDotNet.Webhooks { @@ -13,7 +13,7 @@ public class PostmarkDeliveryWebhookMessage /// /// The associated server's ID. /// - [JsonProperty("ServerId")] + [JsonPropertyName("ServerId")] public int ServerID { get; set; } /// diff --git a/src/Postmark/Model/PostmarkInboundMessageList.cs b/src/Postmark/Model/PostmarkInboundMessageList.cs index 370bd18..662c90d 100644 --- a/src/Postmark/Model/PostmarkInboundMessageList.cs +++ b/src/Postmark/Model/PostmarkInboundMessageList.cs @@ -66,7 +66,7 @@ public class Attachment public string Name { get; set; } public string ContentType { get; set; } public string ContentID { get; set; } - public string ContentLength { get; set; } + public int ContentLength { get; set; } } public class Header diff --git a/src/Postmark/Model/PostmarkInboundWebhookMessage.cs b/src/Postmark/Model/PostmarkInboundWebhookMessage.cs index 93ad9a9..d307e64 100644 --- a/src/Postmark/Model/PostmarkInboundWebhookMessage.cs +++ b/src/Postmark/Model/PostmarkInboundWebhookMessage.cs @@ -1,5 +1,4 @@ -using PostmarkDotNet.Model; -using System; +using System; using System.Collections.Generic; namespace PostmarkDotNet.Webhooks diff --git a/src/Postmark/Model/PostmarkMessageAttachment.cs b/src/Postmark/Model/PostmarkMessageAttachment.cs index 9305c6f..3e2916d 100644 --- a/src/Postmark/Model/PostmarkMessageAttachment.cs +++ b/src/Postmark/Model/PostmarkMessageAttachment.cs @@ -1,5 +1,4 @@ using System; -using System.IO; namespace PostmarkDotNet { diff --git a/src/Postmark/Model/PostmarkOpenWebhookMessage.cs b/src/Postmark/Model/PostmarkOpenWebhookMessage.cs index 9ca4b3a..baf096f 100644 --- a/src/Postmark/Model/PostmarkOpenWebhookMessage.cs +++ b/src/Postmark/Model/PostmarkOpenWebhookMessage.cs @@ -1,7 +1,6 @@ using PostmarkDotNet.Model; using System; using System.Collections.Generic; -using System.Text; namespace PostmarkDotNet.Webhooks { diff --git a/src/Postmark/Model/PostmarkOpensList.cs b/src/Postmark/Model/PostmarkOpensList.cs index 44c971e..abf5af3 100644 --- a/src/Postmark/Model/PostmarkOpensList.cs +++ b/src/Postmark/Model/PostmarkOpensList.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace PostmarkDotNet.Model { diff --git a/src/Postmark/Model/PostmarkOutboundMessagesList.cs b/src/Postmark/Model/PostmarkOutboundMessagesList.cs index 80f0905..4296232 100644 --- a/src/Postmark/Model/PostmarkOutboundMessagesList.cs +++ b/src/Postmark/Model/PostmarkOutboundMessagesList.cs @@ -1,5 +1,4 @@ -using PostmarkDotNet; -using System; +using System; using System.Collections.Generic; namespace PostmarkDotNet.Model diff --git a/src/Postmark/Model/PostmarkResponse.cs b/src/Postmark/Model/PostmarkResponse.cs index 325a071..3e2308c 100644 --- a/src/Postmark/Model/PostmarkResponse.cs +++ b/src/Postmark/Model/PostmarkResponse.cs @@ -1,12 +1,12 @@ using System; -using System.Runtime.Serialization; +using System.Text.Json.Serialization; namespace PostmarkDotNet { /// /// A response from the Postmark API after a request sent with . /// - public class PostmarkResponse + public class PostmarkResponse : IJsonOnDeserialized { /// /// The Message ID returned from Postmark. @@ -40,8 +40,7 @@ public class PostmarkResponse /// public int ErrorCode { get; set; } - [OnDeserialized] - internal void OnDeserializedMethod(StreamingContext context) + void IJsonOnDeserialized.OnDeserialized() { if (ErrorCode != 0 && Status == PostmarkStatus.Success) { diff --git a/src/Postmark/Model/PostmarkTemplate.cs b/src/Postmark/Model/PostmarkTemplate.cs index 2978566..9c83c10 100644 --- a/src/Postmark/Model/PostmarkTemplate.cs +++ b/src/Postmark/Model/PostmarkTemplate.cs @@ -18,7 +18,6 @@ public class PostmarkTemplate public bool Active { get; set; } - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] public TemplateType TemplateType { get; set; } diff --git a/src/Postmark/Model/PostmarkTemplateListingResponse.cs b/src/Postmark/Model/PostmarkTemplateListingResponse.cs index 1a3a211..6a46125 100644 --- a/src/Postmark/Model/PostmarkTemplateListingResponse.cs +++ b/src/Postmark/Model/PostmarkTemplateListingResponse.cs @@ -20,7 +20,6 @@ public class BasicTemplateInformation public string Alias { get; set; } - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] public TemplateType TemplateType { get; set; } diff --git a/src/Postmark/Model/Suppressions/PostmarkReactivationRequestResult.cs b/src/Postmark/Model/Suppressions/PostmarkReactivationRequestResult.cs index 0befb93..03b01ca 100644 --- a/src/Postmark/Model/Suppressions/PostmarkReactivationRequestResult.cs +++ b/src/Postmark/Model/Suppressions/PostmarkReactivationRequestResult.cs @@ -1,6 +1,4 @@ -using PostmarkDotNet; - -namespace Postmark.Model.Suppressions +namespace Postmark.Model.Suppressions { /// /// Result of applying a reactivation request. @@ -15,7 +13,6 @@ public class PostmarkReactivationRequestResult /// /// Status of the request. /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] public PostmarkReactivationRequestStatus Status { get; set; } diff --git a/src/Postmark/Model/Suppressions/PostmarkSuppressionRequestResult.cs b/src/Postmark/Model/Suppressions/PostmarkSuppressionRequestResult.cs index 0b7d72a..e07be4c 100644 --- a/src/Postmark/Model/Suppressions/PostmarkSuppressionRequestResult.cs +++ b/src/Postmark/Model/Suppressions/PostmarkSuppressionRequestResult.cs @@ -1,6 +1,4 @@ -using PostmarkDotNet; - -namespace Postmark.Model.Suppressions +namespace Postmark.Model.Suppressions { /// /// Result of applying a Suppression request. @@ -15,7 +13,6 @@ public class PostmarkSuppressionRequestResult /// /// Status of the request. /// - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] public PostmarkSuppressionRequestStatus Status { get; set; } diff --git a/src/Postmark/Model/TemplateValidationResponse.cs b/src/Postmark/Model/TemplateValidationResponse.cs index 362fc59..c3a8ffd 100644 --- a/src/Postmark/Model/TemplateValidationResponse.cs +++ b/src/Postmark/Model/TemplateValidationResponse.cs @@ -1,7 +1,8 @@ -using Newtonsoft.Json.Linq; -using System.Collections.Generic; +using System.Collections.Generic; using System.Dynamic; using System.Linq; +using System.Text.Json; +using System.Text.Json.Nodes; namespace PostmarkDotNet { @@ -40,25 +41,44 @@ public class TemplateValidationResponse private dynamic ConvertJsonResponse(dynamic value) { dynamic retval = null; - if (value is JObject) + if (value is JsonElement elem) + { + switch (elem.ValueKind) + { + case JsonValueKind.Object: + value = JsonObject.Create(elem); + break; + case JsonValueKind.Array: + value = JsonArray.Create(elem); + break; + default: + value = JsonValue.Create(elem); + break; + } + } + if (value is JsonObject obj) { var dictionary = new ExpandoObject() as IDictionary; - var o = value as JObject; - foreach (var prop in o.Properties()) + foreach (var prop in obj) { - dictionary[prop.Name] = ConvertJsonResponse(prop.Value); + dictionary[prop.Key] = ConvertJsonResponse(prop.Value); } retval = dictionary as ExpandoObject; } - else if (value is JArray) + else if (value is JsonArray arr) { - var o = value as JArray; - retval = o.Select(ConvertJsonResponse).ToArray(); + retval = arr.Select(ConvertJsonResponse).ToArray(); } - else if (value is JValue) + else if (value is JsonValue val) { - var o = value as JValue; - retval = o.Value; + retval = val.GetValueKind() switch + { + JsonValueKind.False => false, + JsonValueKind.True => true, + JsonValueKind.Null => null, + JsonValueKind.Number => val.GetValue(), + _ => val.ToString() + }; } return retval; } diff --git a/src/Postmark/Model/TemplatedPostmarkMessage.cs b/src/Postmark/Model/TemplatedPostmarkMessage.cs index d1d382b..efc34f6 100644 --- a/src/Postmark/Model/TemplatedPostmarkMessage.cs +++ b/src/Postmark/Model/TemplatedPostmarkMessage.cs @@ -1,6 +1,5 @@ using System; -using Newtonsoft.Json.Linq; -using PostmarkDotNet.Exceptions; +using System.Text.Json.Nodes; namespace PostmarkDotNet { @@ -68,7 +67,7 @@ public object TemplateModel { { try { - _templateModel = JObject.Parse(value as string); + _templateModel = JsonNode.Parse(value as string).AsObject(); }catch{ throw new FormatException(@"The specified string is not a valid JSON object." + "The root TemplateModel must be a JSON object, scalars and arrays may not be " + diff --git a/src/Postmark/Postmark.csproj b/src/Postmark/Postmark.csproj index a378469..0441453 100644 --- a/src/Postmark/Postmark.csproj +++ b/src/Postmark/Postmark.csproj @@ -10,10 +10,10 @@ Wildbit, LLC. The official .net client for Postmark. MIT + latest - diff --git a/src/Postmark/Postmark.nuspec b/src/Postmark/Postmark.nuspec index 8b7b221..d58f85c 100644 --- a/src/Postmark/Postmark.nuspec +++ b/src/Postmark/Postmark.nuspec @@ -11,10 +11,5 @@ false The official client library for PostmarkApp. (https://postmarkapp.com) Copyright 2012-$year$ - \ No newline at end of file diff --git a/src/Postmark/PostmarkClient.Net20.Async.cs b/src/Postmark/PostmarkClient.Net20.Async.cs deleted file mode 100644 index 5547955..0000000 --- a/src/Postmark/PostmarkClient.Net20.Async.cs +++ /dev/null @@ -1,804 +0,0 @@ -#if NET20 -using System; -using System.Collections.Generic; -using Newtonsoft.Json; -using PostmarkDotNet.Model; - -namespace PostmarkDotNet -{ - public partial class PostmarkClient - { - #region Mail API - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// An email address for a sender. - /// An email address for a recipient. - /// The message subject line. - /// The plain text message body. This may be null, if htmlBody is set. - /// The plain HTML message body. This may be null, if textBody is set. - /// A with details about the transaction. - public IAsyncResult BeginSendMessage(string from, string to, string subject, string textBody, string htmlBody) - { - return BeginSendMessage(from, to, subject, textBody, htmlBody, null); - } - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// An email address for a sender - /// An email address for a recipient - /// The message subject line - /// The plain text message body. This may be null, if htmlBody is set. - /// The plain HTML message body. This may be null, if textBody is set. - /// A collection of additional mail headers to send with the message - /// A with details about the transaction - public IAsyncResult BeginSendMessage(string from, string to, string subject, string textBody, string htmlBody, HeaderCollection headers) - { - var message = new PostmarkMessage(from, to, subject, textBody, htmlBody, headers); - - return BeginSendMessage(message); - } - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message instance - /// - public IAsyncResult BeginSendMessage(PostmarkMessage message) - { - var request = NewEmailRequest(); - - CleanPostmarkMessage(message); - - request.Entity = message; - - return BeginGetPostmarkResponse(request); - } - - /// - /// Completes an asynchronous request to send a message. - /// - ///An for the desired response - /// - public PostmarkResponse EndSendMessage(IAsyncResult asyncResult) - { - return EndGetPostmarkResponse(asyncResult); - } - - /// - /// Sends a batch of up to messages through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message batch. - /// - public IAsyncResult BeginSendMessages(IEnumerable messages) - { - var request = NewBatchedEmailRequest(); - - var batch = new List(messages); - - foreach (var message in messages) - { - CleanPostmarkMessage(message); - batch.Add(message); - } - - return BeginGetPostmarkResponses(request); - } - - /// - /// Send an email using a template associated with your Server. - /// - /// - /// - public IAsyncResult BeginSendMessage(TemplatedPostmarkMessage message) - { - var request = NewTemplatedEmailRequest(); - request.Entity = message; - return BeginGetPostmarkResponse(request); - } - - /// - /// Sends a batch of up to messages through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message batch. - /// - public IAsyncResult BeginSendMessages(params PostmarkMessage[] messages) - { - return BeginSendMessages(messages ?? new PostmarkMessage[0] ); - } - - /// - /// Completes an asynchronous request to send a message batch. - /// - ///An for the desired response - /// - public IEnumerable EndSendMessages(IAsyncResult asyncResult) - { - return EndGetPostmarkResponses(asyncResult); - } - - private IAsyncResult BeginGetPostmarkResponse(RestRequest request) - { - var response = _client.BeginRequest(request); - return response; - } - - private PostmarkResponse EndGetPostmarkResponse(IAsyncResult asyncResult) - { - var response = _client.EndRequest(asyncResult); - - return GetPostmarkResponseImpl(response); - } - - private IAsyncResult BeginGetPostmarkResponses(RestRequest request) - { - var response = _client.BeginRequest(request); - return response; - } - - private IEnumerable EndGetPostmarkResponses(IAsyncResult asyncResult) - { - var response = _client.EndRequest(asyncResult); - - return GetPostmarkResponsesImpl(response); - } - - #endregion - - #region Bounce API - - /// - /// Retrieves the bounce-related results for the - /// associated mail server. - /// - /// - public IAsyncResult BeginGetDeliveryStats() - { - var request = NewBouncesRequest(); - request.Path = "deliverystats"; - - return _client.BeginRequest(request); - } - - /// - /// Completes a request for the bounce-related results for the - /// associated mail server. - /// - /// - /// - public PostmarkDeliveryStats EndGetDeliveryStats(IAsyncResult asyncResult) - { - return EndBounceRequest(asyncResult); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public IAsyncResult BeginGetBounces(PostmarkBounceType type, bool? inactive, string emailFilter, string tag, int offset, int count) - { - return BeginGetBouncesImpl(type, inactive, emailFilter, tag, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public IAsyncResult BeginGetBounces(bool? inactive, string emailFilter, string tag, int offset, int count) - { - return BeginGetBouncesImpl(null, inactive, emailFilter, tag, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public IAsyncResult BeginGetBounces(PostmarkBounceType type, int offset, int count) - { - return BeginGetBouncesImpl(type, null, null, null, offset, count); - } - - public IAsyncResult BeginGetBounces(int offset, int count) - { - return BeginGetBouncesImpl(null, null, null, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public IAsyncResult BeginGetBounces(PostmarkBounceType type, bool? inactive, int offset, int count) - { - return BeginGetBouncesImpl(type, inactive, null, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public IAsyncResult BeginGetBounces(bool? inactive, int offset, int count) - { - return BeginGetBouncesImpl(null, inactive, null, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public IAsyncResult BeginGetBounces(PostmarkBounceType type, string emailFilter, int offset, int count) - { - return BeginGetBouncesImpl(type, null, emailFilter, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public IAsyncResult BeginGetBounces(string emailFilter, int offset, int count) - { - return BeginGetBouncesImpl(null, null, emailFilter, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public IAsyncResult BeginGetBounces(PostmarkBounceType type, string emailFilter, string tag, int offset, int count) - { - return BeginGetBouncesImpl(type, null, emailFilter, tag, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public IAsyncResult BeginGetBounces(string emailFilter, string tag, int offset, int count) - { - return BeginGetBouncesImpl(null, null, emailFilter, tag, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public IAsyncResult BeginGetBounces(PostmarkBounceType type, bool? inactive, string emailFilter, int offset, int count) - { - return BeginGetBouncesImpl(type, inactive, emailFilter, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public IAsyncResult BeginGetBounces(bool? inactive, string emailFilter, int offset, int count) - { - return BeginGetBouncesImpl(null, inactive, emailFilter, null, offset, count); - } - - private IAsyncResult BeginGetBouncesImpl(PostmarkBounceType? type, bool? inactive, string emailFilter, string tag, int offset, int count) - { - var request = NewBouncesRequest(); - request.Path = "bounces"; - if (inactive.HasValue) request.AddParameter("inactive", inactive.Value.ToString().ToLowerInvariant()); - if (!string.IsNullOrEmpty(emailFilter)) request.AddParameter("emailFilter", emailFilter); - if (!string.IsNullOrEmpty(tag)) request.AddParameter("tag", tag); - if(type.HasValue) - {request.AddParameter("type", type.ToString());} - request.AddParameter("offset", offset.ToString()); - request.AddParameter("count", count.ToString()); - - return _client.BeginRequest(request); - } - - /// - /// Completes an asynchronous request for a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - ///An for the desired response - /// - public PostmarkBounces EndGetBounces(IAsyncResult asyncResult) - { - return EndBounceRequest(asyncResult); - } - - /// - /// Retrieves a single based on a specified ID. - /// - /// The bounce ID - /// - /// - public IAsyncResult BeginGetBounce(string bounceId) - { - var request = NewBouncesRequest(); - request.Path = string.Format("bounces/{0}", bounceId); - - return _client.BeginRequest(request); - } - - /// - /// Completes an asynchronous request for a single based on a specified ID. - /// - /// An for the desired response - /// - public PostmarkBounce EndGetBounce(IAsyncResult asyncResult) - { - return EndBounceRequest(asyncResult); - } - - /// - /// Returns the raw source of the bounce we accepted. - /// If Postmark does not have a dump for that bounce, it will return an empty string. - /// - /// The bounce ID - /// - /// - public IAsyncResult BeginGetBounceDump(string bounceId) - { - var request = NewBouncesRequest(); - request.Path = string.Format("bounces/{0}/dump", bounceId.Trim()); - - return _client.BeginRequest(request); - } - - /// - /// Completes an asynchronous request for the raw source of the bounce we accepted. - /// - /// An for the desired response - /// - public PostmarkBounceDump EndGetBounceDump(IAsyncResult asyncResult) - { - return EndBounceRequest(asyncResult); - } - - /// - /// Activates a deactivated bounce. - /// - /// The bounce ID - /// - /// - public IAsyncResult BeginActivateBounce(string bounceId) - { - var request = NewBouncesRequest(); - request.Method = WebMethod.Put; - request.Path = string.Format("bounces/{0}/activate", bounceId.Trim()); - - return _client.BeginRequest(request); - } - - /// - /// Completes an asynchronous request for a deactivated bounce. - /// - /// - /// - public PostmarkBounceActivation EndActivateBounce(IAsyncResult asyncResult) - { - return EndBounceRequest(asyncResult); - } - - private T EndBounceRequest(IAsyncResult asyncResult) - { - var response = _client.EndRequest(asyncResult); - - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - #endregion - - #region Messages API - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Filter by message subject. - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - public IAsyncResult BeginGetOutboundMessages(int count, string subject, int offset) - { - return BeginGetOutboundMessagesImpl(null, null, null, subject, count, offset); - } - - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// Filter by the recipient(s) of the message. - /// IAsyncResult - /// - public IAsyncResult BeginGetOutboundMessages(int count, int offset, string recipient) - { - return BeginGetOutboundMessagesImpl(recipient, null, null, null, count, offset); - } - - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - public IAsyncResult BeginGetOutboundMessages(int count, int offset) - { - return BeginGetOutboundMessagesImpl(null, null, null, null, count, offset); - } - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - public IAsyncResult BeginGetOutboundMessages(string recipient, string fromemail, - int count, int offset) - { - return BeginGetOutboundMessagesImpl(recipient, fromemail, null, null, count, offset); - } - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - public IAsyncResult BeginGetOutboundMessages(string subject, int count, int offset) - { - return BeginGetOutboundMessagesImpl(null, null, null, subject, count, offset); - } - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Filter by a tag used for the message (messages sent directly through the API only) - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - public IAsyncResult BeginGetOutboundMessages(string fromemail, string tag, - string subject, int count, int offset) - { - return BeginGetOutboundMessagesImpl(null, fromemail, tag, subject, count, offset); - } - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by a tag used for the message (messages sent directly through the API only) - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - public IAsyncResult BeginGetOutboundMessages(string recipient, string fromemail, string tag, - string subject, int count, int offset) - { - return BeginGetOutboundMessagesImpl(recipient, fromemail, tag, subject, count, offset); - } - - /// - /// Implementation called to do the actual messages call and return a - /// s - private IAsyncResult BeginGetOutboundMessagesImpl(string recipient, string fromemail, string tag, string subject, int count, int offset) - { - var request = NewMessagesRequest(); - request.Path = "messages/outbound"; - - if (!string.IsNullOrEmpty(recipient)) request.AddParameter("recipient", recipient); - if (!string.IsNullOrEmpty(fromemail)) request.AddParameter("fromemail", fromemail); - if (!string.IsNullOrEmpty(tag)) request.AddParameter("tag", tag); - if (!string.IsNullOrEmpty(subject)) request.AddParameter("subject", subject); - - request.AddParameter("count", count.ToString()); - request.AddParameter("offset", offset.ToString()); - - return _client.BeginRequest(request); - } - - - /// - /// Completes an asynchronous request for a instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// An for the desired response - /// PostmarkOutboundMessageList - /// - public PostmarkOutboundMessageList EndGetOutboundMessages(IAsyncResult asyncResult) - { - var response = _client.EndRequest(asyncResult); - - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - - /// - /// Get the full details of a sent message including all fields, raw body, attachment names, etc - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetOutboundMessages call. - /// IAsyncResult - /// - public IAsyncResult BeginGetOutboundMessageDetail(string messageID) - { - var request = NewMessagesRequest(); - request.Path = string.Format("messages/outbound/{0}/details", messageID.Trim()); - - return _client.BeginRequest(request); - } - - /// - /// Completes an asynchronous request for a instance. - /// - /// An for the desired response - /// OutboundMessageDetail - /// - public OutboundMessageDetail EndGetOutboundMessageDetail(IAsyncResult asyncResult) - { - var response = _client.EndRequest(asyncResult); - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - - /// - /// Get the original raw message dump of on outbound message including all SMTP headers and data. - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetOutboundMessages call. - /// IAsyncResult - /// - public IAsyncResult BeginGetOutboundMessageDump(string messageID) - { - var request = NewMessagesRequest(); - request.Path = string.Format("messages/outbound/{0}/dump", messageID.Trim()); - - return _client.BeginRequest(request); - } - - /// - /// Completes an asynchronous request for a instance. - /// - /// An for the desired response - /// MessageDump - /// - public MessageDump EndGetOutboundMessageDump(IAsyncResult asyncResult) - { - var response = _client.EndRequest(asyncResult); - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - public IAsyncResult BeginGetInboundMessages(int count, int offset) - { - return BeginGetInboundMessagesImpl(null, null, null, null, count, offset); - } - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - public IAsyncResult BeginGetInboundMessages(string fromemail, int count, int offset) - { - return BeginGetInboundMessagesImpl(null, fromemail, null, null, count, offset); - } - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - public IAsyncResult BeginGetInboundMessages(string fromemail, string subject, int count, int offset) - { - return BeginGetInboundMessagesImpl(null, fromemail, subject, null, count, offset); - } - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - public IAsyncResult BeginGetInboundMessages(string recipient, string fromemail, string subject, int count, int offset) - { - return BeginGetInboundMessagesImpl(recipient, fromemail, subject, null, count, offset); - } - - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Filter by mailbox hash that was parsed from the inbound message. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// IAsyncResult - /// - public IAsyncResult BeginGetInboundMessages(string recipient, string fromemail, string subject, string mailboxhash, int count, int offset) - { - return BeginGetInboundMessagesImpl(recipient, fromemail, subject, mailboxhash, count, offset); - } - - - /// - /// Implementation to get Inbound messages for the public search APIs - /// - private IAsyncResult BeginGetInboundMessagesImpl(string recipient, string fromemail, string subject, string mailboxhash, int count, int offset) - { - var request = NewMessagesRequest(); - request.Path = "messages/inbound"; - - if (!string.IsNullOrEmpty(recipient)) request.AddParameter("recipient", recipient); - if (!string.IsNullOrEmpty(fromemail)) request.AddParameter("fromemail", fromemail); - if (!string.IsNullOrEmpty(subject)) request.AddParameter("subject", subject); - if (!string.IsNullOrEmpty(subject)) request.AddParameter("mailboxhash", mailboxhash); - - request.AddParameter("count", count.ToString()); - request.AddParameter("offset", offset.ToString()); - - return _client.BeginRequest(request); - } - - /// - /// Completes an asynchronous request for a instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// An for the desired response - /// PostmarkInboundMessageList - /// - public PostmarkInboundMessageList EndGetInboundMessages(IAsyncResult asyncResult) - { - var response = _client.EndRequest(asyncResult); - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - /// - /// Get the full details of a processed inbound message including all fields, attachment names, etc. - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetInboundMessages call. - /// IAsyncResult - /// - public IAsyncResult BeginGetInboundMessageDetail(string messageID) - { - var request = NewMessagesRequest(); - request.Path = string.Format("messages/inbound/{0}/details", messageID.Trim()); - - return _client.BeginRequest(request); - } - - /// - /// Completes an asynchronous request for a instance. - /// - /// An for the desired response - /// InboundMessageDetail - /// - public InboundMessageDetail EndGetInboundMessageDetail(IAsyncResult asyncResult) - { - var response = _client.EndRequest(asyncResult); - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - #endregion - - } -} -#endif \ No newline at end of file diff --git a/src/Postmark/PostmarkClient.Net20.cs b/src/Postmark/PostmarkClient.Net20.cs deleted file mode 100644 index 78f2f74..0000000 --- a/src/Postmark/PostmarkClient.Net20.cs +++ /dev/null @@ -1,1037 +0,0 @@ -#if NET20 -using System; -using System.Collections.Generic; -using Hammock; -using Hammock.Web; -using Newtonsoft.Json; -using PostmarkDotNet.Converters; -using PostmarkDotNet.Model; -using PostmarkDotNet.Validation; - -namespace PostmarkDotNet -{ - /// - /// A client for the Postmark application. - /// Use this client in place of an SmtpClient to send messages - /// through this service. - /// - public partial class PostmarkClient : IPostmarkClient - { - private static readonly JsonSerializerSettings _settings; - private static readonly PostmarkConverter _serializer; - private readonly RestClient _client; - - static PostmarkClient() - { - _settings = new JsonSerializerSettings - { - MissingMemberHandling = MissingMemberHandling.Ignore, - NullValueHandling = NullValueHandling.Include, - DefaultValueHandling = DefaultValueHandling.Include - }; - - _settings.Converters.Add(new UnicodeJsonStringConverter()); - _serializer = new PostmarkConverter(_settings); - } - - /// - /// Initializes a new instance of the class. - /// If you do not have a server token you can request one by signing up to - /// use Postmark: http://postmarkapp.com. - /// - /// The server token. - public PostmarkClient(string serverToken) - { - ServerToken = serverToken; - _client = new RestClient - { - Authority = "https://api.postmarkapp.com" - }; - } - - /// - /// Initializes a new instance of the class. - /// If you do not have a server token you can request one by signing up to - /// use Postmark: http://postmarkapp.com. - /// - /// The server token. - /// Time to wait for the API in seconds. - public PostmarkClient(string serverToken, int timeout) - { - ServerToken = serverToken; - - // Configure timespam from number of seconds the user wants to set the timeout for - TimeSpan timeoutInSeconds = DateTime.Now.AddSeconds(timeout).Subtract(DateTime.Now); - - _client = new RestClient - { - Authority = "https://api.postmarkapp.com", - Timeout = timeoutInSeconds - }; - } - - /// - /// Initializes a new instance of the class. - /// If you do not have a server token you can request one by signing up to - /// use Postmark: http://postmarkapp.com. - /// Extra signature to override https - /// - /// You can get a server token by signing up at http://www.postmarkapp.com - /// Skip https usage - public PostmarkClient(string serverToken, bool noSSL) - { - ServerToken = serverToken; - _client = new RestClient(); - - _client.Authority = noSSL ? "http://api.postmarkapp.com" : "https://api.postmarkapp.com"; - } - - /// - /// Override the REST API endpoint by specifying your own address, if necessary. - /// - public string Authority - { - get { return _client.Authority; } - set { _client.Authority = value; } - } - - /// - /// Gets the server token issued with your Postmark email server configuration. - /// - /// The server token. - public string ServerToken { get; private set; } - -#region Mail API - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// An email address for a sender. - /// An email address for a recipient. - /// The message subject line. - /// The message body. - /// The message body. - /// A with details about the transaction. - public PostmarkResponse SendMessage(string from, string to, string subject, string textbody, string htmlbody) - { - return SendMessage(from, to, subject, textbody, htmlbody); - } - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// An email address for a sender. - /// An email address for a recipient. - /// The message subject line. - /// The plain text body. Can be null if htmlbody is set. - /// The html text body. Can be null if textbody is set. - /// A collection of additional mail headers to send with the message. - /// A with details about the transaction. - public PostmarkResponse SendMessage(string from, string to, string subject, string textbody, string htmlbody, HeaderCollection headers) - { - var message = new PostmarkMessage(from, to, subject, textbody, htmlbody, headers); - - return SendMessage(message); - } - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message instance. - /// - public PostmarkResponse SendMessage(PostmarkMessage message) - { - var request = NewEmailRequest(); - - CleanPostmarkMessage(message); - - request.Entity = message; - - return GetPostmarkResponse(request); - } - - /// - /// Send an email using a template associated with your Server. - /// - /// - /// - public PostmarkResponse SendMessage(TemplatedPostmarkMessage message) - { - var request = NewTemplatedEmailRequest(); - request.Entity = message; - return GetPostmarkResponse(request); - } - - /// - /// Sends a batch of messages through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message batch. - /// - public IEnumerable SendMessages(params PostmarkMessage[] messages) - { - if (messages.Length > 500) - { - throw new ValidationException("You may only send up to 500 messages in a batched call"); - } - return SendMessages(messages); - } - - /// - /// Sends a batch of messages through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message batch. - /// - public IEnumerable SendMessages(IEnumerable messages) - { - var request = NewBatchedEmailRequest(); - var batch = new List(messages); - batch.ForEach(m => CleanPostmarkMessage(m)); - request.Entity = messages; - return GetPostmarkResponses(request); - } - -#endregion - -#region Bounce API - - /// - /// Retrieves the bounce-related results for the - /// associated mail server. - /// - /// - public PostmarkDeliveryStats GetDeliveryStats() - { - var request = NewBouncesRequest(); - request.Path = "deliverystats"; - - var response = _client.Request(request); - - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(bool? inactive, string emailFilter, string tag, int offset, int count) - { - return GetBouncesImpl(null, inactive, emailFilter, tag, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(PostmarkBounceType type, bool? inactive, string emailFilter, string tag, int offset, int count) - { - return GetBouncesImpl(type, inactive, emailFilter, tag, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(PostmarkBounceType type, int offset, int count) - { - return GetBouncesImpl(type, null, null, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(int offset, int count) - { - return GetBouncesImpl(null, null, null, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(PostmarkBounceType type, bool? inactive, int offset, int count) - { - return GetBouncesImpl(type, inactive, null, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(bool? inactive, int offset, int count) - { - return GetBouncesImpl(null, inactive, null, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(PostmarkBounceType type, string emailFilter, int offset, int count) - { - return GetBouncesImpl(type, null, emailFilter, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(string emailFilter, int offset, int count) - { - return GetBouncesImpl(null, null, emailFilter, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(PostmarkBounceType type, string emailFilter, string tag, int offset, int count) - { - return GetBouncesImpl(type, null, emailFilter, tag, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Filters based on whether the filter value is contained in the bounce source's email - /// Filters on the bounce tag - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(string emailFilter, string tag, int offset, int count) - { - return GetBouncesImpl(null, null, emailFilter, tag, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// The type of bounces to filter on - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(PostmarkBounceType type, bool? inactive, string emailFilter, int offset, int count) - { - return GetBouncesImpl(type, inactive, emailFilter, null, offset, count); - } - - /// - /// Retrieves a collection of instances along - /// with a sum total of bounces recorded by the server, based on filter parameters. - /// - /// Whether to return only inactive or active bounces; use null to return all bounces - /// Filters based on whether the filter value is contained in the bounce source's email - /// The page offset for the returned results; mandatory - /// The number of results to return by the page offset; mandatory. - /// - /// - public PostmarkBounces GetBounces(bool? inactive, string emailFilter, int offset, int count) - { - return GetBouncesImpl(null, inactive, emailFilter, null, offset, count); - } - - private PostmarkBounces GetBouncesImpl(PostmarkBounceType? type, bool? inactive, string emailFilter, string tag, int offset, int count) - { - var request = NewBouncesRequest(); - request.Path = "bounces"; - if (inactive.HasValue) request.AddParameter("inactive", inactive.Value.ToString().ToLowerInvariant()); - if (!string.IsNullOrEmpty(emailFilter)) request.AddParameter("emailFilter", emailFilter); - if (!string.IsNullOrEmpty(tag)) request.AddParameter("tag", tag); - if (type.HasValue) - { - request.AddParameter("type", type.ToString()); - } - request.AddParameter("offset", offset.ToString()); - request.AddParameter("count", count.ToString()); - - var response = _client.Request(request); - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - /// - /// Retrieves a single based on a specified ID. - /// - /// The bounce ID - /// - /// - public PostmarkBounce GetBounce(string bounceId) - { - var request = NewBouncesRequest(); - request.Path = string.Format("bounces/{0}", bounceId); - - var response = _client.Request(request); - - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - /// - /// Returns the raw source of the bounce we accepted. - /// If Postmark does not have a dump for that bounce, it will return an empty string. - /// - /// The bounce ID - /// - /// - public PostmarkBounceDump GetBounceDump(string bounceId) - { - var request = NewBouncesRequest(); - request.Path = string.Format("bounces/{0}/dump", bounceId.Trim()); - - var response = _client.Request(request); - - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - /// - /// Activates a deactivated bounce. - /// - /// The bounce ID - /// - /// - public PostmarkBounceActivation ActivateBounce(string bounceId) - { - var request = NewBouncesRequest(); - request.Method = WebMethod.Put; - request.Path = string.Format("bounces/{0}/activate", bounceId.Trim()); - - var response = _client.Request(request); - - return JsonConvert.DeserializeObject(response.Content, _settings); - } - -#endregion - -#region Messages API - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Filter by message subject. - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - public PostmarkOutboundMessageList GetOutboundMessages(int count, string subject, int offset) - { - return GetOutboundMessagesImpl(null, null, null, subject, count, offset); - } - - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// Filter by the recipient(s) of the message. - /// PostmarkOutboundMessageList - public PostmarkOutboundMessageList GetOutboundMessages(int count, int offset, string recipient) - { - return GetOutboundMessagesImpl(recipient, null, null, null, count, offset); - } - - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - public PostmarkOutboundMessageList GetOutboundMessages(int count, int offset) - { - return GetOutboundMessagesImpl(null, null, null, null, count, offset); - } - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - public PostmarkOutboundMessageList GetOutboundMessages(string recipient, string fromemail, - int count, int offset) - { - return GetOutboundMessagesImpl(recipient, fromemail, null, null, count, offset); - } - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - public PostmarkOutboundMessageList GetOutboundMessages(string subject, int count, int offset) - { - return GetOutboundMessagesImpl(null, null, null, subject, count, offset); - } - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Filter by a tag used for the message (messages sent directly through the API only) - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - public PostmarkOutboundMessageList GetOutboundMessages(string fromemail, string tag, - string subject, int count, int offset) - { - return GetOutboundMessagesImpl(null, fromemail, tag, subject, count, offset); - } - - /// - /// Return a listing of Outbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by a tag used for the message (messages sent directly through the API only) - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkOutboundMessageList - public PostmarkOutboundMessageList GetOutboundMessages(string recipient, string fromemail, string tag, - string subject, int count, int offset) - { - return GetOutboundMessagesImpl(recipient, fromemail, tag, subject, count, offset); - } - - - /// - /// Implementation called to do the actual messages call and return a - /// s - private PostmarkOutboundMessageList GetOutboundMessagesImpl(string recipient, string fromemail, string tag, string subject, int count, int offset) - { - if (count > 500) - { - throw new ValidationException("You can only receive up to 500 messages per call."); - } - - var request = NewMessagesRequest(); - request.Path = "messages/outbound"; - - if (!string.IsNullOrEmpty(recipient)) request.AddParameter("recipient", recipient); - if (!string.IsNullOrEmpty(fromemail)) request.AddParameter("fromemail", fromemail); - if (!string.IsNullOrEmpty(tag)) request.AddParameter("tag", tag); - if (!string.IsNullOrEmpty(subject)) request.AddParameter("subject", subject); - - request.AddParameter("count", count.ToString()); - request.AddParameter("offset", offset.ToString()); - - var response = _client.Request(request); - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - /// - /// Get the full details of a sent message including all fields, raw body, attachment names, etc - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetOutboundMessages call. - /// OutboundMessageDetail - public OutboundMessageDetail GetOutboundMessageDetail(string messageID) - { - var request = NewMessagesRequest(); - request.Path = string.Format("messages/outbound/{0}/details", messageID.Trim()); - - var response = _client.Request(request); - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - /// - /// Get the original raw message dump of on outbound message including all SMTP headers and data. - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetOutboundMessages call. - /// MessageDump - public MessageDump GetOutboundMessageDump(string messageID) - { - var request = NewMessagesRequest(); - request.Path = string.Format("messages/outbound/{0}/dump", messageID.Trim()); - - var response = _client.Request(request); - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkInboundMessageList - public PostmarkInboundMessageList GetInboundMessages(int count, int offset) - { - return GetInboundMessagesImpl(null, null, null, null, count, offset); - } - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkInboundMessageList - public PostmarkInboundMessageList GetInboundMessages(string fromemail, int count, int offset) - { - return GetInboundMessagesImpl(null, fromemail, null, null, count, offset); - } - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkInboundMessageList - public PostmarkInboundMessageList GetInboundMessages(string fromemail, string subject, int count, int offset) - { - return GetInboundMessagesImpl(null, fromemail, subject, null, count, offset); - } - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkInboundMessageList - public PostmarkInboundMessageList GetInboundMessages(string recipient, string fromemail, string subject, int count, int offset) - { - return GetInboundMessagesImpl(recipient, fromemail, subject, null, count, offset); - } - - - /// - /// Return a listing of Inbound sent messages using the filters supported by the API. - /// - /// Filter by the recipient(s) of the message. - /// Filter by the email address the message is sent from. - /// Filter by message subject. - /// Filter by mailbox hash that was parsed from the inbound message. - /// Number of messages to return per call. (required) - /// Number of messages to offset/page per call. (required) - /// PostmarkInboundMessageList - public PostmarkInboundMessageList GetInboundMessages(string recipient, string fromemail, string subject, string mailboxhash, int count, int offset) - { - return GetInboundMessagesImpl(recipient, fromemail, subject, mailboxhash, count, offset); - } - - /// - /// Implementation to get Inbound messages for the public search APIs - /// - private PostmarkInboundMessageList GetInboundMessagesImpl(string recipient, string fromemail, string subject, string mailboxhash, int count, int offset) - { - if (count > 500) - { - throw new ValidationException("You can only receive up to 500 messages per call."); - } - - var request = NewMessagesRequest(); - request.Path = "messages/inbound"; - - if (!string.IsNullOrEmpty(recipient)) request.AddParameter("recipient", recipient); - if (!string.IsNullOrEmpty(fromemail)) request.AddParameter("fromemail", fromemail); - if (!string.IsNullOrEmpty(subject)) request.AddParameter("subject", subject); - if (!string.IsNullOrEmpty(subject)) request.AddParameter("mailboxhash", mailboxhash); - - request.AddParameter("count", count.ToString()); - request.AddParameter("offset", offset.ToString()); - - var response = _client.Request(request); - return JsonConvert.DeserializeObject(response.Content, _settings); - } - - /// - /// Get the full details of a processed inbound message including all fields, attachment names, etc. - /// - /// The MessageID of a message which can be optained either from the initial API send call or a GetInboundMessages call. - /// InboundMessageDetail - public InboundMessageDetail GetInboundMessageDetail(string messageID) - { - var request = NewMessagesRequest(); - request.Path = string.Format("messages/inbound/{0}/details", messageID.Trim()); - - var response = _client.Request(request); - return JsonConvert.DeserializeObject(response.Content, _settings); - } - -#endregion - - private void SetPostmarkMeta(RestBase request) - { - request.AddHeader("Accept", "application/json"); - request.AddHeader("Content-Type", "application/json; charset=utf-8"); - request.AddHeader("X-Postmark-Server-Token", ServerToken); - request.AddHeader("User-Agent", "Postmark.NET 1.x (" + this.GetType().AssemblyQualifiedName + ")"); - } - - private static void CleanPostmarkMessage(PostmarkMessage message) - { - if (!string.IsNullOrEmpty(message.From)) - { - message.From = message.From.Trim(); - } - if (!string.IsNullOrEmpty(message.To)) - { - message.To = message.To.Trim(); - } - message.Subject = message.Subject != null ? message.Subject.Trim() : ""; - } - - private PostmarkResponse GetPostmarkResponse(RestRequest request) - { - var response = _client.Request(request); - - return GetPostmarkResponseImpl(response); - } - - private IEnumerable GetPostmarkResponses(RestRequest request) - { - var response = _client.Request(request); - - return GetPostmarkResponsesImpl(response); - } - - - private static IEnumerable GetPostmarkResponsesImpl(RestResponseBase response) - { - var results = TryGetPostmarkResponses(response) ?? new List - { - new PostmarkResponse - { - Status = PostmarkStatus.Unknown, - Message = response.StatusDescription - } - }; - - foreach (var result in results) - { - switch ((int)response.StatusCode) - { - case 200: - result.Status = PostmarkStatus.Success; - break; - case 401: - case 422: - result.Status = PostmarkStatus.UserError; - break; - case 500: - result.Status = PostmarkStatus.ServerError; - break; - } - } - - return results; - } - - private static PostmarkResponse GetPostmarkResponseImpl(RestResponseBase response) - { - var result = TryGetPostmarkResponse(response) ?? new PostmarkResponse - { - Status = PostmarkStatus.Unknown, - Message = response.StatusDescription - }; - - switch ((int)response.StatusCode) - { - case 200: - result.Status = PostmarkStatus.Success; - break; - case 401: - case 422: - result.Status = PostmarkStatus.UserError; - break; - case 500: - result.Status = PostmarkStatus.ServerError; - break; - } - - return result; - } - - private static PostmarkResponse TryGetPostmarkResponse(RestResponseBase response) - { - PostmarkResponse result = null; - var statusCode = (int)response.StatusCode; - if (statusCode == 200 || statusCode == 401 || statusCode == 422 || statusCode == 500) - { - try - { - result = JsonConvert.DeserializeObject(response.Content, _settings); - } - catch (JsonReaderException) - { - result = null; - } - } - return result; - } - - private static IEnumerable TryGetPostmarkResponses(RestResponseBase response) - { - IEnumerable result = null; - var statusCode = (int)response.StatusCode; - if (statusCode == 200 || statusCode == 401 || statusCode == 422 || statusCode == 500) - { - try - { - result = JsonConvert.DeserializeObject>(response.Content, _settings); - } - catch (JsonReaderException) - { - result = null; - } - } - return result; - } - - private RestRequest NewBouncesRequest() - { - var request = new RestRequest - { - Serializer = _serializer - }; - - SetPostmarkMeta(request); - - return request; - } - - private RestRequest NewEmailRequest() - { - var request = new RestRequest - { - Path = "email", - Method = WebMethod.Post, - Serializer = _serializer - }; - - SetPostmarkMeta(request); - - return request; - } - - private RestRequest NewTemplatedEmailRequest() - { - var request = new RestRequest - { - Path = "email/withTemplate", - Method = WebMethod.Post, - Serializer = _serializer - }; - - SetPostmarkMeta(request); - - return request; - } - - - private RestRequest NewBatchedEmailRequest() - { - var request = new RestRequest - { - Path = "email/batch", - Method = WebMethod.Post, - Serializer = _serializer - }; - - SetPostmarkMeta(request); - - return request; - } - - private RestRequest NewMessagesRequest() - { - var request = new RestRequest - { - Method = WebMethod.Get, - Serializer = _serializer - }; - - SetPostmarkMeta(request); - - return request; - } - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// An email address for a sender. - /// An email address for a recipient. - /// The message subject line. - /// The plain text message body. This may be null, if htmlBody is set. - /// The plain HTML message body. This may be null, if textBody is set. - /// The callback invoked when a is received from the API - public void SendMessage(string from, string to, string subject, string textBody, string htmlBody, Action callback) - { - SendMessage(from, to, subject, textBody, htmlBody, callback); - } - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// An email address for a sender - /// An email address for a recipient - /// The message subject line - /// The plain text message body. This may be null, if htmlBody is set. - /// The plain HTML message body. This may be null, if textBody is set. - /// A collection of additional mail headers to send with the message - /// The callback invoked when a response is received from the API - /// A with details about the transaction - public void SendMessage(string from, string to, string subject, string textBody, string htmlBody, HeaderCollection headers, Action callback) - { - var message = new PostmarkMessage(from, to, subject, textBody, htmlBody, headers); - SendMessage(message, callback); - } - - /// - /// Sends a message through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message instance - /// The callback invoked when a response is received from the API - public void SendMessage(PostmarkMessage message, Action callback) - { - var request = NewEmailRequest(); - - CleanPostmarkMessage(message); - - request.Entity = message; - - BeginGetPostmarkResponse(request, callback); - } - - /// - /// Sends a batch of up to messages through the Postmark API. - /// All email addresses must be valid, and the sender must be - /// a valid sender signature according to Postmark. To obtain a valid - /// sender signature, log in to Postmark and navigate to: - /// http://postmarkapp.com/signatures. - /// - /// A prepared message batch. - /// The callback invoked when a response is received from the API - public void SendMessages(IEnumerable messages, Action> callback) - { - var request = NewBatchedEmailRequest(); - var batch = new List(messages); - batch.ForEach(m => CleanPostmarkMessage(m)); - - request.Entity = messages; - - BeginGetPostmarkResponses(request, callback); - } - - private void BeginGetPostmarkResponse(RestRequest request, Action callback) - { - _client.BeginRequest(request, new RestCallback((req, resp, state) => - { - var postmark = GetPostmarkResponseImpl(resp); - - callback(postmark); - })); - } - - private void BeginGetPostmarkResponses(RestRequest request, Action> callback) - { - _client.BeginRequest(request, new RestCallback((req, resp, state) => - { - var postmark = GetPostmarkResponsesImpl(resp); - - callback(postmark); - })); - } - } -} -#endif \ No newline at end of file diff --git a/src/Postmark/PostmarkClient.cs b/src/Postmark/PostmarkClient.cs index 647b762..089be57 100644 --- a/src/Postmark/PostmarkClient.cs +++ b/src/Postmark/PostmarkClient.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json.Linq; using PostmarkDotNet.Model; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; +using System.Text.Json; using System.Threading.Tasks; using Postmark.Model.MessageStreams; using Postmark.Model.Suppressions; @@ -595,7 +595,7 @@ public async Task GetOutboundPlatformCountsAsync( public async Task GetOutboundClientUsageCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null) { var parameters = ConstructSentStatsFilter(tag, fromDate, toDate); - var result = await this.ProcessNoBodyRequestAsync>("/stats/outbound/opens/emailclients", parameters); + var result = await this.ProcessNoBodyRequestAsync>("/stats/outbound/opens/emailclients", parameters); var retval = new PostmarkOutboundClientStats(); var clientCounts = new Dictionary(); @@ -603,25 +603,24 @@ public async Task GetOutboundClientUsageCountsAsync { if (a.Key != "Days") { - clientCounts[a.Key] = (int)(long)a.Value; + clientCounts[a.Key] = a.Value.GetInt32(); } } retval.ClientCounts = clientCounts; - var dayCount = (JArray)result["Days"]; var dayList = new List(); - foreach (var obj in dayCount) + foreach (var obj in result["Days"].EnumerateArray()) { var newCount = new PostmarkOutboundClientStats.DatedClientCount(); - foreach (var i in (JObject)obj) + foreach (var i in obj.EnumerateObject()) { - if (i.Key == "Date") + if (i.Name == "Date") { - newCount.Date = DateTime.Parse(i.Value.ToString()); + newCount.Date = DateTime.Parse(i.Value.GetString()); } else { - newCount.ClientCounts[i.Key] = (int)(long)i.Value; + newCount.ClientCounts[i.Name] = i.Value.GetInt32(); } } dayList.Add(newCount); @@ -642,7 +641,7 @@ public async Task GetOutboundClientUsageCountsAsync public async Task GetOutboundReadtimeStatsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null) { var parameters = ConstructSentStatsFilter(tag, fromDate, toDate); - var result = await this.ProcessNoBodyRequestAsync>("/stats/outbound/opens/readtimes", parameters); + var result = await this.ProcessNoBodyRequestAsync>("/stats/outbound/opens/readtimes", parameters); var retval = new PostmarkOutboundReadStats(); var clientCounts = new Dictionary(); @@ -650,25 +649,24 @@ public async Task GetOutboundReadtimeStatsAsync(strin { if (a.Key != "Days") { - clientCounts[a.Key] = (int)(long)a.Value; + clientCounts[a.Key] = a.Value.GetInt32(); } } retval.ReadCounts = clientCounts; - var dayCount = (JArray)result["Days"]; var dayList = new List(); - foreach (var obj in dayCount) + foreach (var obj in result["Days"].EnumerateArray()) { var newCount = new PostmarkOutboundReadStats.DatedReadCount(); - foreach (var i in (JObject)obj) + foreach (var i in obj.EnumerateObject()) { - if (i.Key == "Date") + if (i.Name == "Date") { newCount.Date = DateTime.Parse(i.Value.ToString()); } else { - newCount.ReadCounts[i.Key] = (int)(long)i.Value; + newCount.ReadCounts[i.Name] = i.Value.GetInt32(); } } dayList.Add(newCount); diff --git a/src/Postmark/PostmarkClientBase.cs b/src/Postmark/PostmarkClientBase.cs index fc8e0a9..4fe9a8b 100644 --- a/src/Postmark/PostmarkClientBase.cs +++ b/src/Postmark/PostmarkClientBase.cs @@ -88,13 +88,13 @@ protected async Task ProcessRequestAsync( var body = await result.Content.ReadAsStringAsync(); - if (JsonNetExtensions.TryDeserializeObject(body, out TResponse parsedResponse) + if (JsonExtensions.TryDeserializeObject(body, out TResponse parsedResponse) && result.StatusCode == HttpStatusCode.OK) { return parsedResponse; } - if (!JsonNetExtensions.TryDeserializeObject(body, out PostmarkResponse error)) + if (!JsonExtensions.TryDeserializeObject(body, out PostmarkResponse error)) { throw new PostmarkResponseException("The response from the API could not be parsed.", body); } diff --git a/src/Postmark/Utility/JsonContent.cs b/src/Postmark/Utility/JsonContent.cs index 77be45e..ccaeea2 100644 --- a/src/Postmark/Utility/JsonContent.cs +++ b/src/Postmark/Utility/JsonContent.cs @@ -1,8 +1,7 @@ -using Newtonsoft.Json; -using PostmarkDotNet.Converters; -using System; +using PostmarkDotNet.Converters; using System.Net.Http; using System.Text; +using System.Text.Json; namespace PostmarkDotNet.Utility { @@ -11,21 +10,14 @@ namespace PostmarkDotNet.Utility /// internal class JsonContent : StringContent { - private static Lazy _settings = new Lazy(() => + private static JsonSerializerOptions _settings = new JsonSerializerOptions { - var retval = new JsonSerializerSettings() - { - MissingMemberHandling = MissingMemberHandling.Ignore, - NullValueHandling = NullValueHandling.Include, - DefaultValueHandling = DefaultValueHandling.Include - }; - - retval.Converters.Add(new UnicodeJsonStringConverter()); - return retval; - }); + WriteIndented = true, + Converters = { new UnicodeJsonStringConverter() } + }; internal JsonContent(T content) : - base(JsonConvert.SerializeObject(content, Formatting.Indented, _settings.Value), + base(JsonSerializer.Serialize(content, _settings), Encoding.UTF8, "application/json") { }