|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using DigitalOcean.API.Http; |
| 4 | +using DigitalOcean.API.Models.Responses; |
| 5 | +using RestSharp; |
| 6 | + |
| 7 | +namespace DigitalOcean.API.Clients { |
| 8 | + public class CdnEndpointsClient : ICdnEndpointsClient { |
| 9 | + private readonly IConnection _connection; |
| 10 | + |
| 11 | + public CdnEndpointsClient(IConnection connection) { |
| 12 | + _connection = connection; |
| 13 | + } |
| 14 | + |
| 15 | + /// <summary> |
| 16 | + /// To list all of the CDN endpoints available on your account. |
| 17 | + /// </summary> |
| 18 | + public Task<IReadOnlyList<CdnEndpoint>> GetAll() { |
| 19 | + return _connection.GetPaginated<CdnEndpoint>("cdn/endpoints", null, "endpoints"); |
| 20 | + } |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// To show information about an existing CDN endpoint. |
| 24 | + /// </summary> |
| 25 | + public Task<CdnEndpoint> Get(string endpointId) { |
| 26 | + var parameters = new List<Parameter> { |
| 27 | + new Parameter { Name = "endpoint_id", Value = endpointId, Type = ParameterType.UrlSegment } |
| 28 | + }; |
| 29 | + return _connection.ExecuteRequest<CdnEndpoint>("cdn/endpoints/{endpoint_id}", parameters, null, "endpoint"); |
| 30 | + } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// To create a new CDN endpoint. |
| 34 | + /// The Origin attribute must be set to the fully qualified domain name (FQDN) of a DigitalOcean Space. |
| 35 | + /// </summary> |
| 36 | + public Task<CdnEndpoint> Create(Models.Requests.CdnEndpoint endpoint) { |
| 37 | + return _connection.ExecuteRequest<CdnEndpoint>("cdn/endpoints", null, endpoint, "endpoint", Method.POST); |
| 38 | + } |
| 39 | + |
| 40 | + /// <summary> |
| 41 | + /// To update the TTL, certificate ID, or the FQDN of the custom subdomain for an existing CDN endpoint. |
| 42 | + /// </summary> |
| 43 | + public Task<CdnEndpoint> Update(string endpointId, Models.Requests.UpdateCdnEndpoint updateEndpoint) { |
| 44 | + var parameters = new List<Parameter> { |
| 45 | + new Parameter { Name = "endpoint_id", Value = endpointId, Type = ParameterType.UrlSegment } |
| 46 | + }; |
| 47 | + return _connection.ExecuteRequest<CdnEndpoint>("cdn/endpoints/{endpoint_id}", parameters, updateEndpoint, "endpoint", Method.PUT); |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// To delete a specific CDN endpoint. |
| 52 | + /// </summary> |
| 53 | + public Task Delete(string endpointId) { |
| 54 | + var parameters = new List<Parameter> { |
| 55 | + new Parameter { Name = "endpoint_id", Value = endpointId, Type = ParameterType.UrlSegment } |
| 56 | + }; |
| 57 | + return _connection.ExecuteRaw("cdn/endpoints/{endpoint_id}", parameters, null, Method.DELETE); |
| 58 | + } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// To purge cached content from a CDN endpoint. |
| 62 | + /// A path may be for a single file or may contain a wildcard (*) to recursively purge all files under a directory. |
| 63 | + /// When only a wildcard is provided, all cached files will be purged. |
| 64 | + /// </summary> |
| 65 | + public Task PurgeCache(string endpointId, Models.Requests.PurgeCdnFiles purgeFiles) { |
| 66 | + var parameters = new List<Parameter> { |
| 67 | + new Parameter { Name = "endpoint_id", Value = endpointId, Type = ParameterType.UrlSegment } |
| 68 | + }; |
| 69 | + return _connection.ExecuteRaw("cdn/endpoints/{endpoint_id}/cache", parameters, purgeFiles, Method.DELETE); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments