-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for the /sites endpoint
- Loading branch information
Showing
25 changed files
with
1,553 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
Oops, something went wrong.