diff --git a/src/CloudFlare.NET/HttpClientDnsRecordExtensions.cs b/src/CloudFlare.NET/HttpClientDnsRecordExtensions.cs
index 35fffe0..2390f32 100644
--- a/src/CloudFlare.NET/HttpClientDnsRecordExtensions.cs
+++ b/src/CloudFlare.NET/HttpClientDnsRecordExtensions.cs
@@ -17,31 +17,17 @@ public static class HttpClientDnsRecordExtensions
/// Gets the zones for the account specified by the details.
///
///
- public static async Task> GetDnsRecordsAsync(
+ public static Task> GetDnsRecordsAsync(
this HttpClient client,
IdentifierTag zoneId,
CancellationToken cancellationToken,
CloudFlareAuth auth)
{
- if (client == null)
- throw new ArgumentNullException(nameof(client));
if (zoneId == null)
throw new ArgumentNullException(nameof(zoneId));
- if (auth == null)
- throw new ArgumentNullException(nameof(auth));
Uri uri = new Uri(CloudFlareConstants.BaseUri, $"zones/{zoneId}/dns_records");
- var request = new HttpRequestMessage(HttpMethod.Get, uri);
- request.AddAuth(auth);
-
- HttpResponseMessage response =
- await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
- .ConfigureAwait(false);
-
- return (await response
- .GetResultAsync>(cancellationToken)
- .ConfigureAwait(false))
- .Result;
+ return client.GetAsync>(uri, auth, cancellationToken);
}
}
}
diff --git a/src/CloudFlare.NET/HttpClientExtensions.cs b/src/CloudFlare.NET/HttpClientExtensions.cs
index 0fcaebd..e41c4cc 100644
--- a/src/CloudFlare.NET/HttpClientExtensions.cs
+++ b/src/CloudFlare.NET/HttpClientExtensions.cs
@@ -13,11 +13,6 @@
///
public static class HttpClientExtensions
{
- ///
- /// Gets the base address of the CloudFlare API.
- ///
- public static Uri ZonesUri { get; } = new Uri(CloudFlareConstants.BaseUri, "zones");
-
///
/// Gets the of a CloudFlare API .
///
@@ -60,5 +55,39 @@ public static void AddAuth(this HttpRequestMessage request, CloudFlareAuth auth)
request.Headers.Add("X-Auth-Key", auth.Key);
request.Headers.Add("X-Auth-Email", auth.Email);
}
+
+ ///
+ /// Executes a request returning the type specified by .
+ ///
+ /// The type of the .
+ public static async Task GetAsync(
+ this HttpClient client,
+ Uri uri,
+ CloudFlareAuth auth,
+ CancellationToken cancellationToken)
+ where T : class
+ {
+ if (client == null)
+ throw new ArgumentNullException(nameof(client));
+ if (uri == null)
+ throw new ArgumentNullException(nameof(uri));
+ if (auth == null)
+ throw new ArgumentNullException(nameof(auth));
+
+ using (var request = new HttpRequestMessage(HttpMethod.Get, uri))
+ {
+ request.AddAuth(auth);
+
+ HttpResponseMessage response =
+ await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
+ .ConfigureAwait(false);
+ using (response)
+ {
+ CloudFlareResponse cloudFlareResponse =
+ await response.GetResultAsync(cancellationToken).ConfigureAwait(false);
+ return cloudFlareResponse.Result;
+ }
+ }
+ }
}
}
diff --git a/src/CloudFlare.NET/HttpClientZoneExtensions.cs b/src/CloudFlare.NET/HttpClientZoneExtensions.cs
index f001d29..023b2d7 100644
--- a/src/CloudFlare.NET/HttpClientZoneExtensions.cs
+++ b/src/CloudFlare.NET/HttpClientZoneExtensions.cs
@@ -17,65 +17,36 @@ public static class HttpClientZoneExtensions
/// Gets the zones for the account specified by the details.
///
///
- public static async Task> GetZonesAsync(
+ public static Task> GetZonesAsync(
this HttpClient client,
CancellationToken cancellationToken,
CloudFlareAuth auth,
PagedZoneParameters parameters = null)
{
- if (client == null)
- throw new ArgumentNullException(nameof(client));
- if (auth == null)
- throw new ArgumentNullException(nameof(auth));
-
Uri uri = new Uri(CloudFlareConstants.BaseUri, "zones");
if (parameters != null)
{
uri = new UriBuilder(uri) { Query = parameters.ToQuery() }.Uri;
}
- var request = new HttpRequestMessage(HttpMethod.Get, uri);
- request.AddAuth(auth);
-
- HttpResponseMessage response =
- await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
- .ConfigureAwait(false);
-
- return (await response
- .GetResultAsync>(cancellationToken)
- .ConfigureAwait(false))
- .Result;
+ return client.GetAsync>(uri, auth, cancellationToken);
}
///
/// Gets the zones for the account specified by the details.
///
///
- public static async Task GetZoneAsync(
+ public static Task GetZoneAsync(
this HttpClient client,
IdentifierTag zoneId,
CancellationToken cancellationToken,
CloudFlareAuth auth)
{
- if (client == null)
- throw new ArgumentNullException(nameof(client));
if (zoneId == null)
throw new ArgumentNullException(nameof(zoneId));
- if (auth == null)
- throw new ArgumentNullException(nameof(auth));
Uri uri = new Uri(CloudFlareConstants.BaseUri, $"zones/{zoneId}");
- var request = new HttpRequestMessage(HttpMethod.Get, uri);
- request.AddAuth(auth);
-
- HttpResponseMessage response =
- await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
- .ConfigureAwait(false);
-
- return (await response
- .GetResultAsync(cancellationToken)
- .ConfigureAwait(false))
- .Result;
+ return client.GetAsync(uri, auth, cancellationToken);
}
}
}