Implement AuthService and ApiClient core logic
This commit is contained in:
36
Core/ApiClient.cs
Normal file
36
Core/ApiClient.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user