Add "Zone" extensions

This commit is contained in:
2025-06-24 15:14:54 +02:00
parent 2fe9ac0657
commit 9aa1dbb02c
18 changed files with 1856 additions and 6 deletions

View File

@@ -0,0 +1,48 @@
using System.Runtime.Serialization;
using Newtonsoft.Json.Converters;
namespace AMWD.Net.Api.Cloudflare.Zones
{
/// <summary>
/// Zone types.
/// <see href="https://github.com/cloudflare/cloudflare-typescript/blob/v4.4.1/src/resources/zones/zones.ts#L223">Source</see>
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum ZoneType
{
/// <summary>
/// Full Setup (most common).
/// </summary>
/// <remarks>
/// Use Cloudflare as your primary DNS provider and manage your DNS records on Cloudflare.
/// </remarks>
[EnumMember(Value = "full")]
Full = 1,
/// <summary>
/// Partial (CNAME) setup.
/// </summary>
/// <remarks>
/// Keep your primary DNS provider and only use Cloudflare's reverse proxy for individual subdomains.
/// </remarks>
[EnumMember(Value = "partial")]
Partial = 2,
/// <summary>
/// Zone transfers.
/// </summary>
/// <remarks>
/// Use Cloudflare and another DNS provider together across your entire zone to increase availability and fault tolerance.
/// <br/>
/// DNS records will be transferred between providers using <see href="https://datatracker.ietf.org/doc/html/rfc5936">AXFR</see> or <see href="https://datatracker.ietf.org/doc/html/rfc1995">IXFR</see>.
/// </remarks>
[EnumMember(Value = "secondary")]
Secondary = 3,
/// <summary>
/// An internal zone.
/// </summary>
[EnumMember(Value = "internal")]
Internal = 4
}
}

View File

