From 727f695d6653e886ab7437f73d5a16f53db83dbf Mon Sep 17 00:00:00 2001 From: Brandon seydel Date: Thu, 28 Mar 2019 16:09:03 -0500 Subject: [PATCH] #381 - Added ping --- MailChimp.Net.Tests/ApiTest.cs | 8 ++++++++ MailChimp.Net/Core/Constants.cs | 13 +++++++++++++ MailChimp.Net/Interfaces/IApiLogic.cs | 4 +++- MailChimp.Net/Logic/ApiLogic.cs | 11 +++++++++++ MailChimp.Net/Models/Ping.cs | 22 ++++++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 MailChimp.Net/Core/Constants.cs create mode 100644 MailChimp.Net/Models/Ping.cs diff --git a/MailChimp.Net.Tests/ApiTest.cs b/MailChimp.Net.Tests/ApiTest.cs index a359cf88..53ccaf5b 100644 --- a/MailChimp.Net.Tests/ApiTest.cs +++ b/MailChimp.Net.Tests/ApiTest.cs @@ -5,6 +5,7 @@ // -------------------------------------------------------------------------------------------------------------------- using System.Threading.Tasks; +using MailChimp.Net.Core; using Xunit; namespace MailChimp.Net.Tests @@ -26,5 +27,12 @@ public async Task Should_Return_API_Information() var apiInfo = await this.MailChimpManager.Api.GetInfoAsync().ConfigureAwait(false); Assert.NotNull(apiInfo); } + + [Fact] + public async Task Should_Return_String_From_Ping() + { + var ping = await this.MailChimpManager.Api.PingAsync().ConfigureAwait(false); + Assert.Equal(ping.HealthStatus, Constants.MailChimpHealthCheck); + } } } \ No newline at end of file diff --git a/MailChimp.Net/Core/Constants.cs b/MailChimp.Net/Core/Constants.cs new file mode 100644 index 00000000..1e040973 --- /dev/null +++ b/MailChimp.Net/Core/Constants.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MailChimp.Net.Core +{ + public static class Constants + { + public const string MailChimpHealthCheck = "Everything's Chimpy!"; + } +} diff --git a/MailChimp.Net/Interfaces/IApiLogic.cs b/MailChimp.Net/Interfaces/IApiLogic.cs index b7051928..2a124d0d 100644 --- a/MailChimp.Net/Interfaces/IApiLogic.cs +++ b/MailChimp.Net/Interfaces/IApiLogic.cs @@ -1,4 +1,4 @@ -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // N/A // @@ -22,5 +22,7 @@ public interface IApiLogic /// The . /// Task GetInfoAsync(); + + Task PingAsync(); } } \ No newline at end of file diff --git a/MailChimp.Net/Logic/ApiLogic.cs b/MailChimp.Net/Logic/ApiLogic.cs index de8e5826..484e9944 100644 --- a/MailChimp.Net/Logic/ApiLogic.cs +++ b/MailChimp.Net/Logic/ApiLogic.cs @@ -47,5 +47,16 @@ public async Task GetInfoAsync() return await response.Content.ReadAsAsync().ConfigureAwait(false); } } + + public async Task PingAsync() + { + using (var client = CreateMailClient("/ping")) + { + var response = await client.GetAsync(string.Empty).ConfigureAwait(false); + await response.EnsureSuccessMailChimpAsync().ConfigureAwait(false); + + return await response.Content.ReadAsAsync().ConfigureAwait(false); + } + } } } \ No newline at end of file diff --git a/MailChimp.Net/Models/Ping.cs b/MailChimp.Net/Models/Ping.cs new file mode 100644 index 00000000..f2b204a2 --- /dev/null +++ b/MailChimp.Net/Models/Ping.cs @@ -0,0 +1,22 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// N/A +// +// -------------------------------------------------------------------------------------------------------------------- +using Newtonsoft.Json; + +namespace MailChimp.Net.Models +{ + /// + /// The ping response + /// + public class Ping + { + + /// + /// Gets the health status from Mail Chimp + /// + [JsonProperty("health_status")] + public string HealthStatus { get; set; } + } +} \ No newline at end of file