Added client library
This commit is contained in:
		
							
								
								
									
										2060
									
								
								SchengenVisaApi/VisaApiClient/Client.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2060
									
								
								SchengenVisaApi/VisaApiClient/Client.cs
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										39
									
								
								SchengenVisaApi/VisaApiClient/ClientBase.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								SchengenVisaApi/VisaApiClient/ClientBase.cs
									
									
									
									
									
										Normal 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); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										13
									
								
								SchengenVisaApi/VisaApiClient/VisaApiClient.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								SchengenVisaApi/VisaApiClient/VisaApiClient.csproj
									
									
									
									
									
										Normal 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> | ||||
		Reference in New Issue
	
	Block a user