@@ -0,0 +1,180 @@
using System.Runtime.Serialization;
using Newtonsoft.Json.Converters;
namespace AMWD.Net.Api.Cloudflare.Zones
{
/// <summary>
/// Filter for listing zones.
/// </summary>
public class ListZonesFilter : IQueryParameterFilter
{
/// <summary>
/// An account ID.
/// </summary>
public string? AccountId { get; set; }
/// <summary>
/// An account Name.
/// </summary>
/// <remarks>
/// Optional filter operators can be provided to extend refine the search:
/// <list type="bullet">
/// <item><description>equal</description> (default)</item>
/// <item><description>not_equal</description></item>
/// <item><description>starts_with</description></item>
/// <item><description>ends_with</description></item>
/// <item><description>contains</description></item>
/// <item><description>starts_with_case_sensitive</description></item>
/// <item><description>ends_with_case_sensitive</description></item>
/// <item><description>contains_case_sensitive</description></item>
/// </list>
/// </remarks>
/// <example>Dev Account</example>
/// <example>contains:Test</example>
public string? AccountName { get; set; }
/// <summary>
/// Direction to order zones.
/// </summary>
public SortDirection? Direction { get; set; }
/// <summary>
/// Whether to match all search requirements or at least one (any).
/// </summary>
public ListZonesMatch? Match { get; set; }
/// <summary>
/// A domain name.
/// </summary>
/// <remarks>
/// Optional filter operators can be provided to extend refine the search:
/// <list type="bullet">
/// <item><description>equal</description> (default)</item>
/// <item><description>not_equal</description></item>
/// <item><description>starts_with</description></item>
/// <item><description>ends_with</description></item>
/// <item><description>contains</description></item>
/// <item><description>starts_with_case_sensitive</description></item>
/// <item><description>ends_with_case_sensitive</description></item>
/// <item><description>contains_case_sensitive</description></item>
/// </list>
/// </remarks>
/// <example>example.com</example>
/// <example>contains:.org</example>
/// <example>ends_with:arpa</example>
/// <example>starts_with:dev</example>
public string? Name { get; set; }
/// <summary>
/// Field to order zones by.
/// </summary>
public ListZonesOrderBy? OrderBy { get; set; }
/// <summary>
/// Page number of paginated results.
/// </summary>
/// <value>1 &lt;= X</value>
public int? Page { get; set; }
/// <summary>
/// Number of zones per page.
/// </summary>
/// <value>5 &lt;= X &lt;= 50</value>
public int? PerPage { get; set; }
/// <summary>
/// A zone status.
/// </summary>
public ZoneStatus? Status { get; set; }
/// <inheritdoc />
public IDictionary<string, string> GetQueryParameters()
{
var dict = new Dictionary<string, string>();
#pragma warning disable CS8602, CS8604 // There will be no null value below.
if (!string.IsNullOrWhiteSpace(AccountId))
dict.Add("account.id", AccountId.Trim());
if (!string.IsNullOrWhiteSpace(AccountName))
dict.Add("account.name", AccountName.Trim());
if (Direction.HasValue && Enum.IsDefined(typeof(SortDirection), Direction.Value))
dict.Add("direction", Direction.Value.GetEnumMemberValue());
if (Match.HasValue && Enum.IsDefined(typeof(ListZonesMatch), Match.Value))
dict.Add("match", Match.Value.GetEnumMemberValue());
if (!string.IsNullOrWhiteSpace(Name))
dict.Add("name", Name);
if (OrderBy.HasValue && Enum.IsDefined(typeof(ListZonesOrderBy), OrderBy.Value))
dict.Add("order", OrderBy.Value.GetEnumMemberValue());
if (Page.HasValue && Page.Value >= 1)
dict.Add("page", Page.Value.ToString());
if (PerPage.HasValue && PerPage.Value >= 5 && PerPage.Value <= 50)
dict.Add("per_page", PerPage.Value.ToString());
if (Status.HasValue && Enum.IsDefined(typeof(ZoneStatus), Status.Value))
dict.Add("status", Status.Value.GetEnumMemberValue());
#pragma warning restore CS8602, CS8604
return dict;
}
}
/// <summary>
/// Match type for listing zones.
/// <see href="https://github.com/cloudflare/cloudflare-typescript/blob/v4.4.1/src/resources/zones/zones.ts#L553">Source</see>
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum ListZonesMatch
{
/// <summary>
/// Match all search requirements.
/// </summary>
[EnumMember(Value = "all")]
All = 1,
/// <summary>
/// Match at least one search requirement.
/// </summary>
[EnumMember(Value = "any")]
Any = 2
}
/// <summary>
/// Field to order zones by.
/// <see href="https://github.com/cloudflare/cloudflare-typescript/blob/v4.4.1/src/resources/zones/zones.ts#L573">Source</see>
/// </summary>
public enum ListZonesOrderBy
{
/// <summary>
/// Order by zone name.
/// </summary>
[EnumMember(Value = "name")]
Name = 1,
/// <summary>
/// Order by zone status.
/// </summary>
[EnumMember(Value = "status")]
Status = 2,
/// <summary>
/// Order by account ID.
/// </summary>
[EnumMember(Value = "account.id")]
AccountId = 3,
/// <summary>
/// Order by account name.
/// </summary>
[EnumMember(Value = "account.name")]
AccountName = 4,
}
}

View File

