Skip to content

Commit 2cd0fe5

Browse files
committed
Initial commit
0 parents  commit 2cd0fe5

9 files changed

+140
-0
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
insert_final_newline = true
6+
7+
[*.cs]
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
end_of_line = lf

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bin
2+
obj
3+
.DS_Store

CloudflareDnsync.sln

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0DF04433-43F6-45C9-86BA-744356BC7810}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudflareDnsync.Cli", "src\CloudflareDnsync.Cli\CloudflareDnsync.Cli.csproj", "{5B7CD32D-1472-47E7-8959-14D7618AC151}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudflareDnsync.Services", "src\CloudflareDnsync.Services\CloudflareDnsync.Services.csproj", "{91D9B0C3-11A7-4849-87D3-527A39534742}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudflareDnsync.Abstractions", "src\CloudflareDnsync.Abstractions\CloudflareDnsync.Abstractions.csproj", "{46E2C087-1871-4EEC-B96A-4F52E97829F3}"
13+
EndProject
14+
Global
15+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|Any CPU = Debug|Any CPU
17+
Release|Any CPU = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20+
{5B7CD32D-1472-47E7-8959-14D7618AC151}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{5B7CD32D-1472-47E7-8959-14D7618AC151}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{5B7CD32D-1472-47E7-8959-14D7618AC151}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{5B7CD32D-1472-47E7-8959-14D7618AC151}.Release|Any CPU.Build.0 = Release|Any CPU
24+
{91D9B0C3-11A7-4849-87D3-527A39534742}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{91D9B0C3-11A7-4849-87D3-527A39534742}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{91D9B0C3-11A7-4849-87D3-527A39534742}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{91D9B0C3-11A7-4849-87D3-527A39534742}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{46E2C087-1871-4EEC-B96A-4F52E97829F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{46E2C087-1871-4EEC-B96A-4F52E97829F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{46E2C087-1871-4EEC-B96A-4F52E97829F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{46E2C087-1871-4EEC-B96A-4F52E97829F3}.Release|Any CPU.Build.0 = Release|Any CPU
32+
EndGlobalSection
33+
GlobalSection(SolutionProperties) = preSolution
34+
HideSolutionNode = FALSE
35+
EndGlobalSection
36+
GlobalSection(NestedProjects) = preSolution
37+
{5B7CD32D-1472-47E7-8959-14D7618AC151} = {0DF04433-43F6-45C9-86BA-744356BC7810}
38+
{91D9B0C3-11A7-4849-87D3-527A39534742} = {0DF04433-43F6-45C9-86BA-744356BC7810}
39+
{46E2C087-1871-4EEC-B96A-4F52E97829F3} = {0DF04433-43F6-45C9-86BA-744356BC7810}
40+
EndGlobalSection
41+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace CloudflareDnsync.Abstractions;
2+
3+
public interface ICloudflareService
4+
{
5+
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

src/CloudflareDnsync.Cli/Program.cs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\CloudflareDnsync.Abstractions\CloudflareDnsync.Abstractions.csproj" />
5+
</ItemGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
9+
</ItemGroup>
10+
11+
<PropertyGroup>
12+
<TargetFramework>net8.0</TargetFramework>
13+
<ImplicitUsings>enable</ImplicitUsings>
14+
<Nullable>enable</Nullable>
15+
</PropertyGroup>
16+
17+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Text;
2+
using CloudflareDnsync.Abstractions;
3+
using Newtonsoft.Json;
4+
5+
namespace CloudflareDnsync.Services;
6+
7+
public class CloudflareService : ICloudflareService
8+
{
9+
private const string BaseUrl = "https://api.cloudflare.com/client/v4/";
10+
11+
private readonly HttpClient _httpClient = new()
12+
{
13+
BaseAddress = new Uri(BaseUrl)
14+
};
15+
16+
public CloudflareService(string apiKey, string apiEmail, string? baseAddress = null)
17+
{
18+
_httpClient.DefaultRequestHeaders.Add("X-Auth-Key", apiKey);
19+
_httpClient.DefaultRequestHeaders.Add("X-Auth-Email", apiEmail);
20+
if (baseAddress is not null)
21+
_httpClient.BaseAddress = new Uri(baseAddress);
22+
}
23+
24+
public CloudflareService(string token, string? baseAddress = null)
25+
{
26+
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
27+
if (baseAddress is not null)
28+
_httpClient.BaseAddress = new Uri(baseAddress);
29+
}
30+
31+
private async Task<TResult> SendAsync<TResult>(HttpMethod method, string url, object? data = null)
32+
{
33+
var request = new HttpRequestMessage(HttpMethod.Get, url);
34+
if (data is not null && (method == HttpMethod.Patch || method == HttpMethod.Post || method == HttpMethod.Put))
35+
{
36+
var json = JsonConvert.SerializeObject(data);
37+
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
38+
}
39+
var response = await _httpClient.SendAsync(request);
40+
var content = await response.Content.ReadAsStringAsync();
41+
return JsonConvert.DeserializeObject<TResult>(content)!;
42+
}
43+
}

0 commit comments

Comments
 (0)