mirror of
https://github.com/yawaflua/spworlds-csharp-library.git
synced 2025-12-10 04:29:25 +02:00
0
gitignore → .gitignore
vendored
0
gitignore → .gitignore
vendored
22
Deserialize.cs
Normal file
22
Deserialize.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace spworlds
|
||||||
|
{
|
||||||
|
internal class Deserialize
|
||||||
|
{
|
||||||
|
public static T DeserializeObject<T>(string data) where T : class
|
||||||
|
{
|
||||||
|
T objectToReturn = JsonConvert.DeserializeObject<T>(data);
|
||||||
|
if (objectToReturn == null)
|
||||||
|
throw new Exception("User not player.");
|
||||||
|
else
|
||||||
|
return objectToReturn;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Types/Card.cs
Normal file
14
Types/Card.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace spworlds.Types
|
||||||
|
{
|
||||||
|
public class Card
|
||||||
|
{
|
||||||
|
public int Balance { get; set; }
|
||||||
|
public string Webhook { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,15 @@
|
|||||||
namespace spworlds.Types;
|
namespace spworlds.Types;
|
||||||
|
|
||||||
|
public class Item
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int Count { get; set; }
|
||||||
|
public int Price { get; set; }
|
||||||
|
public string? Comment { get; set; } = null;
|
||||||
|
}
|
||||||
public class PaymentData
|
public class PaymentData
|
||||||
{
|
{
|
||||||
public int Amount;
|
public Item[] Items;
|
||||||
public string RedirectUrl;
|
public string RedirectUrl;
|
||||||
public string WebHookUrl;
|
public string WebHookUrl;
|
||||||
public string Data;
|
public string Data;
|
||||||
|
|||||||
41
Types/UserAccount.cs
Normal file
41
Types/UserAccount.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace spworlds.Types
|
||||||
|
{
|
||||||
|
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
|
||||||
|
public class MyCard
|
||||||
|
{
|
||||||
|
public string id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
public string number { get; set; }
|
||||||
|
public int color { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class City
|
||||||
|
{
|
||||||
|
public string id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
public string description { get; set; }
|
||||||
|
public int x { get; set; }
|
||||||
|
public int z { get; set; }
|
||||||
|
public bool isMayor { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UserAccount
|
||||||
|
{
|
||||||
|
public string id { get; set; }
|
||||||
|
public string username { get; set; }
|
||||||
|
public string minecraftUUID { get; set; }
|
||||||
|
public string status { get; set; }
|
||||||
|
public List<object> roles { get; set; }
|
||||||
|
public City city { get; set; }
|
||||||
|
public List<UserCard> cards { get; set; }
|
||||||
|
public DateTime createdAt { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
14
Types/UserCard.cs
Normal file
14
Types/UserCard.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace spworlds.Types
|
||||||
|
{
|
||||||
|
public class UserCard
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int Number { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Types/WebhookResponse.cs
Normal file
14
Types/WebhookResponse.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace spworlds.Types
|
||||||
|
{
|
||||||
|
public class WebhookResponse
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Webhook { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
|
// Runtime Version:4.0.30319.42000
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
@@ -15,7 +16,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyDescriptionAttribute("данная библиотека предназначена для работы с сайтом spworlds. Ознакомиться с доку" +
|
[assembly: System.Reflection.AssemblyDescriptionAttribute("данная библиотека предназначена для работы с сайтом spworlds. Ознакомиться с доку" +
|
||||||
"ментацией можно в гитхабе проекта")]
|
"ментацией можно в гитхабе проекта")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.5.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.5.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.5")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.5+2a1317d393845b4d8c2aebe83482addf91da2948")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("spworlds")]
|
[assembly: System.Reflection.AssemblyProductAttribute("spworlds")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("spworlds")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("spworlds")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.5.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.5.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
16a07a97f6c3ac88ffd8da0fdc03f5c5f3aadf69
|
408e46d4b0c697d197fb7b372e95e1f96ce6875650810a4a0ad66dc759971202
|
||||||
|
|||||||
@@ -8,4 +8,6 @@ build_property.PlatformNeutralAssembly =
|
|||||||
build_property.EnforceExtendedAnalyzerRules =
|
build_property.EnforceExtendedAnalyzerRules =
|
||||||
build_property._SupportedPlatformList = Linux,macOS,Windows
|
build_property._SupportedPlatformList = Linux,macOS,Windows
|
||||||
build_property.RootNamespace = spworlds
|
build_property.RootNamespace = spworlds
|
||||||
build_property.ProjectDir = C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\
|
build_property.ProjectDir = C:\Users\yawaflua\Source\Repos\spworlds-csharp-library\
|
||||||
|
build_property.EnableComHosting =
|
||||||
|
build_property.EnableGeneratedComInterfaceComImportInterop =
|
||||||
|
|||||||
Binary file not shown.
@@ -1,30 +1,77 @@
|
|||||||
{
|
{
|
||||||
"version": 3,
|
"version": 3,
|
||||||
"targets": {
|
"targets": {
|
||||||
"net6.0": {}
|
"net6.0": {
|
||||||
|
"Newtonsoft.Json/13.0.3": {
|
||||||
|
"type": "package",
|
||||||
|
"compile": {
|
||||||
|
"lib/net6.0/Newtonsoft.Json.dll": {
|
||||||
|
"related": ".xml"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"runtime": {
|
||||||
|
"lib/net6.0/Newtonsoft.Json.dll": {
|
||||||
|
"related": ".xml"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"libraries": {
|
||||||
|
"Newtonsoft.Json/13.0.3": {
|
||||||
|
"sha512": "HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==",
|
||||||
|
"type": "package",
|
||||||
|
"path": "newtonsoft.json/13.0.3",
|
||||||
|
"files": [
|
||||||
|
".nupkg.metadata",
|
||||||
|
".signature.p7s",
|
||||||
|
"LICENSE.md",
|
||||||
|
"README.md",
|
||||||
|
"lib/net20/Newtonsoft.Json.dll",
|
||||||
|
"lib/net20/Newtonsoft.Json.xml",
|
||||||
|
"lib/net35/Newtonsoft.Json.dll",
|
||||||
|
"lib/net35/Newtonsoft.Json.xml",
|
||||||
|
"lib/net40/Newtonsoft.Json.dll",
|
||||||
|
"lib/net40/Newtonsoft.Json.xml",
|
||||||
|
"lib/net45/Newtonsoft.Json.dll",
|
||||||
|
"lib/net45/Newtonsoft.Json.xml",
|
||||||
|
"lib/net6.0/Newtonsoft.Json.dll",
|
||||||
|
"lib/net6.0/Newtonsoft.Json.xml",
|
||||||
|
"lib/netstandard1.0/Newtonsoft.Json.dll",
|
||||||
|
"lib/netstandard1.0/Newtonsoft.Json.xml",
|
||||||
|
"lib/netstandard1.3/Newtonsoft.Json.dll",
|
||||||
|
"lib/netstandard1.3/Newtonsoft.Json.xml",
|
||||||
|
"lib/netstandard2.0/Newtonsoft.Json.dll",
|
||||||
|
"lib/netstandard2.0/Newtonsoft.Json.xml",
|
||||||
|
"newtonsoft.json.13.0.3.nupkg.sha512",
|
||||||
|
"newtonsoft.json.nuspec",
|
||||||
|
"packageIcon.png"
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"libraries": {},
|
|
||||||
"projectFileDependencyGroups": {
|
"projectFileDependencyGroups": {
|
||||||
"net6.0": []
|
"net6.0": [
|
||||||
|
"Newtonsoft.Json >= 13.0.3"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"packageFolders": {
|
"packageFolders": {
|
||||||
"C:\\Users\\losev\\.nuget\\packages\\": {},
|
"C:\\Users\\yawaflua\\.nuget\\packages\\": {},
|
||||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
|
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
|
||||||
},
|
},
|
||||||
"project": {
|
"project": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
"restore": {
|
"restore": {
|
||||||
"projectUniqueName": "C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\spworlds.csproj",
|
"projectUniqueName": "C:\\Users\\yawaflua\\Source\\Repos\\spworlds-csharp-library\\spworlds.csproj",
|
||||||
"projectName": "spworlds",
|
"projectName": "spworlds",
|
||||||
"projectPath": "C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\spworlds.csproj",
|
"projectPath": "C:\\Users\\yawaflua\\Source\\Repos\\spworlds-csharp-library\\spworlds.csproj",
|
||||||
"packagesPath": "C:\\Users\\losev\\.nuget\\packages\\",
|
"packagesPath": "C:\\Users\\yawaflua\\.nuget\\packages\\",
|
||||||
"outputPath": "C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\obj\\",
|
"outputPath": "C:\\Users\\yawaflua\\Source\\Repos\\spworlds-csharp-library\\obj\\",
|
||||||
"projectStyle": "PackageReference",
|
"projectStyle": "PackageReference",
|
||||||
"fallbackFolders": [
|
"fallbackFolders": [
|
||||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
||||||
],
|
],
|
||||||
"configFilePaths": [
|
"configFilePaths": [
|
||||||
"C:\\Users\\losev\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
"C:\\Users\\yawaflua\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
||||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||||
],
|
],
|
||||||
@@ -45,11 +92,22 @@
|
|||||||
"warnAsError": [
|
"warnAsError": [
|
||||||
"NU1605"
|
"NU1605"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"restoreAuditProperties": {
|
||||||
|
"enableAudit": "true",
|
||||||
|
"auditLevel": "low",
|
||||||
|
"auditMode": "direct"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net6.0": {
|
"net6.0": {
|
||||||
"targetAlias": "net6.0",
|
"targetAlias": "net6.0",
|
||||||
|
"dependencies": {
|
||||||
|
"Newtonsoft.Json": {
|
||||||
|
"target": "Package",
|
||||||
|
"version": "[13.0.3, )"
|
||||||
|
}
|
||||||
|
},
|
||||||
"imports": [
|
"imports": [
|
||||||
"net461",
|
"net461",
|
||||||
"net462",
|
"net462",
|
||||||
@@ -66,7 +124,7 @@
|
|||||||
"privateAssets": "all"
|
"privateAssets": "all"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.401\\RuntimeIdentifierGraph.json"
|
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.204\\RuntimeIdentifierGraph.json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
{
|
{
|
||||||
"version": 2,
|
"version": 2,
|
||||||
"dgSpecHash": "p7cKQ/JzbW/pFxNjOXo5Xhfj5ODn4c+I/3V85sntBWgUuc5uosay2iPDLl5YmDVFkvR7Suoevt+A+2w9fpQxjw==",
|
"dgSpecHash": "wn8UpI/92drj7Y9CQl+s7VBYfOMeRffRtWpQCB7W3D+sZ2Noiue7K9viVJxtJpvymvDsYPRnQ4JHorfg+z+nsQ==",
|
||||||
"success": true,
|
"success": true,
|
||||||
"projectFilePath": "C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\spworlds.csproj",
|
"projectFilePath": "C:\\Users\\yawaflua\\Source\\Repos\\spworlds-csharp-library\\spworlds.csproj",
|
||||||
"expectedPackageFiles": [],
|
"expectedPackageFiles": [
|
||||||
|
"C:\\Users\\yawaflua\\.nuget\\packages\\newtonsoft.json\\13.0.3\\newtonsoft.json.13.0.3.nupkg.sha512"
|
||||||
|
],
|
||||||
"logs": []
|
"logs": []
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,23 @@
|
|||||||
{
|
{
|
||||||
"format": 1,
|
"format": 1,
|
||||||
"restore": {
|
"restore": {
|
||||||
"C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\spworlds.csproj": {}
|
"C:\\Users\\yawaflua\\Source\\Repos\\spworlds-csharp-library\\spworlds.csproj": {}
|
||||||
},
|
},
|
||||||
"projects": {
|
"projects": {
|
||||||
"C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\spworlds.csproj": {
|
"C:\\Users\\yawaflua\\Source\\Repos\\spworlds-csharp-library\\spworlds.csproj": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
"restore": {
|
"restore": {
|
||||||
"projectUniqueName": "C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\spworlds.csproj",
|
"projectUniqueName": "C:\\Users\\yawaflua\\Source\\Repos\\spworlds-csharp-library\\spworlds.csproj",
|
||||||
"projectName": "spworlds",
|
"projectName": "spworlds",
|
||||||
"projectPath": "C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\spworlds.csproj",
|
"projectPath": "C:\\Users\\yawaflua\\Source\\Repos\\spworlds-csharp-library\\spworlds.csproj",
|
||||||
"packagesPath": "C:\\Users\\losev\\.nuget\\packages\\",
|
"packagesPath": "C:\\Users\\yawaflua\\.nuget\\packages\\",
|
||||||
"outputPath": "C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\obj\\",
|
"outputPath": "C:\\Users\\yawaflua\\Source\\Repos\\spworlds-csharp-library\\obj\\",
|
||||||
"projectStyle": "PackageReference",
|
"projectStyle": "PackageReference",
|
||||||
"fallbackFolders": [
|
"fallbackFolders": [
|
||||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
||||||
],
|
],
|
||||||
"configFilePaths": [
|
"configFilePaths": [
|
||||||
"C:\\Users\\losev\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
"C:\\Users\\yawaflua\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
||||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||||
],
|
],
|
||||||
@@ -38,11 +38,22 @@
|
|||||||
"warnAsError": [
|
"warnAsError": [
|
||||||
"NU1605"
|
"NU1605"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"restoreAuditProperties": {
|
||||||
|
"enableAudit": "true",
|
||||||
|
"auditLevel": "low",
|
||||||
|
"auditMode": "direct"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net6.0": {
|
"net6.0": {
|
||||||
"targetAlias": "net6.0",
|
"targetAlias": "net6.0",
|
||||||
|
"dependencies": {
|
||||||
|
"Newtonsoft.Json": {
|
||||||
|
"target": "Package",
|
||||||
|
"version": "[13.0.3, )"
|
||||||
|
}
|
||||||
|
},
|
||||||
"imports": [
|
"imports": [
|
||||||
"net461",
|
"net461",
|
||||||
"net462",
|
"net462",
|
||||||
@@ -59,7 +70,7 @@
|
|||||||
"privateAssets": "all"
|
"privateAssets": "all"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.401\\RuntimeIdentifierGraph.json"
|
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.204\\RuntimeIdentifierGraph.json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
||||||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
||||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\losev\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
|
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\yawaflua\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
|
||||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.7.0</NuGetToolVersion>
|
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.9.2</NuGetToolVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||||
<SourceRoot Include="C:\Users\losev\.nuget\packages\" />
|
<SourceRoot Include="C:\Users\yawaflua\.nuget\packages\" />
|
||||||
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
|
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
147
spworlds.cs
147
spworlds.cs
@@ -6,8 +6,11 @@ using System.Security.Cryptography;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
using spworlds.Types;
|
using spworlds.Types;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
namespace spworlds;
|
namespace spworlds;
|
||||||
|
|
||||||
|
|
||||||
public class SPWorlds
|
public class SPWorlds
|
||||||
{
|
{
|
||||||
private readonly HttpClient client;
|
private readonly HttpClient client;
|
||||||
@@ -24,49 +27,65 @@ public class SPWorlds
|
|||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Base64BearerToken);
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Base64BearerToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> ValidateWebHook(string webHook, string bodyHash)
|
/// <summary>
|
||||||
|
/// Validating wenhook from site
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="requestBody">Body of request</param>
|
||||||
|
/// <param name="base64Hash">X-Body-Hash</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool ValidateWebhook(string requestBody, string base64Hash)
|
||||||
{
|
{
|
||||||
byte[] body = Encoding.UTF8.GetBytes(bodyHash);
|
byte[] requestData = Encoding.UTF8.GetBytes(requestBody);
|
||||||
byte[] webhook = Encoding.UTF8.GetBytes(webHook);
|
|
||||||
var key = new HMACSHA256(Encoding.UTF8.GetBytes(token));
|
using (HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(token)))
|
||||||
string webhook64 = Convert.ToBase64String(key.ComputeHash(webhook));
|
{
|
||||||
return webhook64.Equals(body);
|
byte[] hashBytes = hmac.ComputeHash(requestData);
|
||||||
|
|
||||||
|
string computedHash = Convert.ToBase64String(hashBytes);
|
||||||
|
|
||||||
|
return base64Hash.Equals(computedHash);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<string> SendRequest(string endpoint, Boolean getResult = true, Dictionary<string, object>? body = null)
|
private async Task<string> SendRequest(string endpoint, bool getResult = true, HttpMethod method = null, object body = null)
|
||||||
{
|
{
|
||||||
string respond;
|
method ??= body == null ? HttpMethod.Get : HttpMethod.Post;
|
||||||
string jsonBody;
|
HttpResponseMessage message;
|
||||||
|
|
||||||
if (body == null)
|
using (var requestMessage = new HttpRequestMessage(method, client.BaseAddress + endpoint))
|
||||||
{
|
{
|
||||||
return respond = client.GetAsync(endpoint).Result.Content.ReadAsStringAsync().Result;
|
requestMessage.Content = new StringContent(
|
||||||
|
JsonSerializer.Serialize(body),
|
||||||
|
Encoding.UTF8, "application/json"
|
||||||
|
);
|
||||||
|
requestMessage.Headers.Authorization = client.DefaultRequestHeaders.Authorization;
|
||||||
|
|
||||||
|
message = await client.SendAsync(requestMessage);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
jsonBody = JsonSerializer.Serialize(body);
|
|
||||||
var payload = new StringContent(jsonBody, Encoding.UTF8, "application/json");
|
|
||||||
|
|
||||||
if (getResult)
|
if (getResult)
|
||||||
return respond = client.PostAsync(endpoint, payload).Result.Content.ReadAsStringAsync().Result;
|
return await message.Content.ReadAsStringAsync();
|
||||||
else
|
else
|
||||||
await client.PostAsync(endpoint, payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> GetBalance()
|
|
||||||
{
|
|
||||||
string respond = await SendRequest("card");
|
|
||||||
|
|
||||||
var card = JsonObject.Parse(respond);
|
/// <summary>
|
||||||
var balance = card["balance"];
|
/// Get card from spworlds
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<Card> GetCard()
|
||||||
|
=> Deserialize.DeserializeObject<Card>(await SendRequest("card"));
|
||||||
|
|
||||||
return (int)balance;
|
/// <summary>
|
||||||
}
|
/// Create transaction
|
||||||
|
/// </summary>
|
||||||
public async Task CreateTransaction(string receiver, int amount, string comment)
|
/// <param name="receiver">receiver card</param>
|
||||||
|
/// <param name="amount">amount of AR</param>
|
||||||
|
/// <param name="comment">comment to transaction</param>
|
||||||
|
/// <returns>balance of card</returns>
|
||||||
|
public async Task<int> CreateTransaction(string receiver, int amount, string comment)
|
||||||
{
|
{
|
||||||
var transitionInfo = new Dictionary<string, object>
|
var transitionInfo = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
@@ -75,21 +94,41 @@ public class SPWorlds
|
|||||||
{ "comment", comment }
|
{ "comment", comment }
|
||||||
};
|
};
|
||||||
|
|
||||||
await SendRequest(endpoint: "transactions", body: transitionInfo);
|
var response = JsonObject.Parse(await SendRequest(endpoint: "transactions", body: transitionInfo, getResult: true));
|
||||||
|
return (int)response["balance"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get user cards by nickname
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="username">Username of player</param>
|
||||||
|
/// <returns>Array of cards</returns>
|
||||||
|
public async Task<UserCard[]> GetUserCardsAsync(string username)
|
||||||
|
=> Deserialize.DeserializeObject<UserCard[]>(await SendRequest($"accounts/{username}/cards"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get user info from site
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="discordId">Discord id of user</param>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task<User> GetUser(string discordId)
|
public async Task<User> GetUser(string discordId)
|
||||||
{
|
=> Deserialize.DeserializeObject<User>(await SendRequest($"users/{discordId}"));
|
||||||
string userName = (string)JsonObject.Parse(await SendRequest($"users/{discordId}"))["username"];
|
|
||||||
User user = await User.CreateUser(userName);
|
|
||||||
return (User)user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<string> InitPayment(int amount, string redirectUrl, string webhookUrl, string data)
|
/// <summary>
|
||||||
|
/// Create payment url
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items">List of items</param>
|
||||||
|
/// <param name="redirectUrl">User will be redirected to this url</param>
|
||||||
|
/// <param name="webhookUrl">Webhook will be sended to this url</param>
|
||||||
|
/// <param name="data">Data, returned with webhook</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<string> InitPayment(Item[] items, string redirectUrl, string webhookUrl, string data)
|
||||||
{
|
{
|
||||||
var paymentInfo = new Dictionary<string, object>
|
var paymentInfo = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "amount", amount },
|
{ "items", JsonSerializer.Serialize(items)},
|
||||||
{ "redirectUrl", redirectUrl },
|
{ "redirectUrl", redirectUrl },
|
||||||
{ "webhookUrl", webhookUrl },
|
{ "webhookUrl", webhookUrl },
|
||||||
{ "data", data }
|
{ "data", data }
|
||||||
@@ -101,20 +140,34 @@ public class SPWorlds
|
|||||||
return (string)url;
|
return (string)url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create payment url
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="paymentData"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task<string> InitPayment(PaymentData paymentData)
|
public async Task<string> InitPayment(PaymentData paymentData)
|
||||||
{
|
{
|
||||||
var paymentInfo = new Dictionary<string, object>
|
var payment = JsonObject.Parse(await SendRequest(endpoint: $"payment", body: JsonSerializer.Serialize(paymentData)));
|
||||||
|
return (string)payment["url"];
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Setting up a webhook to card
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="webhookUrl">Url of webhook</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<WebhookResponse> SetWebhook(string webhookUrl)
|
||||||
|
=> Deserialize.DeserializeObject<WebhookResponse>(
|
||||||
|
await SendRequest(
|
||||||
|
"card/webhook",
|
||||||
|
true,
|
||||||
|
HttpMethod.Put,
|
||||||
|
new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
{ "amount", paymentData.Amount },
|
{ "url", webhookUrl }
|
||||||
{ "redirectUrl", paymentData.RedirectUrl },
|
|
||||||
{ "webhookUrl", paymentData.WebHookUrl },
|
|
||||||
{ "data", paymentData.Data }
|
|
||||||
};
|
|
||||||
|
|
||||||
var payment = JsonObject.Parse(await SendRequest(endpoint: $"payment", body: paymentInfo));
|
|
||||||
var url = payment["url"];
|
|
||||||
|
|
||||||
return (string)url;
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
public async Task<UserAccount> GetMeAsync()
|
||||||
|
=> Deserialize.DeserializeObject<UserAccount>(await SendRequest("accounts/me"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,4 +18,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user