Skip to content

Commit

Permalink
feat: Add support for the /sites endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Antaris committed Feb 12, 2024
1 parent 8dac710 commit 910cc1b
Show file tree
Hide file tree
Showing 25 changed files with 1,553 additions and 142 deletions.
23 changes: 15 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>

<!-- Microsoft.Extensions.* Ver -->
<DotNet8Version>8.0.0</DotNet8Version>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Ben.Demystifier" Version="0.4.1" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.7" />
<PackageVersion Include="FluentValidation" Version="11.6.0" />
<PackageVersion Include="MinVer" Version="4.3.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="$(DotNet8Version)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="$(DotNet8Version)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="$(DotNet8Version)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="$(DotNet8Version)" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(DotNet8Version)" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="$(DotNet8Version)" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(DotNet8Version)" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="$(DotNet8Version)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="System.Net.Http.Json" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="$(DotNet8Version)" />
<PackageVersion Include="System.Net.Http.Json" Version="$(DotNet8Version)" />
<PackageVersion Include="System.Text.Json" Version="$(DotNet8Version)" />
<PackageVersion Include="xunit" Version="2.6.5" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
</ItemGroup>
Expand Down
11 changes: 10 additions & 1 deletion TrybeSDK.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\release.yml = .github\workflows\release.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrybeSDK.Extensions.DependencyInjection", "libs\TrybeSDK.Extensions.DependencyInjection\TrybeSDK.Extensions.DependencyInjection.csproj", "{058204F4-0B67-42B4-9FEF-9AE2BCC8E7F6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrybeSDK.Extensions.DependencyInjection", "libs\TrybeSDK.Extensions.DependencyInjection\TrybeSDK.Extensions.DependencyInjection.csproj", "{058204F4-0B67-42B4-9FEF-9AE2BCC8E7F6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "apps", "apps", "{44D9A031-6FAD-45B7-A5BE-680E031CD72E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrybeSDK.ConsoleSample", "apps\TrybeSDK.ConsoleSample\TrybeSDK.ConsoleSample.csproj", "{D1D474F6-F972-42B7-BB2C-E54DA07D48DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -76,6 +80,10 @@ Global
{058204F4-0B67-42B4-9FEF-9AE2BCC8E7F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{058204F4-0B67-42B4-9FEF-9AE2BCC8E7F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{058204F4-0B67-42B4-9FEF-9AE2BCC8E7F6}.Release|Any CPU.Build.0 = Release|Any CPU
{D1D474F6-F972-42B7-BB2C-E54DA07D48DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1D474F6-F972-42B7-BB2C-E54DA07D48DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1D474F6-F972-42B7-BB2C-E54DA07D48DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1D474F6-F972-42B7-BB2C-E54DA07D48DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -87,6 +95,7 @@ Global
{B55E88E9-F535-4649-A4E4-CE8495D4DDC6} = {F3DB67FB-0AED-46C2-9F74-A9C197443E68}
{9E95ECB2-C721-4367-B515-25C735D6573B} = {71A838D8-527D-41D1-99B0-611404787F46}
{058204F4-0B67-42B4-9FEF-9AE2BCC8E7F6} = {3D0CADC5-4B71-455C-9CD0-BDB0B3A74B3F}
{D1D474F6-F972-42B7-BB2C-E54DA07D48DE} = {44D9A031-6FAD-45B7-A5BE-680E031CD72E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {26041282-B1C0-4262-AE2F-DA9CF2480C37}
Expand Down
56 changes: 56 additions & 0 deletions apps/TrybeSDK.ConsoleSample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.

using System.Net.Http.Headers;

using Microsoft.Extensions.Configuration;

using TrybeSDK;

var settings = GetSettings();
var http = CreateHttpClient();
var api = new TrybeApiClient(http, settings);

var response = await api.Sites.GetSiteAsync("97be0f8c-b78d-4648-b5b9-310d1b3388e2");
if (response.IsSuccess)
{
Console.WriteLine($"Found site: {response.Data?.Name}");

response = await api.Sites.UpdateSiteAsync(response.Data.Id, response.Data);
if (response.IsSuccess)
{
Console.WriteLine($"Updated site: {response.Data?.Name}");
}
else
{
Console.WriteLine($"Error: {response.Error?.Message}");
}
}
else
{
Console.WriteLine($"Error: {response.Error?.Message}");
}

TrybeSettings GetSettings()
{
var configuration = new ConfigurationBuilder()
.AddJsonFile("./appsettings.json", optional: false)
.AddJsonFile("./appsettings.env.json", optional: true)
.Build();

TrybeSettings settings = new();
configuration.GetSection(TrybeSettings.ConfigurationSection).Bind(settings);

settings.Validate();

return settings;
}

HttpClient CreateHttpClient()
{
var http = new HttpClient();

http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

return http;
}
26 changes: 26 additions & 0 deletions apps/TrybeSDK.ConsoleSample/TrybeSDK.ConsoleSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>TrybeSDK</RootNamespace>
<ImplicitPackageReferences>false</ImplicitPackageReferences>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
</ItemGroup>

<ItemGroup>
<Content Include="appsettings*.json" CopyToOutputDirectory="Always" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\libs\TrybeSDK\TrybeSDK.csproj" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions apps/TrybeSDK.ConsoleSample/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
2 changes: 1 addition & 1 deletion build
Submodule build updated 1 files
+34 −31 src/SharedSource.cs
34 changes: 34 additions & 0 deletions libs/TrybeSDK/Api/Shop/ShopOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.

namespace TrybeSDK;

partial interface ITrybeApiClient
{
/// <summary>
/// Gets the shop operations.
/// </summary>
IShopOperations Shop { get; }
}

partial class TrybeApiClient
{
Lazy<IShopOperations>? _shop;
public IShopOperations Shop => (_shop ??= Defer<IShopOperations>(
c => new ShopOperations(new("/shop"), c))).Value;
}

public partial interface IShopOperations
{
}

/// <summary>
/// Provides operations for the /shop/ resource.
/// </summary>
/// <param name="path">The path for this resource.</param>
/// <param name="client">The API client.</param>
public partial class ShopOperations(
PathString path,
ApiClient client) : IShopOperations
{
}
89 changes: 89 additions & 0 deletions libs/TrybeSDK/Api/Sites/Site.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.

using System.Text.Json.Serialization;

namespace TrybeSDK;

/// <summary>
/// A site object.
/// </summary>
public class Site
{
/// <summary>
/// The date and time the site was created.
/// </summary>
/// <value>The date and time the site was created.</value>
[JsonPropertyName("created_at")]
public DateTime? CreatedAt { get; set; }

/// <summary>
/// The id of the organisation this site belongs to
/// </summary>
/// <value>The id of the organisation this site belongs to</value>
[JsonPropertyName("brand_id")]
public string? BrandId { get; set; }

/// <summary>
/// The name of the organisation this site belongs to
/// </summary>
/// <value>The name of the organisation this site belongs to</value>
[JsonPropertyName("brand_name")]
public string? BrandName { get; set; }

/// <summary>
/// The ISO-4217 currency code in lower case
/// </summary>
/// <value>The ISO-4217 currency code in lower case</value>
[JsonPropertyName("currency")]
public string? Currency { get; set; }

/// <summary>
/// The subdomain which this shop is accessible from on the .try.be domain.
/// </summary>
/// <value>The subdomain which this shop is accessible from on the .try.be domain.</value>
[JsonPropertyName("frontend_subdomain")]
public string? FrontendSubdomain { get; set; }

/// <summary>
/// The ID of the site.
/// </summary>
/// <value>The ID of the site.</value>
[JsonPropertyName("id")]
public string? Id { get; set; }

/// <summary>
/// The default locale of the site
/// </summary>
/// <value>The default locale of the site</value>
[JsonPropertyName("locale")]
public string? Locale { get; set; }

/// <summary>
/// The name of the site
/// </summary>
/// <value>The name of the site</value>
[JsonPropertyName("name")]
public string? Name { get; set; }

/// <summary>
/// The id of the organisation this site belongs to
/// </summary>
/// <value>The id of the organisation this site belongs to</value>
[JsonPropertyName("organisation_id")]
public string? OrganisationId { get; set; }

/// <summary>
/// The name of the organisation this site belongs to
/// </summary>
/// <value>The name of the organisation this site belongs to</value>
[JsonPropertyName("organisation_name")]
public string? OrganisationName { get; set; }

/// <summary>
/// The timezone of the site
/// </summary>
/// <value>The timezone of the site</value>
[JsonPropertyName("timezone")]
public string? Timezone { get; set; }
}
Loading

0 comments on commit 910cc1b

Please sign in to comment.