@@ -0,0 +1,22 @@
namespace AMWD.Net.Api.Cloudflare.Zones.Internals
{
internal class InternalCreateZoneRequest
{
public InternalCreateZoneRequest(string? accountId, string name, ZoneType? type)
{
Account = new Identifier { Id = accountId };
Name = name;
Type = type;
}
[JsonProperty("account")]
public Identifier Account { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("type")]
public ZoneType? Type { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
namespace AMWD.Net.Api.Cloudflare.Zones.Internals
{
internal class InternalEditZoneRequest
{
[JsonProperty("paused")]
public bool? Paused { get; set; }
[JsonProperty("type")]
public ZoneType? Type { get; set; }
[JsonProperty("vanity_name_servers")]
public IReadOnlyCollection<string>? VanityNameServers { get; set; }
}
}

View File

@@ -0,0 +1,408 @@
using System.Runtime.Serialization;
using Newtonsoft.Json.Converters;
namespace AMWD.Net.Api.Cloudflare.Zones
{
/// <summary>
/// A Cloudflare zone.
/// <see href="https://github.com/cloudflare/cloudflare-typescript/blob/v4.4.1/src/resources/zones/zones.ts#L231">Source</see>
/// </summary>
public class Zone
{
/// <summary>
/// Initializes a new instance of the <see cref="Zone"/> class.
/// </summary>
/// <param name="id">Identifier.</param>
/// <param name="name">The domain name.</param>
/// <param name="nameServers">The name servers Cloudflare assigns to the zone.</param>
/// <param name="account">The account the zone belongs to.</param>
/// <param name="meta">Metadata about the zone.</param>
/// <param name="owner">The owner of the zone.</param>
public Zone(string id, string name, IReadOnlyCollection<string> nameServers, ZoneAccount account, ZoneMeta meta, ZoneOwner owner)
{
Id = id;
Account = account;
Meta = meta;
Name = name;
NameServers = nameServers;
Owner = owner;
#pragma warning disable CS0612
Plan = new();
#pragma warning restore CS0612
}
/// <summary>
/// Identifier.
/// </summary>
[JsonProperty("id")]
public string Id { get; set; }
/// <summary>
/// The account the zone belongs to.
/// </summary>
[JsonProperty("account")]
public ZoneAccount Account { get; set; }
/// <summary>
/// The last time proof of ownership was detected and the zone was made active.
/// </summary>
[JsonProperty("activated_on")]
public DateTime? ActivatedOn { get; set; }
/// <summary>
/// When the zone was created.
/// </summary>
[JsonProperty("created_on")]
public DateTime CreatedOn { get; set; }
/// <summary>
/// The interval (in seconds) from when development mode expires (positive integer)
/// or last expired (negative integer) for the domain. If development mode has never
/// been enabled, this value is 0.
/// </summary>
[JsonProperty("development_mode")]
public int DevelopmentMode { get; set; }
/// <summary>
/// Metadata about the zone.
/// </summary>
[JsonProperty("meta")]
public ZoneMeta Meta { get; set; }
/// <summary>
/// When the zone was last modified.
/// </summary>
[JsonProperty("modified_on")]
public DateTime ModifiedOn { get; set; }
/// <summary>
/// The domain name.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// The name servers Cloudflare assigns to a zone.
/// </summary>
[JsonProperty("name_servers")]
public IReadOnlyCollection<string> NameServers { get; set; }
/// <summary>
/// DNS host at the time of switching to Cloudflare.
/// </summary>
[JsonProperty("original_dnshost")]
public string? OriginalDnsHost { get; set; }
/// <summary>
/// Original name servers before moving to Cloudflare.
/// </summary>
[JsonProperty("original_name_servers")]
public IReadOnlyCollection<string>? OriginalNameServers { get; set; }
/// <summary>
/// Registrar for the domain at the time of switching to Cloudflare.
/// </summary>
[JsonProperty("original_registrar")]
public string? OriginalRegistrar { get; set; }
/// <summary>
/// The owner of the zone.
/// </summary>
[JsonProperty("owner")]
public ZoneOwner Owner { get; set; }
/// <summary>
/// A Zones subscription information.
/// </summary>
[Obsolete]
[JsonProperty("plan")]
public ZonePlan Plan { get; set; }
/// <summary>
/// Allows the customer to use a custom apex.
/// <em>Tenants Only Configuration</em>.
/// </summary>
[JsonProperty("cname_suffix")]
public string? CnameSuffix { get; set; }
/// <summary>
/// Indicates whether the zone is only using Cloudflare DNS services.
/// </summary>
/// <remarks>
/// A <see langword="true"/> value means the zone will not receive security or performance benefits.
/// </remarks>
[JsonProperty("paused")]
public bool? Paused { get; set; }
/// <summary>
/// Legacy permissions based on legacy user membership information.
/// </summary>
[Obsolete]
[JsonProperty("permissions")]
public IReadOnlyCollection<string>? Permissions { get; set; }
/// <summary>
/// The zone status on Cloudflare.
/// </summary>
[JsonProperty("status")]
public ZoneStatus? Status { get; set; }
/// <summary>
/// The root organizational unit that this zone belongs to (such as a tenant or organization).
/// </summary>
[JsonProperty("tenant")]
public ZoneTenant? Tenant { get; set; }
/// <summary>
/// The immediate parent organizational unit that this zone belongs to (such as under a tenant or sub-organization).
/// </summary>
[JsonProperty("tenant_unit")]
public ZoneTenantUnit? TenantUnit { get; set; }
/// <summary>
/// A full zone implies that DNS is hosted with Cloudflare.
/// A partial zone is typically a partner-hosted zone or a CNAME setup.
/// </summary>
[JsonProperty("type")]
public ZoneType? Type { get; set; }
/// <summary>
/// An array of domains used for custom name servers.
/// This is only available for Business and Enterprise plans.
/// </summary>
[JsonProperty("vanity_name_servers")]
public IReadOnlyCollection<string>? VanityNameServers { get; set; }
/// <summary>
/// Verification key for partial zone setup.
/// </summary>
[JsonProperty("verification_key")]
public string? VerificationKey { get; set; }
}
/// <summary>
/// The account the zone belongs to.
/// <see href="https://github.com/cloudflare/cloudflare-typescript/blob/v4.4.1/src/resources/zones/zones.ts#L359">Source</see>
/// </summary>
public class ZoneAccount
{
/// <summary>
/// Identifier.
/// </summary>
[JsonProperty("id")]
public string? Id { get; set; }
/// <summary>
/// The name of the account.
/// </summary>
[JsonProperty("name")]
public string? Name { get; set; }
}
/// <summary>
/// Metadata about the zone.
/// <see href="https://github.com/cloudflare/cloudflare-typescript/blob/v4.4.1/src/resources/zones/zones.ts#L374">Source</see>
/// </summary>
public class ZoneMeta
{
/// <summary>
/// The zone is only configured for CDN.
/// </summary>
[JsonProperty("cdn_only")]
public bool? CdnOnly { get; set; }
/// <summary>
/// Number of Custom Certificates the zone can have.
/// </summary>
[JsonProperty("custom_certificate_quota")]
public int? CustomCertificateQuota { get; set; }
/// <summary>
/// The zone is only configured for DNS.
/// </summary>
[JsonProperty("dns_only")]
public bool? DnsOnly { get; set; }
/// <summary>
/// The zone is setup with Foundation DNS.
/// </summary>
[JsonProperty("foundation_dns")]
public bool? FoundationDns { get; set; }
/// <summary>
/// Number of Page Rules a zone can have.
/// </summary>
[JsonProperty("page_rule_quota")]
public int? PageRuleQuota { get; set; }
/// <summary>
/// The zone has been flagged for phishing.
/// </summary>
[JsonProperty("phishing_detected")]
public bool? PhishingDetected { get; set; }
/// <summary>
/// Step.
/// </summary>
[JsonProperty("step")]
public int? Step { get; set; }
}
/// <summary>
/// The owner of the zone.
/// <see href="https://github.com/cloudflare/cloudflare-typescript/blob/v4.4.1/src/resources/zones/zones.ts#L411">Source</see>
/// </summary>
public class ZoneOwner
{
/// <summary>
/// Identifier.
/// </summary>
[JsonProperty("id")]
public string? Id { get; set; }
/// <summary>
/// Name of the owner.
/// </summary>
[JsonProperty("name")]
public string? Name { get; set; }
/// <summary>
/// The type of owner.
/// </summary>
[JsonProperty("type")]
public string? Type { get; set; }
}
/// <summary>
/// A Zones subscription information.
/// <see href="https://github.com/cloudflare/cloudflare-typescript/blob/v4.4.1/src/resources/zones/zones.ts#L431">Source</see>
/// </summary>
[Obsolete]
public class ZonePlan
{
/// <summary>
/// Identifier.
/// </summary>
[JsonProperty("id")]
public string? Id { get; set; }
/// <summary>
/// States if the subscription can be activated.
/// </summary>
[JsonProperty("can_subscribe")]
public bool? CanSubscribe { get; set; }
/// <summary>
/// The denomination of the customer.
/// </summary>
[JsonProperty("currency")]
public string? Currency { get; set; }
/// <summary>
/// If this Zone is managed by another company.
/// </summary>
[JsonProperty("externally_managed")]
public bool? ExternallyManaged { get; set; }
/// <summary>
/// How often the customer is billed.
/// </summary>
[JsonProperty("frequency")]
public string? Frequency { get; set; }
/// <summary>
/// States if the subscription active.
/// </summary>
[JsonProperty("is_subscribed")]
public bool? IsSubscribed { get; set; }
/// <summary>
/// If the legacy discount applies to this Zone.
/// </summary>
[JsonProperty("legacy_discount")]
public bool? LegacyDiscount { get; set; }
/// <summary>
/// The legacy name of the plan.
/// </summary>
[JsonProperty("legacy_id")]
public string? LegacyId { get; set; }
/// <summary>
/// Name of the owner.
/// </summary>
[JsonProperty("name")]
public string? Name { get; set; }
/// <summary>
/// How much the customer is paying.
/// </summary>
[JsonProperty("price")]
public decimal? Price { get; set; }
}
/// <summary>
/// Zone status.
/// <see href="https://github.com/cloudflare/cloudflare-typescript/blob/v4.4.1/src/resources/zones/zones.ts#L323">Source</see>
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum ZoneStatus
{
/// <summary>
/// Initializing.
/// </summary>
[EnumMember(Value = "initializing")]
Initializing = 1,
/// <summary>
/// Pending.
/// </summary>
[EnumMember(Value = "pending")]
Pending = 2,
/// <summary>
/// Active.
/// </summary>
[EnumMember(Value = "active")]
Active = 3,
/// <summary>
/// Moved.
/// </summary>
[EnumMember(Value = "moved")]
Moved = 4
}
/// <summary>
/// The root organizational unit that this zone belongs to (such as a tenant or organization).
/// <see href="https://github.com/cloudflare/cloudflare-typescript/blob/v4.4.1/src/resources/zones/zones.ts#L487">Source</see>
/// </summary>
public class ZoneTenant
{
/// <summary>
/// Identifier.
/// </summary>
[JsonProperty("id")]
public string? Id { get; set; }
/// <summary>
/// The name of the Tenant account.
/// </summary>
[JsonProperty("name")]
public string? Name { get; set; }
}
/// <summary>
/// The immediate parent organizational unit that this zone belongs to (such as under a tenant or sub-organization).
/// <see href="https://github.com/cloudflare/cloudflare-typescript/blob/v4.4.1/src/resources/zones/zones.ts#L503">Source</see>
/// </summary>
public class ZoneTenantUnit
{
/// <summary>
/// Identifier.
/// </summary>
[JsonProperty("id")]
public string? Id { get; set; }
}
}

View File

@@ -11,7 +11,13 @@ This package contains the feature set of the _Domain/Zone Management_ section of
- [Update Domain](https://developers.cloudflare.com/api/resources/registrar/subresources/domains/methods/update/)
### [Zones]
- [Create Zone](https://developers.cloudflare.com/api/resources/zones/methods/create/)
- [Delete Zone](https://developers.cloudflare.com/api/resources/zones/methods/delete/)
- [Edit Zone](https://developers.cloudflare.com/api/resources/zones/methods/edit/)
- [Zone Details](https://developers.cloudflare.com/api/resources/zones/methods/get/)
- [List Zones](https://developers.cloudflare.com/api/resources/zones/methods/list/)

View File

@@ -0,0 +1,33 @@
namespace AMWD.Net.Api.Cloudflare.Zones
{
/// <summary>
/// Represents a request to create a zone.
/// </summary>
public class CreateZoneRequest
{
/// <summary>
/// Initializes a new instance of the <see cref="CreateZoneRequest"/> class.
/// </summary>
/// <param name="name">The domain name.</param>
public CreateZoneRequest(string name)
{
Name = name;
}
/// <summary>
/// The account identifier.
/// </summary>
public string? AccountId { get; set; }
/// <summary>
/// The domain name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// A full zone implies that DNS is hosted with Cloudflare.
/// A partial zone is typically a partner-hosted zone or a CNAME setup.
/// </summary>
public ZoneType? Type { get; set; }
}
}

View File

@@ -0,0 +1,47 @@
namespace AMWD.Net.Api.Cloudflare.Zones
{
/// <summary>
/// Represents a request to edit a zone.
/// </summary>
public class EditZoneRequest
{
/// <summary>
/// Initializes a new instance of the <see cref="EditZoneRequest"/> class.
/// </summary>
/// <param name="zoneId">The zone identifier.</param>
public EditZoneRequest(string zoneId)
{
ZoneId = zoneId;
}
/// <summary>
/// The zone identifier.
/// </summary>
public string ZoneId { get; set; }
/// <summary>
/// Indicates whether the zone is only using Cloudflare DNS services.
/// </summary>
/// <remarks>
/// A <see langword="true"/> value means the zone will not receive security or performance benefits.
/// </remarks>
public bool? Paused { get; set; }
/// <summary>
/// A full zone implies that DNS is hosted with Cloudflare.
/// A partial zone is typically a partner-hosted zone or a CNAME setup.
/// </summary>
/// <remarks>
/// This parameter is only available to Enterprise customers or if it has been explicitly enabled on a zone.
/// </remarks>
public ZoneType? Type { get; set; }
/// <summary>
/// A list of domains used for custom name servers.
/// </summary>
/// <remarks>
/// This is only available for Business and Enterprise plans.
/// </remarks>
public IReadOnlyCollection<string>? VanityNameServers { get; set; }
}
}

View File

@@ -0,0 +1,110 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AMWD.Net.Api.Cloudflare.Zones.Internals;
namespace AMWD.Net.Api.Cloudflare.Zones
{
/// <summary>
/// Extensions for <see href="https://developers.cloudflare.com/api/resources/zones/">Zones</see>.
/// </summary>
public static class ZonesExtensions
{
/// <summary>
/// Create Zone.
/// </summary>
/// <param name="client">The <see cref="ICloudflareClient"/> instance.</param>
/// <param name="request">The request.</param>
/// <param name="cancellationToken">A cancellation token used to propagate notification that this operation should be canceled.</param>
public static Task<CloudflareResponse<Zone>> CreateZone(this ICloudflareClient client, CreateZoneRequest request, CancellationToken cancellationToken = default)
{
request.AccountId?.ValidateCloudflareId();
request.Name.ValidateLength(253, nameof(request.Name));
if (request.Type.HasValue && !Enum.IsDefined(typeof(ZoneType), request.Type.Value))
throw new ArgumentOutOfRangeException(nameof(request.Type));
var req = new InternalCreateZoneRequest(
request.AccountId,
request.Name,
request.Type
);
return client.PostAsync<Zone, InternalCreateZoneRequest>($"/zones", req, cancellationToken: cancellationToken);
}
/// <summary>
/// Deletes an existing zone.
/// </summary>
/// <param name="client">The <see cref="ICloudflareClient"/> instance.</param>
/// <param name="zoneId">The zone identifier.</param>
/// <param name="cancellationToken">A cancellation token used to propagate notification that this operation should be canceled.</param>
public static Task<CloudflareResponse<Identifier>> DeleteZone(this ICloudflareClient client, string zoneId, CancellationToken cancellationToken = default)
{
zoneId.ValidateCloudflareId();
return client.DeleteAsync<Identifier>($"/zones/{zoneId}", cancellationToken: cancellationToken);
}
/// <summary>
/// Edits a zone.
/// </summary>
/// <remarks>
/// <strong>Only one zone property can be changed at a time.</strong>
/// </remarks>
/// <param name="client">The <see cref="ICloudflareClient"/> instance.</param>
/// <param name="request">The request.</param>
/// <param name="cancellationToken">A cancellation token used to propagate notification that this operation should be canceled.</param>
public static Task<CloudflareResponse<Zone>> EditZone(this ICloudflareClient client, EditZoneRequest request, CancellationToken cancellationToken = default)
{
request.ZoneId.ValidateCloudflareId();
if (request.Paused.HasValue && (request.Type.HasValue || request.VanityNameServers != null))
throw new CloudflareException("Only one zone property can be changed at a time.");
if (request.Type.HasValue && request.VanityNameServers != null)
throw new CloudflareException("Only one zone property can be changed at a time.");
if (request.Type.HasValue && !Enum.IsDefined(typeof(ZoneType), request.Type.Value))
throw new ArgumentOutOfRangeException(nameof(request.Type));
var req = new InternalEditZoneRequest
{
Paused = request.Paused,
Type = request.Type
};
if (request.VanityNameServers != null)
req.VanityNameServers = request.VanityNameServers.Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
return client.PatchAsync<Zone, InternalEditZoneRequest>($"/zones/{request.ZoneId}", req, cancellationToken: cancellationToken);
}
/// <summary>
/// Zone Details.
/// </summary>
/// <param name="client">The <see cref="ICloudflareClient"/> instance.</param>
/// <param name="zoneId">The zone identifier.</param>
/// <param name="cancellationToken">A cancellation token used to propagate notification that this operation should be canceled.</param>
public static Task<CloudflareResponse<Zone>> ZoneDetails(this ICloudflareClient client, string zoneId, CancellationToken cancellationToken = default)
{
zoneId.ValidateCloudflareId();
return client.GetAsync<Zone>($"/zones/{zoneId}", cancellationToken: cancellationToken);
}
/// <summary>
/// Lists, searches, sorts, and filters your zones.
/// </summary>
/// <remarks>
/// Listing zones across more than 500 accounts is currently not allowed.
/// </remarks>
/// <param name="client">The <see cref="ICloudflareClient"/> instance.</param>
/// <param name="options">Filter options.</param>
/// <param name="cancellationToken">A cancellation token used to propagate notification that this operation should be canceled.</param>
public static Task<CloudflareResponse<IReadOnlyCollection<Zone>>> ListZones(this ICloudflareClient client, ListZonesFilter? options = null, CancellationToken cancellationToken = default)
{
return client.GetAsync<IReadOnlyCollection<Zone>>($"/zones", queryFilter: options, cancellationToken: cancellationToken);
}
}
}