Skip to content

Commit

Permalink
Ingest JSON for IP pool address
Browse files Browse the repository at this point in the history
Resolves #239
  • Loading branch information
Jericho committed Aug 14, 2018
1 parent 7e2a13e commit 94f00fc
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 11 deletions.
13 changes: 9 additions & 4 deletions Source/StrongGrid.UnitTests/Resources/IpPoolsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ public class IpPoolsTests

private const string SINGLE_IPPOOL_JSON = @"{
'name': 'marketing',
'ips': ['1.1.1.1','2.2.2.2','3.3.3.3']
'ips':
[
{ 'ip': '1.1.1.1', 'start_date': null, 'warmup': false },
{ 'ip': '2.2.2.2', 'start_date': null, 'warmup': false },
{ 'ip': '3.3.3.3', 'start_date': null, 'warmup': false }
]
}";

#endregion
Expand All @@ -36,9 +41,9 @@ public void Parse_json()
result.ShouldNotBeNull();
result.Name.ShouldBe("marketing");
result.IpAddresses.Length.ShouldBe(3);
result.IpAddresses[0].ShouldBe("1.1.1.1");
result.IpAddresses[1].ShouldBe("2.2.2.2");
result.IpAddresses[2].ShouldBe("3.3.3.3");
result.IpAddresses[0].Address.ShouldBe("1.1.1.1");
result.IpAddresses[1].Address.ShouldBe("2.2.2.2");
result.IpAddresses[2].Address.ShouldBe("3.3.3.3");
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions Source/StrongGrid.UnitTests/Warmup/WarmupEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public async Task PrepareWithNewIpAddressesAsync_addresses_added_to_account_and_
.ReturnsAsync(new IpPool() { Name = poolName });
mockIpPoolsResource
.Setup(r => r.AddAddressAsync(poolName, ipAddresses[0], It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(true));
.Returns(Task.FromResult(new IpPoolAddress() { Address = ipAddresses[0], WarmupStartedOn = null, Warmup = false }));
mockIpPoolsResource
.Setup(r => r.AddAddressAsync(poolName, ipAddresses[1], It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(true));
.Returns(Task.FromResult(new IpPoolAddress() { Address = ipAddresses[1], WarmupStartedOn = null, Warmup = false }));

var mockClient = new Mock<IClient>(MockBehavior.Strict);
mockClient.SetupGet(c => c.IpAddresses).Returns(mockIpAddressesResource.Object);
Expand Down
2 changes: 1 addition & 1 deletion Source/StrongGrid/Models/IpAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class IpAddress
/// </value>
[JsonProperty("start_date", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(EpochConverter))]
public DateTime WarmupStartedOn { get; set; }
public DateTime? WarmupStartedOn { get; set; }

/// <summary>
/// Gets or sets the date that the IP address was assigned to the user.
Expand Down
2 changes: 1 addition & 1 deletion Source/StrongGrid/Models/IpPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public class IpPool
/// The IP addresses.
/// </value>
[JsonProperty("ips", NullValueHandling = NullValueHandling.Ignore)]
public string[] IpAddresses { get; set; }
public IpPoolAddress[] IpAddresses { get; set; }
}
}
40 changes: 40 additions & 0 deletions Source/StrongGrid/Models/IpPoolAddress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Newtonsoft.Json;
using StrongGrid.Utilities;
using System;

namespace StrongGrid.Models
{
/// <summary>
/// Information about an IP address in an IP pool.
/// </summary>
public class IpPoolAddress
{
/// <summary>
/// Gets or sets the IP address.
/// </summary>
/// <value>
/// The IP address.
/// </value>
[JsonProperty("ip", NullValueHandling = NullValueHandling.Ignore)]
public string Address { get; set; }

/// <summary>
/// Gets or sets the date that the IP address was entered into warmup.
/// </summary>
/// <value>
/// The cost.
/// </value>
[JsonProperty("start_date", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(EpochConverter))]
public DateTime? WarmupStartedOn { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the IP address is currently warming up.
/// </summary>
/// <value>
/// The warmup indicator.
/// </value>
[JsonProperty("warmup", NullValueHandling = NullValueHandling.Ignore)]
public bool Warmup { get; set; }
}
}
2 changes: 1 addition & 1 deletion Source/StrongGrid/Resources/IIpPools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface IIpPools
/// <returns>
/// The async task.
/// </returns>
Task AddAddressAsync(string name, string address, CancellationToken cancellationToken = default(CancellationToken));
Task<IpPoolAddress> AddAddressAsync(string name, string address, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Remove an address from an IP pool.
Expand Down
4 changes: 2 additions & 2 deletions Source/StrongGrid/Resources/IpPools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public Task DeleteAsync(string name, CancellationToken cancellationToken = defau
/// <returns>
/// The async task.
/// </returns>
public Task AddAddressAsync(string name, string address, CancellationToken cancellationToken = default(CancellationToken))
public Task<IpPoolAddress> AddAddressAsync(string name, string address, CancellationToken cancellationToken = default(CancellationToken))
{
var data = new JObject()
{
Expand All @@ -141,7 +141,7 @@ public Task AddAddressAsync(string name, string address, CancellationToken cance
.PostAsync($"{_endpoint}/{name}/ips")
.WithJsonBody(data)
.WithCancellationToken(cancellationToken)
.AsMessage();
.AsSendGridObject<IpPoolAddress>();
}

/// <summary>
Expand Down

0 comments on commit 94f00fc

Please sign in to comment.