Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup .NET 3.1
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v3
with:
dotnet-version: 3.1.x
- name: Setup .NET 5.0
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v3
with:
dotnet-version: 5.0.x
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Setup .NET 7.0
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Setup .NET 8.0
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ In order to get started, please follow these steps.

_Package Manager_
```
Install-Package Forbury.Integrations -Version 1.5.0
Install-Package Forbury.Integrations -Version 1.7.0
```

_.NET CLI_
```
dotnet add PROJECT package Forbury.Integrations --version 1.5.0
dotnet add PROJECT package Forbury.Integrations --version 1.7.0
```

_PackageReference_
```
<PackageReference Include="Forbury.Integrations" Version="1.5.0" />
<PackageReference Include="Forbury.Integrations" Version="1.7.0" />
```

For a full list of the latest releases, please see the [package release page](https://www.nuget.org/packages/Forbury.Integrations).
Expand Down Expand Up @@ -72,13 +72,48 @@ If you only have one client, you **will not** need to choose which client to mak
public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
{
services.AddForburyApi(Configuration);
...
}
```

Alternatively, if you are using the new .NET 6 design **without** a `Startup.cs`, add the following inside your `Program.cs` _(.NET 6)_.
Alternatively, you are able to create your own configuration object and pass that in as parameter instead.
This gives you the flexibility to build your configuration outside the standard `appsettings.json` structure.

```C#
public void ConfigureServices(IServiceCollection services)
{
var forburyConfiguration = new ForburyConfiguration()
{
Api = new ApiConfiguration()
{
Url = "https://api.forbury.com/",
Version = 1
},
Authentication = new AuthenticationConfiguration()
{
Url = "https://account.forbury.com/",
Clients = new Dictionary<string, AuthenticationClientConfiguration>()
{
{
"UNIQUE_CLIENT_NAME",
new AuthenticationClientConfiguration()
{
ClientId = "YOUR_CLIENT_ID",
ClientSecret = "YOUR_CLIENT_SECRET"
}
}
}
}
};

services.AddForburyApi(forburyConfiguration);
...
}
```

_Note:_ If you are using the new .NET 6 design **without** a `Startup.cs`, add the following inside your `Program.cs` _(.NET 6)_.

```C#
using Forbury.Integrations.API;
Expand Down
Binary file modified assets/logo/logo_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 18 additions & 7 deletions src/Forbury.Integrations/API/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Forbury.Integrations.API.Interfaces;
using Forbury.Integrations.API.Models.Configuration;
using Forbury.Integrations.API.Services;
Expand All @@ -11,13 +12,22 @@ public static class IServiceCollectionExtensions
{
public static IServiceCollection AddForburyApi(this IServiceCollection services, IConfiguration configuration)
{
services.AddForburyAuthenticationAndConfiguration(configuration);
var forburyConfiguration = new ForburyConfiguration();
configuration.GetSection("Forbury").Bind(forburyConfiguration);

services.AddForburyApi(forburyConfiguration);

return services;
}

public static IServiceCollection AddForburyApi(this IServiceCollection services, ForburyConfiguration forburyConfiguration)
{
services.AddForburyAuthenticationAndConfiguration(forburyConfiguration);

// Leaving blank or "0" will setup all API versions for DI
var apiVersion = int.TryParse(configuration["Forbury:Api:Version"], out int parsedApiVersion) ?
parsedApiVersion : 0;
var apiVersion = forburyConfiguration.Api.Version;

if (apiVersion == 1 || apiVersion == 0) v1.ServiceBuilder.AddForburyServices(services, $"{configuration["Forbury:Api:Url"]}api/v1");
if (apiVersion == 1 || apiVersion == 0) v1.ServiceBuilder.AddForburyServices(services, $"{forburyConfiguration.Api.Url}api/v1");

return services;
}
Expand All @@ -32,15 +42,16 @@ internal static void AddForburyHttpClient<TClient, TImplementation>(this IServic
}).AddHttpMessageHandler<AuthorizationDelegatingHandler>();
}

