Skip to content

Commit

Permalink
Merge pull request #42 from Lombiq/issue/OSOE-646
Browse files Browse the repository at this point in the history
OSOE-646: Remove CustomEditAsync
  • Loading branch information
Piedone authored Nov 29, 2023
2 parents ff4b4e8 + 9dc4ed2 commit e80a011
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
17 changes: 13 additions & 4 deletions Lombiq.OrchardCoreApiClient/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@

namespace Lombiq.OrchardCoreApiClient;

public class ApiClient : IDisposable
public class ApiClient : ApiClient<IOrchardCoreApi>
{
private readonly Lazy<IOrchardCoreApi> _lazyOrchardCoreApi;
public ApiClient(ApiClientSettings apiClientSettings)
: base(apiClientSettings)
{
}
}

public class ApiClient<TApi> : IDisposable
where TApi : IOrchardCoreApi
{
private readonly Lazy<TApi> _lazyOrchardCoreApi;

private HttpClient _httpClient;

public IOrchardCoreApi OrchardCoreApi => _lazyOrchardCoreApi.Value;
public TApi OrchardCoreApi => _lazyOrchardCoreApi.Value;

public ApiClient(ApiClientSettings apiClientSettings) =>
_lazyOrchardCoreApi = new(() =>
{
_httpClient = ConfigurableCertificateValidatingHttpClientHandler.CreateClient(apiClientSettings);

// We use Newtonsoft Json.NET because Orchard Core uses it too, so the models will behave the same.
return RefitHelper.WithNewtonsoftJson<IOrchardCoreApi>(_httpClient);
return RefitHelper.WithNewtonsoftJson<TApi>(_httpClient);
});

public async Task CreateAndSetupTenantAsync(
Expand Down
13 changes: 0 additions & 13 deletions Lombiq.OrchardCoreApiClient/Interfaces/IOrchardCoreApi.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lombiq.OrchardCoreApiClient.Models;
using Refit;
using System;
using System.Threading.Tasks;
using static Lombiq.OrchardCoreApiClient.Constants.CommonHeaders;

Expand Down Expand Up @@ -42,18 +41,6 @@ public interface IOrchardCoreApi
[Headers(AuthorizationBearer)]
Task<string> EditAsync([Body(buffered: true)] TenantApiModel editTenantParameters);

/// <summary>
/// Edit a previously created tenant in Orchard Core with additional settings inside
/// <see cref="TenantApiModel.CustomSettings"/>. This endpoint is not implemented, implement on your own.
/// </summary>
/// <param name="editTenantParameters">The <see cref="TenantApiModel.CustomSettings"/> property in the
/// <see cref="TenantApiModel"/> is the additional property that is not processed in <see cref="EditAsync"/>.</param>
/// <returns>The response of the custom tenant edit.</returns>
[Post("/api/tenants/custom-edit")]
[Headers(AuthorizationBearer)]
[Obsolete("This shouldn't be here and will be soon removed, see https://github.com/Lombiq/Orchard-Core-API-Client/issues/30.")]
Task<string> CustomEditAsync([Body(buffered: true)] TenantApiModel editTenantParameters);

/// <summary>
/// Remove a previously created tenant in Orchard Core.
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion Lombiq.OrchardCoreApiClient/Models/TenantApiModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ public class TenantApiModel
public string RecipeName { get; set; }
public IEnumerable<string> FeatureProfiles { get; set; }
public string Category { get; set; }
public IDictionary<string, string> CustomSettings { get; } = new Dictionary<string, string>();
}
13 changes: 13 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ If you want to set up the OpenId features without the recipe, you need to enable

For testing, run your Orchard Core app first, then `Lombiq.OrchardCoreApiClient.Tester`. You may need to edit the [_Program.cs_](Lombiq.OrchardCoreApiClient.Tester/Program.cs) according to your OpenID Application's settings (`ClientId`, `ClientSecret`, and `DefaultTenantUri`) and then run the console application.

### Use your own API endpoints

You can add your own API endpoints by creating a new interface that's inherited from `IOrchardCoreApi` and add your own methods. For example, you can create a new interface called `IOrchardCoreApiExtended` and add a new method to it:

```csharp
public interface IOrchardCoreApiExtended : IOrchardCoreApi
{
[Post("/api/my-custom-endpoint")]
[Headers(AuthorizationBearer)]
Task<string> GetMyCustomEndpointAsync();
}
```

## Recipes

Lombiq OrchardCore API Client OpenId - Recipe for enabling the Tenants and OpenId features and setting it up for the console tester application. To use this recipe, enable the Deployment feature and import this as a deployment package.
Expand Down

0 comments on commit e80a011

Please sign in to comment.