Skip to content

Commit

Permalink
#381 - Added ping
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonseydel committed Mar 28, 2019
1 parent 7b9e36c commit 727f695
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
8 changes: 8 additions & 0 deletions MailChimp.Net.Tests/ApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------

using System.Threading.Tasks;
using MailChimp.Net.Core;
using Xunit;

namespace MailChimp.Net.Tests
Expand All @@ -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);
}
}
}
13 changes: 13 additions & 0 deletions MailChimp.Net/Core/Constants.cs
Original file line number Diff line number Diff line change
@@ -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!";
}
}
4 changes: 3 additions & 1 deletion MailChimp.Net/Interfaces/IApiLogic.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IApiLogic.cs" company="Brandon Seydel">
// N/A
// </copyright>
Expand All @@ -22,5 +22,7 @@ public interface IApiLogic
/// The <see cref="Task"/>.
/// </returns>
Task<ApiInfo> GetInfoAsync();

Task<Ping> PingAsync();
}
}
11 changes: 11 additions & 0 deletions MailChimp.Net/Logic/ApiLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,16 @@ public async Task<ApiInfo> GetInfoAsync()
return await response.Content.ReadAsAsync<ApiInfo>().ConfigureAwait(false);
}
}

public async Task<Ping> 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<Ping>().ConfigureAwait(false);
}
}
}
}
22 changes: 22 additions & 0 deletions MailChimp.Net/Models/Ping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ApiResponse.cs" company="Brandon Seydel">
// N/A
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using Newtonsoft.Json;

namespace MailChimp.Net.Models
{
/// <summary>
/// The ping response
/// </summary>
public class Ping
{

/// <summary>
/// Gets the health status from Mail Chimp
/// </summary>
[JsonProperty("health_status")]
public string HealthStatus { get; set; }
}
}

0 comments on commit 727f695

Please sign in to comment.