Skip to content

Commit

Permalink
Restructured Zone classes for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
JSkimming committed Sep 4, 2015
1 parent 917a3ae commit 535ccdd
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 109 deletions.
9 changes: 5 additions & 4 deletions src/CloudFlare.NET/CloudFlare.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,24 @@
<Compile Include="DnsRecordOrderTypes.cs" />
<Compile Include="DnsRecordType.cs" />
<Compile Include="HttpClientExtensions.cs" />
<Compile Include="HttpClientZoneExtensions.cs" />
<Compile Include="ICloudFlareClient.cs" />
<Compile Include="IdentifierTag.cs" />
<Compile Include="IdentifierTag.IEquatable.cs" />
<Compile Include="IIdentifier.cs" />
<Compile Include="IModified.cs" />
<Compile Include="IZoneClient.cs" />
<Compile Include="PagedParameters.cs" />
<Compile Include="PagedParametersExtensions.cs" />
<Compile Include="PagedParametersMatchType.cs" />
<Compile Include="PagedParametersOrderType.cs" />
<Compile Include="PagedZoneOrderFieldTypes.cs" />
<Compile Include="PagedZoneParameters.cs" />
<Compile Include="Serialization\IsoDateTimeOffsetConverter.cs" />
<Compile Include="Serialization\ToStringJsonConverter.cs" />
<Compile Include="Zone.cs" />
<Compile Include="ZoneClient.Implementation.cs" />
<Compile Include="ZoneClient.Interface.cs" />
<Compile Include="ZoneClientExtensions.cs" />
<Compile Include="ZoneGetParameters.cs" />
<Compile Include="ZoneHttpClientExtensions.cs" />
<Compile Include="ZoneOrderTypes.cs" />
<Compile Include="ZoneStatusType.cs" />
<None Include="app.config" />
<None Include="CloudFlare.NET.nuspec" />
Expand Down
32 changes: 0 additions & 32 deletions src/CloudFlare.NET/CloudFlareClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,38 +141,6 @@ public static HttpClientHandler CreateDefaultHttpClientHandler()
return handler;
}

/// <inheritdoc/>
public Task<CloudFlareResponse<IReadOnlyList<Zone>>> GetZonesAsync(
CancellationToken cancellationToken,
PagedZoneParameters parameters = null,
CloudFlareAuth auth = null)
{
return _client.GetZonesAsync(cancellationToken, auth ?? _auth, parameters);
}

/// <inheritdoc/>
public Task<IEnumerable<Zone>> GetAllZonesAsync(
CancellationToken cancellationToken,
PagedZoneParameters parameters = null,
CloudFlareAuth auth = null)
{
return GetAllPagedResultsAsync<Zone, PagedZoneParameters, PagedZoneOrderFieldTypes>(
_client.GetZonesAsync,
cancellationToken,
auth ?? _auth,
50,
parameters);
}

/// <inheritdoc/>
public Task<Zone> GetZoneAsync(
IdentifierTag zoneId,
CancellationToken cancellationToken,
CloudFlareAuth auth = null)
{
return _client.GetZoneAsync(zoneId, cancellationToken, auth ?? _auth);
}

private static async Task<IEnumerable<TResult>> GetAllPagedResultsAsync<TResult, TParams, TOrder>(
Func<CancellationToken, CloudFlareAuth, TParams, Task<CloudFlareResponse<IReadOnlyList<TResult>>>> request,
CancellationToken cancellationToken,
Expand Down
44 changes: 44 additions & 0 deletions src/CloudFlare.NET/ZoneClient.Implementation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace CloudFlare.NET
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

/// <inheritdoc/>
public partial class CloudFlareClient : IZoneClient
{
/// <inheritdoc/>
public Task<CloudFlareResponse<IReadOnlyList<Zone>>> GetZonesAsync(
CancellationToken cancellationToken,
ZoneGetParameters parameters = null,
CloudFlareAuth auth = null)
{
return _client.GetZonesAsync(cancellationToken, auth ?? _auth, parameters);
}

/// <inheritdoc/>
public Task<IEnumerable<Zone>> GetAllZonesAsync(
CancellationToken cancellationToken,
ZoneGetParameters parameters = null,
CloudFlareAuth auth = null)
{
return GetAllPagedResultsAsync<Zone, ZoneGetParameters, ZoneOrderTypes>(
_client.GetZonesAsync,
cancellationToken,
auth ?? _auth,
50,
parameters);
}

/// <inheritdoc/>
public Task<Zone> GetZoneAsync(
IdentifierTag zoneId,
CancellationToken cancellationToken,
CloudFlareAuth auth = null)
{
return _client.GetZoneAsync(zoneId, cancellationToken, auth ?? _auth);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IZoneClient
/// <seealso href="https://api.cloudflare.com/#zone-list-zones"/>
Task<CloudFlareResponse<IReadOnlyList<Zone>>> GetZonesAsync(
CancellationToken cancellationToken,
PagedZoneParameters parameters = null,
ZoneGetParameters parameters = null,
CloudFlareAuth auth = null);

/// <summary>
Expand All @@ -27,7 +27,7 @@ Task<CloudFlareResponse<IReadOnlyList<Zone>>> GetZonesAsync(
/// <seealso href="https://api.cloudflare.com/#zone-list-zones"/>
Task<IEnumerable<Zone>> GetAllZonesAsync(
CancellationToken cancellationToken,
PagedZoneParameters parameters = null,
ZoneGetParameters parameters = null,
CloudFlareAuth auth = null);

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/CloudFlare.NET/ZoneClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class ZoneClientExtensions
/// <seealso href="https://api.cloudflare.com/#zone-list-zones"/>
public static Task<CloudFlareResponse<IReadOnlyList<Zone>>> GetZonesAsync(
this IZoneClient client,
PagedZoneParameters parameters = null)
ZoneGetParameters parameters = null)
{
if (client == null)
throw new ArgumentNullException(nameof(client));
Expand All @@ -32,7 +32,7 @@ public static Task<CloudFlareResponse<IReadOnlyList<Zone>>> GetZonesAsync(
public static Task<CloudFlareResponse<IReadOnlyList<Zone>>> GetZonesAsync(
this IZoneClient client,
CloudFlareAuth auth,
PagedZoneParameters parameters = null)
ZoneGetParameters parameters = null)
{
if (client == null)
throw new ArgumentNullException(nameof(client));
Expand All @@ -48,7 +48,7 @@ public static Task<CloudFlareResponse<IReadOnlyList<Zone>>> GetZonesAsync(
/// <seealso href="https://api.cloudflare.com/#zone-list-zones"/>
public static Task<IEnumerable<Zone>> GetAllZonesAsync(
this IZoneClient client,
PagedZoneParameters parameters = null)
ZoneGetParameters parameters = null)
{
if (client == null)
throw new ArgumentNullException(nameof(client));
Expand All @@ -63,7 +63,7 @@ public static Task<IEnumerable<Zone>> GetAllZonesAsync(
public static Task<IEnumerable<Zone>> GetAllZonesAsync(
this IZoneClient client,
CloudFlareAuth auth,
PagedZoneParameters parameters = null)
ZoneGetParameters parameters = null)
{
if (client == null)
throw new ArgumentNullException(nameof(client));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
/// Specifies the parameters of the <see cref="IZoneClient.GetZonesAsync"/> request.
/// </summary>
/// <seealso href="https://api.cloudflare.com/#zone-list-zones"/>
public class PagedZoneParameters : PagedParameters<PagedZoneOrderFieldTypes>
public class ZoneGetParameters : PagedParameters<ZoneOrderTypes>
{
/// <summary>
/// Initializes a new instance of the <see cref="PagedZoneParameters"/> class.
/// Initializes a new instance of the <see cref="ZoneGetParameters"/> class.
/// </summary>
public PagedZoneParameters(
public ZoneGetParameters(
string name = null,
ZoneStatusType? status = null,
int page = 0,
int perPage = 0,
PagedZoneOrderFieldTypes order = default(PagedZoneOrderFieldTypes),
ZoneOrderTypes order = default(ZoneOrderTypes),
PagedParametersOrderType direction = default(PagedParametersOrderType),
PagedParametersMatchType match = default(PagedParametersMatchType))
: base(page, perPage, order, direction, match)
Expand All @@ -42,15 +42,15 @@ public PagedZoneParameters(
public ZoneStatusType? Status { get; }

/// <summary>
/// Creates a <see cref="PagedZoneParameters"/> from the <paramref name="data"/> copying any matching
/// Creates a <see cref="ZoneGetParameters"/> from the <paramref name="data"/> copying any matching
/// properties.
/// </summary>
public static PagedZoneParameters Create(object data)
public static ZoneGetParameters Create(object data)
{
if (data == null)
throw new ArgumentNullException(nameof(data));

return JObject.FromObject(data).ToObject<PagedZoneParameters>();
return JObject.FromObject(data).ToObject<ZoneGetParameters>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// Extension methods on <see cref="HttpClient"/> to wrap the Zone APIs
/// </summary>
/// <seealso href="https://api.cloudflare.com/#zone"/>
public static class HttpClientZoneExtensions
public static class ZoneHttpClientExtensions
{
/// <summary>
/// Gets the zones for the account specified by the <paramref name="auth"/> details.
Expand All @@ -21,7 +21,7 @@ public static Task<CloudFlareResponse<IReadOnlyList<Zone>>> GetZonesAsync(
this HttpClient client,
CancellationToken cancellationToken,
CloudFlareAuth auth,
PagedZoneParameters parameters = null)
ZoneGetParameters parameters = null)
{
Uri uri = new Uri(CloudFlareConstants.BaseUri, "zones");
if (parameters != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1303:ConstFieldNamesMustBeginWithUpperCaseLetter",
Justification = "Named to match serialized values.")]
[JsonConverter(typeof(StringEnumConverter))]
public enum PagedZoneOrderFieldTypes
public enum ZoneOrderTypes
{
none,
name,
Expand Down
6 changes: 3 additions & 3 deletions src/Tests/CloudFlare.NET.Tests/CloudFlare.NET.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@
<Compile Include="Serialization\BehaviorTemplates.cs" />
<Compile Include="Serialization\DnsRecordGetParametersSpec.cs" />
<Compile Include="Serialization\DnsRecordSpec.cs" />
<Compile Include="Serialization\PagedZoneParametersSerializationSpec.cs" />
<Compile Include="ZoneClientExtensionsSpec.cs" />
<Compile Include="Serialization\ErrorResponseSerializationSpec.cs" />
<Compile Include="Serialization\SampleJson.cs" />
<Compile Include="Serialization\SuccessResponseSerializationSpec.cs" />
<Compile Include="Serialization\ZoneSerializationSpec.cs" />
<Compile Include="Serialization\ZoneGetParametersSpec.cs" />
<Compile Include="Serialization\ZoneSpec.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ZoneClientExtensionsSpec.cs" />
<Compile Include="ZoneClientSpec.cs" />
<None Include="app.config" />
<None Include="packages.config" />
Expand Down
Loading

0 comments on commit 535ccdd

Please sign in to comment.