mirror of
https://github.com/eliasstepanik/IonosDDNSUpdater.git
synced 2026-01-11 19:48:26 +00:00
182 lines
10 KiB
C#
182 lines
10 KiB
C#
using DDNSUpdater.APIs.Ionos.ApiClient.Models;
|
|
using DDNSUpdater.APIs.Ionos.ApiClient.V1.Dyndns.Item;
|
|
using Microsoft.Kiota.Abstractions;
|
|
using Microsoft.Kiota.Abstractions.Serialization;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
namespace DDNSUpdater.APIs.Ionos.ApiClient.V1.Dyndns {
|
|
/// <summary>
|
|
/// Builds and executes requests for operations under \v1\dyndns
|
|
/// </summary>
|
|
public class DyndnsRequestBuilder {
|
|
/// <summary>Path parameters for the request</summary>
|
|
private Dictionary<string, object> PathParameters { get; set; }
|
|
/// <summary>The request adapter to use to execute the requests.</summary>
|
|
private IRequestAdapter RequestAdapter { get; set; }
|
|
/// <summary>Url template to use to build the URL for the current request builder</summary>
|
|
private string UrlTemplate { get; set; }
|
|
/// <summary>Gets an item from the DDNSUpdater.APIs.Ionos.ApiClient.v1.dyndns.item collection</summary>
|
|
public WithBulkItemRequestBuilder this[string position] { get {
|
|
var urlTplParams = new Dictionary<string, object>(PathParameters);
|
|
if (!string.IsNullOrWhiteSpace(position)) urlTplParams.Add("bulkId", position);
|
|
return new WithBulkItemRequestBuilder(urlTplParams, RequestAdapter);
|
|
} }
|
|
/// <summary>
|
|
/// Instantiates a new DyndnsRequestBuilder and sets the default values.
|
|
/// </summary>
|
|
/// <param name="pathParameters">Path parameters for the request</param>
|
|
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
|
|
public DyndnsRequestBuilder(Dictionary<string, object> pathParameters, IRequestAdapter requestAdapter) {
|
|
_ = pathParameters ?? throw new ArgumentNullException(nameof(pathParameters));
|
|
_ = requestAdapter ?? throw new ArgumentNullException(nameof(requestAdapter));
|
|
UrlTemplate = "{+baseurl}/v1/dyndns";
|
|
var urlTplParams = new Dictionary<string, object>(pathParameters);
|
|
PathParameters = urlTplParams;
|
|
RequestAdapter = requestAdapter;
|
|
}
|
|
/// <summary>
|
|
/// Instantiates a new DyndnsRequestBuilder and sets the default values.
|
|
/// </summary>
|
|
/// <param name="rawUrl">The raw URL to use for the request builder.</param>
|
|
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
|
|
public DyndnsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) {
|
|
if(string.IsNullOrEmpty(rawUrl)) throw new ArgumentNullException(nameof(rawUrl));
|
|
_ = requestAdapter ?? throw new ArgumentNullException(nameof(requestAdapter));
|
|
UrlTemplate = "{+baseurl}/v1/dyndns";
|
|
var urlTplParams = new Dictionary<string, object>();
|
|
if (!string.IsNullOrWhiteSpace(rawUrl)) urlTplParams.Add("request-raw-url", rawUrl);
|
|
PathParameters = urlTplParams;
|
|
RequestAdapter = requestAdapter;
|
|
}
|
|
/// <summary>
|
|
/// Disable Dynamic Dns.The following quota applies: 2 requests per minute per IP address.
|
|
/// </summary>
|
|
/// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
|
|
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
|
|
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
|
|
#nullable enable
|
|
public async Task<Stream?> DeleteAsync(Action<DyndnsRequestBuilderDeleteRequestConfiguration>? requestConfiguration = default, CancellationToken cancellationToken = default) {
|
|
#nullable restore
|
|
#else
|
|
public async Task<Stream> DeleteAsync(Action<DyndnsRequestBuilderDeleteRequestConfiguration> requestConfiguration = default, CancellationToken cancellationToken = default) {
|
|
#endif
|
|
var requestInfo = ToDeleteRequestInformation(requestConfiguration);
|
|
var errorMapping = new Dictionary<string, ParsableFactory<IParsable>> {
|
|
{"401", Error.CreateFromDiscriminatorValue},
|
|
{"500", Error.CreateFromDiscriminatorValue},
|
|
};
|
|
return await RequestAdapter.SendPrimitiveAsync<Stream>(requestInfo, errorMapping, cancellationToken);
|
|
}
|
|
/// <summary>
|
|
/// Activate Dynamic Dns for a bundle of (sub)domains. The url from response will be used to update the ips of the (sub)domains.The following quota applies: 2 requests per minute per IP address.
|
|
/// </summary>
|
|
/// <param name="body">The request body</param>
|
|
/// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
|
|
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
|
|
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
|
|
#nullable enable
|
|
public async Task<DynamicDns?> PostAsync(DynDnsRequest body, Action<DyndnsRequestBuilderPostRequestConfiguration>? requestConfiguration = default, CancellationToken cancellationToken = default) {
|
|
#nullable restore
|
|
#else
|
|
public async Task<DynamicDns> PostAsync(DynDnsRequest body, Action<DyndnsRequestBuilderPostRequestConfiguration> requestConfiguration = default, CancellationToken cancellationToken = default) {
|
|
#endif
|
|
_ = body ?? throw new ArgumentNullException(nameof(body));
|
|
var requestInfo = ToPostRequestInformation(body, requestConfiguration);
|
|
var errorMapping = new Dictionary<string, ParsableFactory<IParsable>> {
|
|
{"400", Error.CreateFromDiscriminatorValue},
|
|
{"401", Error.CreateFromDiscriminatorValue},
|
|
{"500", Error.CreateFromDiscriminatorValue},
|
|
};
|
|
return await RequestAdapter.SendAsync<DynamicDns>(requestInfo, DynamicDns.CreateFromDiscriminatorValue, errorMapping, cancellationToken);
|
|
}
|
|
/// <summary>
|
|
/// Disable Dynamic Dns.The following quota applies: 2 requests per minute per IP address.
|
|
/// </summary>
|
|
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
|
|
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
|
|
#nullable enable
|
|
public RequestInformation ToDeleteRequestInformation(Action<DyndnsRequestBuilderDeleteRequestConfiguration>? requestConfiguration = default) {
|
|
#nullable restore
|
|
#else
|
|
public RequestInformation ToDeleteRequestInformation(Action<DyndnsRequestBuilderDeleteRequestConfiguration> requestConfiguration = default) {
|
|
#endif
|
|
var requestInfo = new RequestInformation {
|
|
HttpMethod = Method.DELETE,
|
|
UrlTemplate = UrlTemplate,
|
|
PathParameters = PathParameters,
|
|
};
|
|
if (requestConfiguration != null) {
|
|
var requestConfig = new DyndnsRequestBuilderDeleteRequestConfiguration();
|
|
requestConfiguration.Invoke(requestConfig);
|
|
requestInfo.AddRequestOptions(requestConfig.Options);
|
|
requestInfo.AddHeaders(requestConfig.Headers);
|
|
}
|
|
return requestInfo;
|
|
}
|
|
/// <summary>
|
|
/// Activate Dynamic Dns for a bundle of (sub)domains. The url from response will be used to update the ips of the (sub)domains.The following quota applies: 2 requests per minute per IP address.
|
|
/// </summary>
|
|
/// <param name="body">The request body</param>
|
|
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
|
|
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
|
|
#nullable enable
|
|
public RequestInformation ToPostRequestInformation(DynDnsRequest body, Action<DyndnsRequestBuilderPostRequestConfiguration>? requestConfiguration = default) {
|
|
#nullable restore
|
|
#else
|
|
public RequestInformation ToPostRequestInformation(DynDnsRequest body, Action<DyndnsRequestBuilderPostRequestConfiguration> requestConfiguration = default) {
|
|
#endif
|
|
_ = body ?? throw new ArgumentNullException(nameof(body));
|
|
var requestInfo = new RequestInformation {
|
|
HttpMethod = Method.POST,
|
|
UrlTemplate = UrlTemplate,
|
|
PathParameters = PathParameters,
|
|
};
|
|
requestInfo.Headers.Add("Accept", "application/json");
|
|
requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
|
|
if (requestConfiguration != null) {
|
|
var requestConfig = new DyndnsRequestBuilderPostRequestConfiguration();
|
|
requestConfiguration.Invoke(requestConfig);
|
|
requestInfo.AddRequestOptions(requestConfig.Options);
|
|
requestInfo.AddHeaders(requestConfig.Headers);
|
|
}
|
|
return requestInfo;
|
|
}
|
|
/// <summary>
|
|
/// Configuration for the request such as headers, query parameters, and middleware options.
|
|
/// </summary>
|
|
public class DyndnsRequestBuilderDeleteRequestConfiguration {
|
|
/// <summary>Request headers</summary>
|
|
public RequestHeaders Headers { get; set; }
|
|
/// <summary>Request options</summary>
|
|
public IList<IRequestOption> Options { get; set; }
|
|
/// <summary>
|
|
/// Instantiates a new dyndnsRequestBuilderDeleteRequestConfiguration and sets the default values.
|
|
/// </summary>
|
|
public DyndnsRequestBuilderDeleteRequestConfiguration() {
|
|
Options = new List<IRequestOption>();
|
|
Headers = new RequestHeaders();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Configuration for the request such as headers, query parameters, and middleware options.
|
|
/// </summary>
|
|
public class DyndnsRequestBuilderPostRequestConfiguration {
|
|
/// <summary>Request headers</summary>
|
|
public RequestHeaders Headers { get; set; }
|
|
/// <summary>Request options</summary>
|
|
public IList<IRequestOption> Options { get; set; }
|
|
/// <summary>
|
|
/// Instantiates a new dyndnsRequestBuilderPostRequestConfiguration and sets the default values.
|
|
/// </summary>
|
|
public DyndnsRequestBuilderPostRequestConfiguration() {
|
|
Options = new List<IRequestOption>();
|
|
Headers = new RequestHeaders();
|
|
}
|
|
}
|
|
}
|
|
}
|