mirror of
https://github.com/yawaflua/SPWorldsWrapper.git
synced 2025-12-13 17:16:21 +02:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46f184d775 | ||
|
|
85c4d5e099 | ||
|
|
1f81fd5cbd | ||
|
|
1201e16caa |
@@ -1,5 +1,5 @@
|
|||||||
# SPWorldsWrapper
|
# SPWorldsWrapper
|
||||||

|

|
||||||
|
|
||||||
Actions pass:
|
Actions pass:
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<PackageId>SPWorldsWrapper</PackageId>
|
<PackageId>SPWorldsWrapper</PackageId>
|
||||||
|
|||||||
@@ -2,13 +2,22 @@
|
|||||||
using SPWorldsWrapper.Types;
|
using SPWorldsWrapper.Types;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
|
using System.Reflection.Metadata.Ecma335;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
namespace SPWorldsWrapper
|
namespace SPWorldsWrapper
|
||||||
{
|
{
|
||||||
|
public class AuthentificationError : Exception
|
||||||
|
{
|
||||||
|
public AuthentificationError(string? message, Exception? innerException) : base(message, innerException) { }
|
||||||
|
public AuthentificationError() : base() { }
|
||||||
|
public AuthentificationError(string? message) : base(message) { }
|
||||||
|
}
|
||||||
public class SPWrapper
|
public class SPWrapper
|
||||||
{
|
{
|
||||||
public readonly HttpClient client;
|
public readonly HttpClient client;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Асинхронный wrapper для работы напрямую с сайтом, а не с API SPWorlds.ru
|
/// Асинхронный wrapper для работы напрямую с сайтом, а не с API SPWorlds.ru
|
||||||
@@ -21,7 +30,11 @@ namespace SPWorldsWrapper
|
|||||||
client = new(handler);
|
client = new(handler);
|
||||||
client.BaseAddress = new Uri("https://spworlds.ru/api/");
|
client.BaseAddress = new Uri("https://spworlds.ru/api/");
|
||||||
cookieContainer.Add(client.BaseAddress, new Cookie("jeff", token));
|
cookieContainer.Add(client.BaseAddress, new Cookie("jeff", token));
|
||||||
spwLogin();
|
var spwLoginMethod = spwLogin();
|
||||||
|
if (!spwLoginMethod.Result)
|
||||||
|
{
|
||||||
|
throw new AuthentificationError("Ошибка парсинга данных от сайта. Проверьте токен, IP сервера и статус сайта SPWORLDS.RU");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -30,11 +43,24 @@ namespace SPWorldsWrapper
|
|||||||
/// Если иное - токен слетел!
|
/// Если иное - токен слетел!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Ничего</returns>
|
/// <returns>Ничего</returns>
|
||||||
public void spwLogin()
|
public async Task<bool> spwLogin()
|
||||||
{
|
{
|
||||||
var content = new StringContent(@"{}");
|
var content = new StringContent(@"{}");
|
||||||
var responseMessage = client.PostAsync("auth/refresh_token", content).Result;
|
var responseMessage = await client.PostAsync("auth/refresh_token", content);
|
||||||
Console.WriteLine(responseMessage.Content.ReadAsStringAsync().Result);
|
var bodyFromSPW = await responseMessage.Content.ReadAsStringAsync();
|
||||||
|
var serializedBody = JsonNode.Parse(bodyFromSPW);
|
||||||
|
if (serializedBody == null)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine("error: Some error returned from site.");
|
||||||
|
Console.WriteLine("debug: please, check your authorization token");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine(await responseMessage.Content.ReadAsStringAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return serializedBody != null;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение данных пользователя по юзернейму.
|
/// Получение данных пользователя по юзернейму.
|
||||||
|
|||||||
Reference in New Issue
Block a user