Skip to content
This repository was archived by the owner on Sep 6, 2025. It is now read-only.

Commit ab0bd53

Browse files
committed
Merge remote-tracking branch 'upstream/master' into other_apis
2 parents 044aaf3 + 2de7053 commit ab0bd53

18 files changed

Lines changed: 549 additions & 9 deletions
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System.Collections.Generic;
2+
using DigitalOcean.API.Clients;
3+
using DigitalOcean.API.Http;
4+
using DigitalOcean.API.Models.Responses;
5+
using NSubstitute;
6+
using RestSharp;
7+
using Xunit;
8+
9+
namespace DigitalOcean.API.Tests.Clients {
10+
public class CdnEndpointsClientTest {
11+
[Fact]
12+
public void CorrectRequestForGetAll() {
13+
var factory = Substitute.For<IConnection>();
14+
var client = new CdnEndpointsClient(factory);
15+
16+
client.GetAll();
17+
18+
factory.Received().GetPaginated<CdnEndpoint>("cdn/endpoints", null, "endpoints");
19+
}
20+
21+
[Fact]
22+
public void CorrectRequestForGet() {
23+
var factory = Substitute.For<IConnection>();
24+
var client = new CdnEndpointsClient(factory);
25+
26+
client.Get("endpoint:abc123");
27+
28+
var parameters = Arg.Is<List<Parameter>>(list => (string)list[0].Value == "endpoint:abc123");
29+
factory.Received().ExecuteRequest<CdnEndpoint>("cdn/endpoints/{endpoint_id}", parameters, null, "endpoint");
30+
}
31+
32+
[Fact]
33+
public void CorrectRequestForCreate() {
34+
var factory = Substitute.For<IConnection>();
35+
var client = new CdnEndpointsClient(factory);
36+
37+
var body = new Models.Requests.CdnEndpoint();
38+
client.Create(body);
39+
40+
factory.Received().ExecuteRequest<CdnEndpoint>("cdn/endpoints", null, body, "endpoint", Method.POST);
41+
}
42+
43+
[Fact]
44+
public void CorrectRequestForUpdate() {
45+
var factory = Substitute.For<IConnection>();
46+
var client = new CdnEndpointsClient(factory);
47+
48+
var body = new Models.Requests.UpdateCdnEndpoint();
49+
client.Update("endpoint:abc123", body);
50+
51+
var parameters = Arg.Is<List<Parameter>>(list => (string)list[0].Value == "endpoint:abc123");
52+
factory.Received().ExecuteRequest<CdnEndpoint>("cdn/endpoints/{endpoint_id}", parameters, body, "endpoint", Method.PUT);
53+
}
54+
55+
[Fact]
56+
public void CorrectRequestForDelete() {
57+
var factory = Substitute.For<IConnection>();
58+
var client = new CdnEndpointsClient(factory);
59+
60+
client.Delete("endpoint:abc123");
61+
62+
var parameters = Arg.Is<List<Parameter>>(list => (string)list[0].Value == "endpoint:abc123");
63+
factory.Received().ExecuteRaw("cdn/endpoints/{endpoint_id}", parameters, null, Method.DELETE);
64+
}
65+
66+
[Fact]
67+
public void CorrectRequestForPurgeCache() {
68+
var factory = Substitute.For<IConnection>();
69+
var client = new CdnEndpointsClient(factory);
70+
71+
var body = new Models.Requests.PurgeCdnFiles();
72+
client.PurgeCache("endpoint:abc123", body);
73+
74+
var parameters = Arg.Is<List<Parameter>>(list => (string)list[0].Value == "endpoint:abc123");
75+
factory.Received().ExecuteRaw("cdn/endpoints/{endpoint_id}/cache", parameters, body, Method.DELETE);
76+
}
77+
}
78+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Collections.Generic;
2+
using DigitalOcean.API.Clients;
3+
using DigitalOcean.API.Http;
4+
using DigitalOcean.API.Models.Responses;
5+
using NSubstitute;
6+
using RestSharp;
7+
using Xunit;
8+
9+
namespace DigitalOcean.API.Tests.Clients {
10+
public class CertificatesClientTest {
11+
[Fact]
12+
public void CorrectRequestForGetAll() {
13+
var factory = Substitute.For<IConnection>();
14+
var client = new CertificatesClient(factory);
15+
16+
client.GetAll();
17+
18+
factory.Received().GetPaginated<Certificate>("certificates", null, "certificates");
19+
}
20+
21+
[Fact]
22+
public void CorrectRequestForGet() {
23+
var factory = Substitute.For<IConnection>();
24+
var client = new CertificatesClient(factory);
25+
26+
client.Get("certificate:abc123");
27+
28+
var parameters = Arg.Is<List<Parameter>>(list => (string)list[0].Value == "certificate:abc123");
29+
factory.Received().ExecuteRequest<Certificate>("certificates/{certificate_id}", parameters, null, "certificate");
30+
}
31+
32+
[Fact]
33+
public void CorrectRequestForCreate() {
34+
var factory = Substitute.For<IConnection>();
35+
var client = new CertificatesClient(factory);
36+
37+
var body = new Models.Requests.Certificate();
38+
client.Create(body);
39+
40+
factory.Received().ExecuteRequest<Certificate>("certificates", null, body, "certificate", Method.POST);
41+
}
42+
43+
[Fact]
44+
public void CorrectRequestForDelete() {
45+
var factory = Substitute.For<IConnection>();
46+
var client = new CertificatesClient(factory);
47+
48+
client.Delete("certificate:abc123");
49+
50+
var parameters = Arg.Is<List<Parameter>>(list => (string)list[0].Value == "certificate:abc123");
51+
factory.Received().ExecuteRaw("certificates/{certificate_id}", parameters, null, Method.DELETE);
52+
}
53+
}
54+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 CertificatesClient : ICertificatesClient {
9+
private readonly IConnection _connection;
10+
11+
public CertificatesClient(IConnection connection) {
12+
_connection = connection;
13+
}
14+
15+
/// <summary>
16+
/// To list all of the certificates available on your account.
17+
/// </summary>
18+
public Task<IReadOnlyList<Certificate>> GetAll() {
19+
return _connection.GetPaginated<Certificate>("certificates", null, "certificates");
20+
}
21+
22+
/// <summary>
23+
/// To show information about an existing certificate.
24+
/// </summary>
25+
public Task<Certificate> Get(string certificateId) {
26+
var parameters = new List<Parameter> {
27+
new Parameter { Name = "certificate_id", Value = certificateId, Type = ParameterType.UrlSegment }
28+
};
29+
return _connection.ExecuteRequest<Certificate>("certificates/{certificate_id}", parameters, null, "certificate");
30+
}
31+
32+
/// <summary>
33+
/// Create a new Let's Encrypt Certificate:
34+
/// When using Let's Encrypt to create a certificate, the dns_names attribute must be provided,
35+
/// and the type must be set to "lets_encrypt".
36+
///
37+
/// Create a new custom Certificate:
38+
/// When uploading a user-generated certificate, the private_key, leaf_certificate, and optionally the certificate_chain
39+
/// attributes should be provided. The type must be set to "custom".
40+
/// </summary>
41+
public Task<Certificate> Create(Models.Requests.Certificate certificate) {
42+
return _connection.ExecuteRequest<Certificate>("certificates", null, certificate, "certificate", Method.POST);
43+
}
44+
45+
/// <summary>
46+
/// To delete a specific certificate.
47+
/// </summary>
48+
public Task Delete(string certificateId) {
49+
var parameters = new List<Parameter> {
50+
new Parameter { Name = "certificate_id", Value = certificateId, Type = ParameterType.UrlSegment }
51+
};
52+
return _connection.ExecuteRaw("certificates/{certificate_id}", parameters, null, Method.DELETE);
53+
}
54+
}
55+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using DigitalOcean.API.Models.Responses;
4+
5+
namespace DigitalOcean.API.Clients {
6+
public interface ICdnEndpointsClient {
7+
/// <summary>
8+
/// To list all of the CDN endpoints available on your account.
9+
/// </summary>
10+
Task<IReadOnlyList<CdnEndpoint>> GetAll();
11+
12+
/// <summary>
13+
/// To show information about an existing CDN endpoint.
14+
/// </summary>
15+
Task<CdnEndpoint> Get(string endpointId);
16+
17+
/// <summary>
18+
/// To create a new CDN endpoint.
19+
/// The Origin attribute must be set to the fully qualified domain name (FQDN) of a DigitalOcean Space.
20+
/// </summary>
21+
Task<CdnEndpoint> Create(Models.Requests.CdnEndpoint endpoint);
22+
23+
/// <summary>
24+
/// To update the TTL, certificate ID, or the FQDN of the custom subdomain for an existing CDN endpoint.
25+
/// </summary>
26+
Task<CdnEndpoint> Update(string endpointId, Models.Requests.UpdateCdnEndpoint updateEndpoint);
27+
28+
/// <summary>
29+
/// To delete a specific CDN endpoint.
30+
/// </summary>
31+
Task Delete(string endpointId);
32+
33+
/// <summary>
34+
/// To purge cached content from a CDN endpoint.
35+
/// A path may be for a single file or may contain a wildcard (*) to recursively purge all files under a directory.
36+
/// When only a wildcard is provided, all cached files will be purged.
37+
/// </summary>
38+
Task PurgeCache(string endpointId, Models.Requests.PurgeCdnFiles purgeFiles);
39+
}
40+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using DigitalOcean.API.Models.Responses;
4+
5+
namespace DigitalOcean.API.Clients {
6+
public interface ICertificatesClient {
7+
/// <summary>
8+
/// To list all of the certificates available on your account.
9+
/// </summary>
10+
Task<IReadOnlyList<Certificate>> GetAll();
11+
12+
/// <summary>
13+
/// To show information about an existing certificate.
14+
/// </summary>
15+
Task<Certificate> Get(string certificateId);
16+
17+
/// <summary>
18+
/// Create a new Let's Encrypt Certificate:
19+
/// When using Let's Encrypt to create a certificate, the dns_names attribute must be provided,
20+
/// and the type must be set to "lets_encrypt".
21+
///
22+
/// Create a new custom Certificate:
23+
/// When uploading a user-generated certificate, the private_key, leaf_certificate, and optionally the certificate_chain
24+
/// attributes should be provided. The type must be set to "custom".
25+
/// </summary>
26+
Task<Certificate> Create(Models.Requests.Certificate certificate);
27+
28+
/// <summary>
29+
/// To delete a specific certificate.
30+
/// </summary>
31+
Task Delete(string certificateId);
32+
}
33+
}

DigitalOcean.API/DigitalOcean.API.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
5-
<Version>2.3.0</Version>
5+
<Version>2.4.0</Version>
66
<Description>.NET wrapper of the DigitalOcean API</Description>
77
<Copyright>2019</Copyright>
88
<PackageLicenseUrl>https://github.com/trmcnvn/DigitalOcean.API/blob/master/LICENSE.md</PackageLicenseUrl>
@@ -11,7 +11,7 @@
1111
<RepositoryUrl>https://github.com/trmcnvn/DigitalOcean.API</RepositoryUrl>
1212
<RepositoryType>git</RepositoryType>
1313
<PackageTags>DigitalOcean API</PackageTags>
14-
<PackageReleaseNotes>Added Project Resources API Support (@Nicholi)</PackageReleaseNotes>
14+
<PackageReleaseNotes>Added CDN Endpoint and Certificate support (@Nicholi)</PackageReleaseNotes>
1515
</PropertyGroup>
1616
<ItemGroup>
1717
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />

DigitalOcean.API/DigitalOcean.API.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
33
<metadata>
44
<id>DigitalOcean.API</id>
5-
<version>2.3.0</version>
5+
<version>2.4.0</version>
66
<authors>DigitalOcean.API</authors>
77
<owners>DigitalOcean.API</owners>
88
<requireLicenseAcceptance>false</requireLicenseAcceptance>
99
<licenseUrl>https://github.com/trmcnvn/DigitalOcean.API/blob/master/LICENSE.md</licenseUrl>
1010
<projectUrl>https://github.com/trmcnvn/DigitalOcean.API</projectUrl>
1111
<iconUrl>http://i.imgur.com/llqIpX6.png</iconUrl>
1212
<description>.NET wrapper of the DigitalOcean API</description>
13-
<releaseNotes>Added Project Resources API Support (@Nicholi)</releaseNotes>
13+
<releaseNotes>Added CDN Endpoint and Certificate support (@Nicholi)</releaseNotes>
1414
<copyright>2019</copyright>
1515
<tags>DigitalOcean API</tags>
1616
<repository type="git" url="https://github.com/trmcnvn/DigitalOcean.API" />

DigitalOcean.API/DigitalOceanClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public DigitalOceanClient(string token) {
1717

1818
Account = new AccountClient(_connection);
1919
Actions = new ActionsClient(_connection);
20+
CdnEndpoints = new CdnEndpointsClient(_connection);
21+
Certificates = new CertificatesClient(_connection);
2022
DomainRecords = new DomainRecordsClient(_connection);
2123
Domains = new DomainsClient(_connection);
2224
DropletActions = new DropletActionsClient(_connection);
@@ -41,6 +43,8 @@ public IRateLimit Rates {
4143

4244
public IAccountClient Account { get; private set; }
4345
public IActionsClient Actions { get; private set; }
46+
public ICdnEndpointsClient CdnEndpoints { get; private set; }
47+
public ICertificatesClient Certificates { get; private set; }
4448
public IDomainRecordsClient DomainRecords { get; private set; }
4549
public IDomainsClient Domains { get; private set; }
4650
public IDropletActionsClient DropletActions { get; private set; }

0 commit comments

Comments
 (0)