-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from JSkimming/zone-list-parameters
Zone list parameters
- Loading branch information
Showing
33 changed files
with
624 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="AsyncFixer" version="1.0.0.0" targetFramework="portable45-net45+win8+wp8+wpa81" developmentDependency="true" /> | ||
<package id="AsyncFixer" version="1.0.0.0" targetFramework="portable45-net45+win8+wp8+wpa81" developmentDependency="true" /> | ||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.0" targetFramework="portable45-net45+win8+wp8+wpa81" /> | ||
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="portable45-net45+win8+wp8+wpa81" /> | ||
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="portable45-net45+win8+wp8+wpa81" /> | ||
<package id="Microsoft.Net.Http" version="2.2.22" targetFramework="portable45-net45+win8+wp8+wpa81" /> | ||
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="portable45-net45+win8+wp8+wpa81" /> | ||
<package id="StyleCop.Analyzers" version="1.0.0-beta003" targetFramework="portable45-net45+win8+wp8+wpa81" developmentDependency="true" /> | ||
<package id="YamlDotNet" version="3.6.1" targetFramework="portable45-net45+win8+wp8+wpa81" /> | ||
<package id="StyleCop.Analyzers" version="1.0.0-beta008" targetFramework="portable45-net45+win8+wp8+wpa81" developmentDependency="true" /> | ||
<package id="YamlDotNet" version="3.7.0" targetFramework="portable45-net45+win8+wp8+wpa81" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace CloudFlare.NET | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
|
||
/// <summary> | ||
/// Specifies the parameters of a request supports paging. | ||
/// </summary> | ||
/// <typeparam name="TOrder">The type of the <see cref="Order"/> property.</typeparam> | ||
public abstract class PagedParameters<TOrder> | ||
where TOrder : struct | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PagedParameters{TOrder}"/> class. | ||
/// </summary> | ||
protected PagedParameters( | ||
int page, | ||
int perPage, | ||
TOrder order, | ||
PagedParametersOrderType direction, | ||
PagedParametersMatchType match) | ||
{ | ||
Page = page; | ||
PerPage = perPage; | ||
Order = order; | ||
Direction = direction; | ||
Match = match; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the page number of paginated results. | ||
/// </summary> | ||
[JsonProperty("page")] | ||
public int Page { get; } | ||
|
||
/// <summary> | ||
/// Gets the number of results per page. | ||
/// </summary> | ||
[JsonProperty("per_page")] | ||
public int PerPage { get; } | ||
|
||
/// <summary> | ||
/// Field to order results by. | ||
/// </summary> | ||
[JsonProperty("order")] | ||
public TOrder Order { get; } | ||
|
||
/// <summary> | ||
/// Gets the direction to order. | ||
/// </summary> | ||
[JsonProperty("direction")] | ||
public PagedParametersOrderType Direction { get; } | ||
|
||
/// <summary> | ||
/// Gets the value of whether to match all search requirements or at least one (any). | ||
/// </summary> | ||
[JsonProperty("match")] | ||
public PagedParametersMatchType Match { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace CloudFlare.NET | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
/// <summary> | ||
/// Extension methinks on paged parameter objects. | ||
/// </summary> | ||
public static class PagedParametersExtensions | ||
{ | ||
/// <summary> | ||
/// <para>Converts the <paramref name="parameters"/> to their equivalent key value pair representation.</para> | ||
/// <para>NOTE. Default values are excluded</para> | ||
/// </summary> | ||
/// <typeparam name="TOrder">The type of the <see cref="PagedParameters{TOrder}.Order"/> property.</typeparam> | ||
public static IEnumerable<KeyValuePair<string, string>> ToKvp<TOrder>(this PagedParameters<TOrder> parameters) | ||
where TOrder : struct | ||
{ | ||
if (parameters == null) | ||
throw new ArgumentNullException(nameof(parameters)); | ||
|
||
// Remove default values to ensure they're not passed as parameters. | ||
JsonSerializer serializer = JsonSerializer.CreateDefault(new JsonSerializerSettings | ||
{ | ||
DefaultValueHandling = DefaultValueHandling.Ignore, | ||
}); | ||
|
||
JObject json = JObject.FromObject(parameters, serializer); | ||
|
||
return | ||
((IDictionary<string, JToken>)json).Select( | ||
kvp => new KeyValuePair<string, string>(kvp.Key, kvp.Value.Value<string>())); | ||
} | ||
|
||
/// <summary> | ||
/// <para>Converts the <paramref name="parameters"/> to their equivalent query string representation.</para> | ||
/// <para>NOTE. Default values are excluded</para> | ||
/// </summary> | ||
/// <typeparam name="TOrder">The type of the <see cref="PagedParameters{TOrder}.Order"/> property.</typeparam> | ||
public static string ToQuery<TOrder>(this PagedParameters<TOrder> parameters) | ||
where TOrder : struct | ||
{ | ||
IEnumerable<KeyValuePair<string, string>> keyValuePairs = parameters.ToKvp(); | ||
|
||
StringBuilder stringBuilder = new StringBuilder(); | ||
foreach (KeyValuePair<string, string> keyValuePair in keyValuePairs) | ||
{ | ||
if (stringBuilder.Length > 0) | ||
stringBuilder.Append('&'); | ||
stringBuilder.Append(Uri.EscapeDataString(keyValuePair.Key)); | ||
stringBuilder.Append('='); | ||
stringBuilder.Append(Uri.EscapeDataString(keyValuePair.Value)); | ||
} | ||
|
||
return stringBuilder.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace CloudFlare.NET | ||
{ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
// ReSharper disable InconsistentNaming | ||
#pragma warning disable 1591 | ||
|
||
/// <summary> | ||
/// The types by which a paged results are matched. | ||
/// </summary> | ||
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:EnumerationItemsMustBeDocumented", | ||
Justification = "Names are self-explanatory.")] | ||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1303:ConstFieldNamesMustBeginWithUpperCaseLetter", | ||
Justification = "Named to match serialized values.")] | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public enum PagedParametersMatchType | ||
{ | ||
all, | ||
any, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace CloudFlare.NET | ||
{ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
// ReSharper disable InconsistentNaming | ||
#pragma warning disable 1591 | ||
|
||
/// <summary> | ||
/// The types by which a paged results an be ordered. | ||
/// </summary> | ||
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:EnumerationItemsMustBeDocumented", | ||
Justification = "Names are self-explanatory.")] | ||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1303:ConstFieldNamesMustBeginWithUpperCaseLetter", | ||
Justification = "Named to match serialized values.")] | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public enum PagedParametersOrderType | ||
{ | ||
asc, | ||
desc, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace CloudFlare.NET | ||
{ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
// ReSharper disable InconsistentNaming | ||
#pragma warning disable 1591 | ||
|
||
/// <summary> | ||
/// The fields by which zones can be ordered. | ||
/// </summary> | ||
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:EnumerationItemsMustBeDocumented", | ||
Justification = "Names are self-explanatory.")] | ||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1303:ConstFieldNamesMustBeginWithUpperCaseLetter", | ||
Justification = "Named to match serialized values.")] | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public enum PagedZoneOrderFieldTypes | ||
{ | ||
none, | ||
name, | ||
status, | ||
email, | ||
} | ||
} |
Oops, something went wrong.