mirror of
https://github.com/yawaflua/SPWorldsWrapper.git
synced 2025-12-11 16:16:22 +02:00
Compare commits
8 Commits
v1.0.3
...
yawaflua-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01cc988f85 | ||
|
|
c84dbecbaf | ||
|
|
8b0043e1ab | ||
|
|
b513e9489d | ||
|
|
46f184d775 | ||
|
|
85c4d5e099 | ||
|
|
1f81fd5cbd | ||
|
|
1201e16caa |
4
.github/workflows/nuget.yml
vendored
4
.github/workflows/nuget.yml
vendored
@@ -12,7 +12,7 @@ jobs:
|
||||
- name: Setup .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: '8.x.x'
|
||||
dotnet-version: '7.x.x'
|
||||
- name: Set output
|
||||
id: vars
|
||||
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
PROJECT_FILE_PATH: SPWorldsWrapper/SPWorldsWrapper.csproj
|
||||
VERSION_STATIC: ${{ steps.vars.outputs.tags }}
|
||||
TAG_COMMIT: true
|
||||
TAG_FORMAT: '*'
|
||||
TAG_FORMAT: ${{ steps.meta.outputs.tags }}
|
||||
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
|
||||
NUGET_SOURCE: https://api.nuget.org
|
||||
INCLUDE_SYMBOLS: false
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPWorldsWrapper
|
||||

|
||||

|
||||
|
||||
Actions pass:
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PackageId>SPWorldsWrapper</PackageId>
|
||||
<Description>Библиотека для работы с сайтом spworlds.ru</Description>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<Version>1.0.2</Version>
|
||||
<Version>1.0.5</Version>
|
||||
<Authors>yawaflua</Authors>
|
||||
<Company>yawaflua</Company>
|
||||
<RepositoryUrl>https://github.com/yawaflua/SPWorldsWrapper</RepositoryUrl>
|
||||
|
||||
@@ -2,13 +2,22 @@
|
||||
using SPWorldsWrapper.Types;
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
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 readonly HttpClient client;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Асинхронный wrapper для работы напрямую с сайтом, а не с API SPWorlds.ru
|
||||
@@ -21,7 +30,11 @@ namespace SPWorldsWrapper
|
||||
client = new(handler);
|
||||
client.BaseAddress = new Uri("https://spworlds.ru/api/");
|
||||
cookieContainer.Add(client.BaseAddress, new Cookie("jeff", token));
|
||||
spwLogin();
|
||||
var spwLoginMethod = spwLogin();
|
||||
if (!spwLoginMethod.Result)
|
||||
{
|
||||
throw new AuthentificationError("Ошибка парсинга данных от сайта. Проверьте токен, IP сервера и статус сайта SPWORLDS.RU");
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
@@ -30,11 +43,24 @@ namespace SPWorldsWrapper
|
||||
/// Если иное - токен слетел!
|
||||
/// </summary>
|
||||
/// <returns>Ничего</returns>
|
||||
public void spwLogin()
|
||||
public async Task<bool> spwLogin()
|
||||
{
|
||||
var content = new StringContent(@"{}");
|
||||
var responseMessage = client.PostAsync("auth/refresh_token", content).Result;
|
||||
Console.WriteLine(responseMessage.Content.ReadAsStringAsync().Result);
|
||||
var responseMessage = await client.PostAsync("auth/refresh_token", content);
|
||||
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>
|
||||
/// Получение данных пользователя по юзернейму.
|
||||
|
||||
Reference in New Issue
Block a user