using System; using System.Collections.Generic; using System.Linq; using System.Net.Http.Headers; using System.Net.Http; using System.Text; using System.Text.Json; using System.Threading.Tasks; using Newtonsoft.Json.Linq; using Refit; using Persistence.Client.Helpers; namespace Persistence.Client { public static class PersistenceClientFactory { private static readonly JsonSerializerOptions JsonSerializerOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, PropertyNameCaseInsensitive = true }; private static readonly RefitSettings RefitSettings = new(new SystemTextJsonContentSerializer(JsonSerializerOptions)); public static T GetClient(HttpClient client) { return RestService.For(client, RefitSettings); } public static T GetClient(string baseUrl) { var client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); return RestService.For(client, RefitSettings); } private static HttpClient GetAuthorizedClient() { var httpClient = new HttpClient(); var jwtToken = ApiTokenHelper.GetAdminUserToken(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken); return httpClient; } } }