private static IServiceCollection AddForburyAuthenticationAndConfiguration(this IServiceCollection services, IConfiguration configuration)
private static IServiceCollection AddForburyAuthenticationAndConfiguration(this IServiceCollection services,
ForburyConfiguration forburyConfiguration)
{
services.Configure<ForburyConfiguration>(options => configuration.GetSection("Forbury").Bind(options));
services.ConfigureOptions(forburyConfiguration);

services.AddTransient<AuthorizationDelegatingHandler>();

services.AddHttpClient<IForburyAuthenticationService, ForburyAuthenticationService>(config =>
{
config.BaseAddress = new Uri(configuration["Forbury:Authentication:Url"]);
config.BaseAddress = new Uri(forburyConfiguration.Authentication.Url);
});

return services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<string> GetAccessTokenAsync(CancellationToken cancellationToke
if (IsAuthorised(customerClient.ClientId))
return _tokens[customerClient.ClientId].AccessToken;

await _tokenSemaphore.WaitAsync(cancellationToken);
await _tokenSemaphore.WaitAsync(cancellationToken);

try
{
Expand Down
18 changes: 17 additions & 1 deletion src/Forbury.Integrations/API/v1/Clients/ForburyApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Forbury.Integrations.API.Models.Configuration;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Configuration;

namespace Forbury.Integrations.API.v1.Clients
{
Expand All @@ -21,9 +24,13 @@ public abstract class ForburyApiClient : IForburyApiClient

protected readonly HttpClient _httpClient;

public ForburyApiClient(HttpClient httpClient)
private readonly ForburyConfiguration _configuration;

public ForburyApiClient(HttpClient httpClient,
IOptions<ForburyConfiguration> configuration)
{
_httpClient = httpClient;
_configuration = configuration.Value;
}

public void SetClient(string name)
Expand All @@ -36,6 +43,15 @@ public void SetClient(string name)
_httpClient.DefaultRequestHeaders.Add(Constants.ClientHeaderName, name);
}

public void SetClient(string name, AuthenticationClientConfiguration clientConfiguration)
{
// Try remove and then add new client
_configuration.Authentication.Clients.Remove(name);
_configuration.Authentication.Clients.Add(name, clientConfiguration);

SetClient(name);
}

protected QueryBuilder GetPagedQueryBuilder(int amount, int page)
{
return new QueryBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Forbury.Integrations.API.Models.Configuration;
using Forbury.Integrations.API.v1.Dto.Enums;
using Forbury.Integrations.API.v1.Dto.Product;
using Forbury.Integrations.API.v1.Interfaces;
using Forbury.Integrations.Helpers.Extensions;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Options;

namespace Forbury.Integrations.API.v1.Clients
{
public class ForburyProductApiClient : ForburyApiClient, IForburyProductApiClient
{
public ForburyProductApiClient(HttpClient httpClient) :
base(httpClient)
public ForburyProductApiClient(HttpClient httpClient,
IOptions<ForburyConfiguration> configuration) :
base(httpClient, configuration)
{ }

public async Task<List<ProductDto>> GetProducts(CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Forbury.Integrations.API.Models.Configuration;
using Forbury.Integrations.API.v1.Dto;
using Forbury.Integrations.API.v1.Dto.Enums;
using Forbury.Integrations.API.v1.Dto.Model;
using Forbury.Integrations.API.v1.Dto.Property;
using Forbury.Integrations.API.v1.Interfaces;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Options;

namespace Forbury.Integrations.API.v1.Clients
{
public class ForburyPropertyApiClient : ForburyApiClient, IForburyPropertyApiClient
{
public ForburyPropertyApiClient(HttpClient httpClient) :
base(httpClient)
public ForburyPropertyApiClient(HttpClient httpClient,
IOptions<ForburyConfiguration> configuration) :
base(httpClient, configuration)
{ }

public async Task<PagedResult<PropertyDto>> GetProperties(int amount = 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Forbury.Integrations.API.Models.Configuration;
using Forbury.Integrations.API.v1.Dto;
using Forbury.Integrations.API.v1.Dto.Enums;
using Forbury.Integrations.API.v1.Dto.Model;
using Forbury.Integrations.API.v1.Dto.Property;
using Forbury.Integrations.API.v1.Dto.Team;
using Forbury.Integrations.API.v1.Interfaces;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Options;

namespace Forbury.Integrations.API.v1.Clients
{
public class ForburyTeamApiClient : ForburyApiClient, IForburyTeamApiClient
{
public ForburyTeamApiClient(HttpClient httpClient) :
base(httpClient)
public ForburyTeamApiClient(HttpClient httpClient,
IOptions<ForburyConfiguration> configuration) :
base(httpClient, configuration)
{ }

public async Task<PagedResult<TeamDto>> GetTeams(int amount = 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Forbury.Integrations.API.Models.Configuration;
using Forbury.Integrations.API.v1.Dto;
using Forbury.Integrations.API.v1.Dto.Enums;
using Forbury.Integrations.API.v1.Dto.File;
using Forbury.Integrations.API.v1.Dto.Model;
using Forbury.Integrations.API.v1.Interfaces.Model;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Options;

namespace Forbury.Integrations.API.v1.Clients.Model
{
public class ForburyModelApiClient : ForburyApiClient, IForburyModelApiClient
{
public ForburyModelApiClient(HttpClient httpClient) :
base(httpClient)
public ForburyModelApiClient(HttpClient httpClient,
IOptions<ForburyConfiguration> configuration) :
base(httpClient, configuration)
{ }

public async Task<PagedResult<ModelDto>> GetModels(ProductType? productType = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Forbury.Integrations.API.Models.Configuration;
using Forbury.Integrations.API.v1.Dto.Model.Commercial;
using Forbury.Integrations.API.v1.Interfaces.Model;
using Microsoft.Extensions.Options;

namespace Forbury.Integrations.API.v1.Clients.Model
{
public class ForburyModelCommercialApiClient : ForburyModelApiClient, IForburyModelCommercialApiClient
{
public ForburyModelCommercialApiClient(HttpClient httpClient) :
base(httpClient)
public ForburyModelCommercialApiClient(HttpClient httpClient,
IOptions<ForburyConfiguration> configuration) :
base(httpClient, configuration)
{ }

public async Task<ModelCommercialDetailedDto> GetModelById(int modelId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Forbury.Integrations.API.Models.Configuration;
using Forbury.Integrations.API.v1.Dto.Model;
using Forbury.Integrations.API.v1.Dto.Model.Datum;
using Forbury.Integrations.API.v1.Dto.Model.Datum.Input;
using Forbury.Integrations.API.v1.Interfaces.Model;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Options;

namespace Forbury.Integrations.API.v1.Clients.Model
{
public class ForburyModelDatumApiClient : ForburyModelApiClient, IForburyModelDatumApiClient
{
public ForburyModelDatumApiClient(HttpClient httpClient) :
base(httpClient)
public ForburyModelDatumApiClient(HttpClient httpClient,
IOptions<ForburyConfiguration> configuration) :
base(httpClient, configuration)
{ }

public async Task<ModelDatumDetailedDto> GetModelById(int modelId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace Forbury.Integrations.API.v1.Interfaces
using Forbury.Integrations.API.Models.Configuration;

namespace Forbury.Integrations.API.v1.Interfaces
{
public interface IForburyApiClient
{
void SetClient(string name);
void SetClient(string name, AuthenticationClientConfiguration clientConfiguration);
}
}
4 changes: 2 additions & 2 deletions src/Forbury.Integrations/Forbury.Integrations.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.6.0</Version>
<Version>1.7.0</Version>
<Authors>Forbury Development Team</Authors>
<Company>Forbury</Company>
<PackageDescription>This .NET client library provides a quick and easy option for integrating with Forbury APIs.</PackageDescription>
Expand All @@ -14,7 +14,7 @@
<PropertyGroup>
<AssemblyName>Forbury.Integrations</AssemblyName>
<PackageId>Forbury.Integrations</PackageId>
<TargetFrameworks>net48;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

Expand Down