Added client library

This commit is contained in:
2024-08-28 12:46:58 +03:00
parent 537081a63f
commit 96acf03acf
4 changed files with 2118 additions and 0 deletions

View File

@@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApplicationLayer", "Applica
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "Infrastructure\Infrastructure.csproj", "{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisaApiClient", "VisaApiClient\VisaApiClient.csproj", "{46172CC0-8935-4158-9B7F-50FCCBDB6F67}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -30,5 +32,9 @@ Global
{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}.Release|Any CPU.Build.0 = Release|Any CPU
{46172CC0-8935-4158-9B7F-50FCCBDB6F67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46172CC0-8935-4158-9B7F-50FCCBDB6F67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46172CC0-8935-4158-9B7F-50FCCBDB6F67}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46172CC0-8935-4158-9B7F-50FCCBDB6F67}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
using System.Text;
namespace VisaApiClient
{
public class ClientBase
{
private const string LoginPath = "users/login";
protected string? AuthToken { get; private set; }
protected void SetAuthToken(string token)
{
AuthToken = token;
}
protected Task<HttpRequestMessage> CreateHttpRequestMessageAsync(CancellationToken cancellationToken)
{
var msg = new HttpRequestMessage();
msg.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", AuthToken);
return Task.FromResult(msg);
}
protected async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, string url, CancellationToken cancellationToken)
=> await Task.CompletedTask;
protected async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, StringBuilder urlBuilder, CancellationToken cancellationToken)
=> await Task.CompletedTask;
protected async Task ProcessResponseAsync(HttpClient client, HttpResponseMessage response, CancellationToken cancellationToken)
{
if (response.RequestMessage!.RequestUri!.AbsolutePath == LoginPath)
{
var token = await response.Content.ReadAsStringAsync(cancellationToken);
SetAuthToken(token);
}
}
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>