Skip to content

Commit

Permalink
feat: add GetDnsRecordsAsync method
Browse files Browse the repository at this point in the history
  • Loading branch information
alperensert committed Apr 8, 2024
1 parent ddf2e3f commit 27f5be0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/CloudflareDnsync.Models/DnsRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Newtonsoft.Json;

namespace CloudflareDnsync.Models;

public sealed class DnsRecord
{
[JsonProperty("content")]
public string Content { get; init; } = null!;

[JsonProperty("name")]
public string Name { get; init; } = null!;

[JsonProperty("proxied")]
public bool Proxied { get; init; }

[JsonProperty("type")]
public string Type { get; init; } = null!;

[JsonProperty("comment")]
public string? Comment { get; init; }

[JsonProperty("id")]
public string Id { get; init; } = null!;

[JsonProperty("locked")]
public bool Locked { get; init; }

[JsonProperty("modified_on")]
public DateTime ModifiedOn { get; init; }

[JsonProperty("proxiable")]
public bool Proxiable { get; init; }

[JsonProperty("tags")]
public List<string> Tags { get; init; } = [];

[JsonProperty("zone_id")]
public string ZoneId { get; init; } = null!;

[JsonProperty("zone_name")]
public string ZoneName { get; init; } = null!;

[JsonProperty("ttl")]
public int Ttl { get; init; }

[JsonProperty("meta")]
public DnsRecord_Meta? Meta { get; init; }

public class DnsRecord_Meta
{
[JsonProperty("auto_added")]
public bool AutoAdded { get; init; }

[JsonProperty("source")]
public string? Source { get; init; }
}
}
8 changes: 8 additions & 0 deletions src/CloudflareDnsync.Services/CloudflareService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public Task<CloudflareResponse<List<Zone>>> GetZonesAsync(int page = 1, int perP
public Task<CloudflareResponse<TokenVerify>> VerifyTokenAsync()
=> SendAsync<CloudflareResponse<TokenVerify>>(HttpMethod.Get, "user/tokens/verify");

public Task<CloudflareResponse<List<DnsRecord>>> GetDnsRecordsAsync(
string zoneId,
int page = 1,
int perPage = 20)
=> SendAsync<CloudflareResponse<List<DnsRecord>>>(
HttpMethod.Get,
$"zones/{zoneId}/dns_records?page={page}&per_page={perPage}&type=A");

private async Task<TResult> SendAsync<TResult>(HttpMethod method, string url, object? data = null)
{
var request = new HttpRequestMessage(HttpMethod.Get, url);
Expand Down

0 comments on commit 27f5be0

Please sign in to comment.