init commit

main
exsersewo 3 years ago
commit e562a90c35
Signed by: exsersewo
GPG Key ID: 9C6DDF9AC9BA14A0
  1. 63
      .gitattributes
  2. 270
      .gitignore
  3. 121
      Interfaces/ISkuldAPIClient.cs
  4. 15
      Skuld.API.csproj
  5. 176
      SkuldAPI.cs

63
.gitattributes vendored

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

270
.gitignore vendored

@ -0,0 +1,270 @@
.cr/
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
Commands/Skuld.Owner/
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 cache/plugin data directory
.cr/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
launchSettings.json
.env

@ -0,0 +1,121 @@
using RestEase;
using Skuld.Core.Models;
using Skuld.Models;
using System;
using System.IO;
using System.Threading.Tasks;
namespace Skuld.API
{
public interface ISkuldAPIClient : IDisposable
{
#region Guild
/// <summary>
/// Get a guild
/// </summary>
/// <param name="id">Guild Id</param>
/// <returns><see cref="EventResult{T}"/> wrapped <see cref="Guild"/></returns>
[Get("/guild/{id}")]
public Task<EventResult> GetGuildAsync([Path] ulong id);
#endregion Guild
#region User
/// <summary>
/// Get a user
/// </summary>
/// <param name="id">User Id</param>
/// <returns><see cref="EventResult{T}"/> wrapped <see cref="User"/></returns>
[Get("/user/{id}")]
public Task<EventResult> GetUserAsync([Path] ulong id);
#endregion User
#region Experience
/// <summary>
/// Gets the experience leaderboard
/// </summary>
/// <param name="guildId">Guild Id, Accepts 0 for all</param>
/// <param name="page">%10 offset page</param>
/// <returns><see cref="EventResult{T}"/> wrapped <see cref="UserExperience"/></returns>
[Get("/experience/{guildId}/{page}")]
public Task<EventResult> GetExperienceLeaderboardAsync([Path] ulong guildId, [Path] int page = 0);
#endregion Experience
#region Money
/// <summary>
/// Gets the money leaderboard
/// </summary>
/// <param name="guildId">Guild Id, Accepts 0 for all</param>
/// <param name="page">%10 offset page</param>
/// <returns><see cref="EventResult{T}"/> wrapped <see cref="User"/></returns>
[Get("/money/{guildId}/{page}")]
public Task<EventResult> GetMoneyLeaderboardAsync([Path] ulong guildId, [Path] int page = 0);
#endregion Money
#region Profile
/// <summary>
/// Get a user's profile card
/// </summary>
/// <param name="id">User Id</param>
/// <returns><see cref="Stream"/> of profile card data</returns>
[Get("/image/profile/{id}")]
public Task<Stream> GetProfileCardAsync([Path] ulong id);
/// <summary>
/// Get a user's profile card with guild attributes
/// </summary>
/// <param name="id">User Id</param>
/// <param name="id">Guild Id</param>
/// <returns><see cref="Stream"/> of profile card data</returns>
[Get("/image/profile/{id}/{guildId}")]
public Task<Stream> GetProfileCardAsync([Path] ulong id, [Path] ulong guildId);
/// <summary>
/// Preview's a custom background image
/// </summary>
/// <param name="id">User Id</param>
/// <param name="previewBackground">Background to preview</param>
/// <returns><see cref="Stream"/> of profile card data</returns>
[Get("/image/profile/{id}/example")]
public Task<Stream> GetExampleProfileCardAsync([Path] ulong id, [Query("previewBackground")] string previewBackground);
#endregion Profile
#region Rank
/// <summary>
/// Get a user's rank card
/// </summary>
/// <param name="id">User Id</param>
/// <param name="guildId">Guild Id</param>
/// <returns><see cref="Stream"/> of profile card data</returns>
[Get("/image/rank/{id}/{guildId}")]
public Task<Stream> GetRankCardAsync([Path] ulong id, [Path] ulong guildId);
#endregion Rank
#region Leave/Join Card
/// <summary>
/// Get's the join card for a guild
/// </summary>
/// <param name="id">User Id</param>
/// <param name="guildId">Guild Id</param>
/// <returns><see cref="Stream"/> of join card</returns>
[Get("/image/join/{id}/{guildId}")]
public Task<Stream> GetJoinCardAsync([Path] ulong id, [Path] ulong guildId);
/// <summary>
/// Get's the leave card for a guild
/// </summary>
/// <param name="id">User Id</param>
/// <param name="guildId">Guild Id</param>
/// <returns><see cref="Stream"/> of leave card</returns>
[Get("/image/leave/{id}/{guildId}")]
public Task<Stream> GetLeaveCardAsync([Path] ulong id, [Path] ulong guildId);
#endregion Leave/Join Card
[Get("/image/magik")]
public Task<Stream> GetLiquidRescaledAsync([Query] string image);
}
}

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RestEase" Version="1.5.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Skuld.Models\Skuld.Models\Skuld.Models.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,176 @@
using Newtonsoft.Json;
using RestEase;
using Skuld.Core.Models;
using System;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
namespace Skuld.API
{
public class SkuldAPI : ISkuldAPIClient, IDisposable
{
public static string WrapperVersion { get; } =
typeof(SkuldAPI).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ??
typeof(SkuldAPI).GetTypeInfo().Assembly.GetName().Version.ToString(3) ??
"Unknown";
private readonly ISkuldAPIClient _api;
static string ApiBase;
static string Token;
private bool disposedValue;
public SkuldAPI()
{
}
public SkuldAPI(string apiBase, string token)
{
ApiBase = apiBase;
Token = token;
var httpClient = new HttpClient
{
BaseAddress = new Uri(ApiBase)
};
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Skuld.API.Client/v{WrapperVersion} (https://github.com/skuldbot/Skuld)");
if (!string.IsNullOrWhiteSpace(Token))
{
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {Token}");
}
JsonSerializerSettings settings = new()
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
_api = new RestClient(httpClient)
{
JsonSerializerSettings = settings
}.For<ISkuldAPIClient>();
}
/// <summary>
/// Get a guild
/// </summary>
/// <param name="id">Guild Id</param>
/// <returns><see cref="EventResult{T}"/> wrapped <see cref="Guild"/></returns>
public Task<EventResult> GetGuildAsync(ulong id)
=> !string.IsNullOrWhiteSpace(Token) ? _api.GetGuildAsync(id) : null;
/// <summary>
/// Get a user
/// </summary>
/// <param name="id">User Id</param>
/// <returns><see cref="EventResult{T}"/> wrapped <see cref="User"/></returns>
public Task<EventResult> GetUserAsync(ulong id)
=> !string.IsNullOrWhiteSpace(Token) ? _api.GetUserAsync(id) : null;
/// <summary>
/// Get a user's profile card
/// </summary>
/// <param name="id">User Id</param>
/// <returns><see cref="Stream"/> of profile card data</returns>
public Task<Stream> GetProfileCardAsync(ulong id)
=> !string.IsNullOrWhiteSpace(Token) ? _api.GetProfileCardAsync(id) : null;
/// <summary>
/// Get a user's profile card with guild attributes
/// </summary>
/// <param name="id">User Id</param>
/// <param name="id">Guild Id</param>
/// <returns><see cref="Stream"/> of profile card data</returns>
public Task<Stream> GetProfileCardAsync(ulong id, ulong guildId)
=> !string.IsNullOrWhiteSpace(Token) ? _api.GetProfileCardAsync(id, guildId) : null;
/// <summary>
/// Get a user's rank card
/// </summary>
/// <param name="id">User Id</param>
/// <param name="guildId">Guild Id</param>
/// <returns><see cref="Stream"/> of profile card data</returns>
public Task<Stream> GetRankCardAsync(ulong id, ulong guildId)
=> !string.IsNullOrWhiteSpace(Token) ? _api.GetRankCardAsync(id, guildId) : null;
/// <summary>
/// Preview's a custom background image
/// </summary>
/// <param name="id">User Id</param>
/// <param name="previewBackground">Background to preview</param>
/// <returns><see cref="Stream"/> of profile card data</returns>
public Task<Stream> GetExampleProfileCardAsync(ulong id, string previewBackground)
=> !string.IsNullOrWhiteSpace(Token) ? _api.GetExampleProfileCardAsync(id, previewBackground) : null;
/// <summary>
/// Gets the experience leaderboard
/// </summary>
/// <param name="guildId">Guild Id, Accepts 0 for all</param>
/// <param name="page">%10 offset page</param>
/// <returns><see cref="EventResult{T}"/> wrapped <see cref="UserExperience"/></returns>
public Task<EventResult> GetExperienceLeaderboardAsync(ulong guildId, int page = 0)
=> !string.IsNullOrWhiteSpace(Token) ? _api.GetExperienceLeaderboardAsync(guildId, page) : null;
/// <summary>
/// Gets the money leaderboard
/// </summary>
/// <param name="guildId">Guild Id, Accepts 0 for all</param>
/// <param name="page">%10 offset page</param>
/// <returns><see cref="EventResult{T}"/> wrapped <see cref="User"/></returns>
public Task<EventResult> GetMoneyLeaderboardAsync(ulong guildId, int page = 0)
=> !string.IsNullOrWhiteSpace(Token) ? _api.GetMoneyLeaderboardAsync(guildId, page) : null;
public Task<Stream> GetLiquidRescaledAsync(string image)
=> !string.IsNullOrWhiteSpace(Token) ? _api.GetLiquidRescaledAsync(image) : null;
/// <summary>
/// Get's the join card for a guild
/// </summary>
/// <param name="id">User Id</param>
/// <param name="guildId">Guild Id</param>
/// <returns><see cref="Stream"/> of join card</returns>
public Task<Stream> GetJoinCardAsync(ulong id, ulong guildId)
=> !string.IsNullOrWhiteSpace(Token) ? _api.GetJoinCardAsync(id, guildId) : null;
/// <summary>
/// Get's the leave card for a guild
/// </summary>
/// <param name="id">User Id</param>
/// <param name="guildId">Guild Id</param>
/// <returns><see cref="Stream"/> of leave card</returns>
public Task<Stream> GetLeaveCardAsync(ulong id, ulong guildId)
=> !string.IsNullOrWhiteSpace(Token) ? _api.GetLeaveCardAsync(id, guildId) : null;
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
disposedValue = true;
}
}
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~SkuldAPI()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
Loading…
Cancel
Save