Implement AuthService and ApiClient core logic

This commit is contained in:
2026-04-09 14:22:47 +02:00
parent 3ee4edac6c
commit 8cbfa61766
22 changed files with 503 additions and 13 deletions

36
Core/ApiClient.cs Normal file
View File

@@ -0,0 +1,36 @@
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Chtn.CSharp.SDK.Core
{
public class ApiClient
{
private readonly HttpClient _httpClient;
private readonly string _baseUrl;
public ApiClient(string baseUrl)
{
_baseUrl = baseUrl.EndsWith("/") ? baseUrl : baseUrl + "/";
_httpClient = new HttpClient();
}
public async Task<TResponse> PostAsync<TRequest, TResponse>(string endpoint, TRequest data)
{
var json = JsonConvert.SerializeObject(data);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync(_baseUrl + endpoint, content);
var responseJson = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
throw new Exception($"API Hiba ({response.StatusCode}): {responseJson}");
}
return JsonConvert.DeserializeObject<TResponse>(responseJson);
}
}
}

View File

@@ -1,8 +1,6 @@
using System;
using System.Globalization;
using System.Net.WebSockets;
using Chtn.CSharpSDK.Interfaces;
using System;
using System.Threading.Tasks;
using Chtn.CSharpSDK.Interfaces;
namespace Chtn.CSharpSDK.Core

View File

@@ -1,7 +1,7 @@
namespace Chtn.CSharp.SDK.Core
{
public class SDKConfig
{
{
public string ApiUrl { get; set; } = "https://api.chatenium.hu";
public string CdnUrl { get; set; } = "https://cdn.chatenium.hu";
public string WsUrl { get; set; } = "wss://api.chatenium.hu";
@@ -10,6 +10,6 @@
public static class EnvironmentConfig
{
private static SDKConfig _currentConfig = new SDKConfig();
public static SDKConfig Get() => _currentConfig;
public static SDKConfig Get() => _currentConfig;
}
}

View File

@@ -3,7 +3,7 @@ using System.Net.Http;
namespace Chtn.CSharp.SDK.Core
{
public static class HttpClientFactory
public static class HttpClientFactory
{
public static HttpClient CreateClient(bool isCdn = false)
{

View File

@@ -1,14 +1,12 @@
using System;
using System.Collections.Generic;
using Chtn.CSharp.SDK.Core;
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Net.Http.Headers;
using Chtn.CSharpSDK.Interfaces;
using Chtn.CSharp.SDK.Core;
namespace Chtn.CSharpSDK.Core
{