Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #239 from aspriddell/update-roles
Browse files Browse the repository at this point in the history
Update roles
  • Loading branch information
aspriddell authored Jun 12, 2021
2 parents e1b3768 + b1c3c8c commit 7ff6c32
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 105 deletions.
3 changes: 2 additions & 1 deletion DragonFruit.Six.Api.Tests/Dragon6ApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
using DragonFruit.Six.Api.Entities;
using DragonFruit.Six.Api.Extensions;
using DragonFruit.Six.Api.Enums;
using DragonFruit.Six.Api.Services.Developer;

namespace DragonFruit.Six.Api.Tests
{
public abstract class Dragon6ApiTest
{
private static readonly List<AccountInfo> Accounts = new();
protected static readonly Dragon6TestClient Client = new();
protected static readonly Dragon6DeveloperClient Client = new("obN8C3Hgi16twnv9S8LJ1Sdkieh7Hyx7qnXmoHkn6Y");

protected static IEnumerable<OperatorStats> OperatorInfo { get; set; }

Expand Down
33 changes: 0 additions & 33 deletions DragonFruit.Six.Api.Tests/Dragon6TestClient.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace DragonFruit.Six.Api.Services.Developer.Auth
{
public class DeveloperTokenRequest : DeveloperApiRequest
{
public override string Path => $"{BaseEndpoint}/api/token/raw";
public override string Path => $"{BaseEndpoint}/api/v2/dev/token";
}
}
35 changes: 2 additions & 33 deletions DragonFruit.Six.Api/Services/Developer/Dragon6DeveloperClient.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,18 @@
// Dragon6 API Copyright 2020 DragonFruit Network <inbox@dragonfruit.network>
// Licensed under Apache-2. Please refer to the LICENSE file for more info

using DragonFruit.Common.Data.Extensions;
using DragonFruit.Six.Api.Tokens;
using DragonFruit.Six.Api.Services.Developer.Auth;

namespace DragonFruit.Six.Api.Services.Developer
{
public class Dragon6DeveloperClient : Dragon6Client
{
private readonly uint _appId;
private readonly string _appSecret;
private readonly object _lock;

private TokenBase _sessionAuthorization;

public Dragon6DeveloperClient(uint appId, string appSecret)
public Dragon6DeveloperClient(string key)
{
_appId = appId;
_appSecret = appSecret;

_lock = new object();
}

public T Perform<T>(DeveloperApiRequest requestData) where T : class
{
lock (_lock)
{
CheckAuthHeader(requestData);
}

return DirectPerform<T>(requestData);
Authorization = $"Dragon6-Api {key}";
}

protected override TokenBase GetToken() => Perform<Dragon6Token>(new DeveloperTokenRequest());

private void CheckAuthHeader(DeveloperApiRequest request)
{
if ((_sessionAuthorization?.Expired).GetValueOrDefault(true))
{
// we don't want this method running if we're getting the token so use the directperform method
_sessionAuthorization = DirectPerform<DeveloperTokenResponse>(new DeveloperSessionRequest(_appId, _appSecret));
}

request.WithAuthHeader($"Bearer {_sessionAuthorization!.Token}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

namespace DragonFruit.Six.Api.Services.Verification
{
public enum AccountType
public enum AccountRole
{
Blocked = -1,
BlockedByAdmin = -2,
BlockedBySelf = -1,

Normal = 0,

Expand All @@ -14,7 +15,6 @@ public enum AccountType
Verified = 3,
Supporter = 4,
Contributor = 5,

Developer = 100
Developer = 6
}
}
67 changes: 35 additions & 32 deletions DragonFruit.Six.Api/Services/Verification/AccountTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,62 @@ namespace DragonFruit.Six.Api.Services.Verification
{
public static class AccountTypeExtensions
{
public static string GetName(this Dragon6AccountInfo dragon6User) => string.IsNullOrEmpty(dragon6User.CustomTitle) ? GetDefaultName(dragon6User.AccountType) : dragon6User.CustomTitle;
public static string GetIcon(this Dragon6AccountInfo dragon6User) => string.IsNullOrEmpty(dragon6User.CustomIcon) ? GetDefaultIcon(dragon6User.AccountType) : dragon6User.CustomIcon;
public static string GetColor(this Dragon6AccountInfo dragon6User) => string.IsNullOrEmpty(dragon6User.CustomColour) ? GetDefaultColor(dragon6User.AccountType) : dragon6User.CustomColour;
public static string GetName(this Dragon6AccountInfo dragon6User) => string.IsNullOrEmpty(dragon6User.CustomTitle) ? GetDefaultName(dragon6User.AccountRole) : dragon6User.CustomTitle;
public static string GetIcon(this Dragon6AccountInfo dragon6User) => string.IsNullOrEmpty(dragon6User.CustomIcon) ? GetDefaultIcon(dragon6User.AccountRole) : dragon6User.CustomIcon;
public static string GetColor(this Dragon6AccountInfo dragon6User) => string.IsNullOrEmpty(dragon6User.CustomColour) ? GetDefaultColor(dragon6User.AccountRole) : dragon6User.CustomColour;

/// <summary>
/// Retrieves the default title for the <see cref="AccountType"/> provided
/// Retrieves the default title for the <see cref="AccountRole"/> provided
/// </summary>
private static string GetDefaultName(this AccountType type) => type switch
private static string GetDefaultName(this AccountRole role) => role switch
{
AccountType.Blocked => "Data Blocked by Request",
AccountRole.BlockedByAdmin => "Account blocked by admin",
AccountRole.BlockedBySelf => "Account blocked by owner",

AccountType.Verified => "Verified User",
AccountType.Beta => "Beta Tester",
AccountType.Translator => "Dragon6 Translator",
AccountType.Supporter => "Dragon6 Supporter",
AccountType.Contributor => "Recognised Contributor",
AccountType.Developer => "Dragon6 Admin",
AccountRole.Verified => "Verified User",
AccountRole.Beta => "Beta Tester",
AccountRole.Translator => "Dragon6 Translator",
AccountRole.Supporter => "Dragon6 Supporter",
AccountRole.Contributor => "Recognised Contributor",
AccountRole.Developer => "Dragon6 Admin",

_ => "Standard User",
_ => "Standard User"
};

/// <summary>
/// Retrieves the default icon for the <see cref="AccountType"/> provided
/// Retrieves the default icon for the <see cref="AccountRole"/> provided
/// </summary>
private static string GetDefaultIcon(this AccountType type) => type switch
private static string GetDefaultIcon(this AccountRole role) => role switch
{
AccountType.Blocked => "explore_off",
AccountRole.BlockedByAdmin => "highlight_off",
AccountRole.BlockedBySelf => "explore_off",

AccountType.Verified => "check",
AccountType.Beta => "bug_report",
AccountType.Translator => "translate",
AccountType.Supporter => "favorite",
AccountType.Contributor => "code",
AccountType.Developer => "verified_user",
AccountRole.Verified => "check",
AccountRole.Beta => "bug_report",
AccountRole.Translator => "translate",
AccountRole.Supporter => "favorite",
AccountRole.Contributor => "code",
AccountRole.Developer => "verified_user",

_ => "face",
};

/// <summary>
/// Retrieves the default title colour for the <see cref="AccountType"/> provided
/// Retrieves the default title colour for the <see cref="AccountRole"/> provided
/// </summary>
private static string GetDefaultColor(this AccountType type) => type switch
private static string GetDefaultColor(this AccountRole role) => role switch
{
AccountType.Blocked => "#bd1818",
AccountRole.BlockedByAdmin => "#BD1818",
AccountRole.BlockedBySelf => "#BD1818",

AccountType.Verified => "#20B2AA",
AccountType.Beta => "#FFA500",
AccountType.Translator => "#1f8b4c",
AccountType.Supporter => "#FFB6C1",
AccountType.Contributor => "#3498DB",
AccountType.Developer => "#90EE90",
AccountRole.Verified => "#20B2AA",
AccountRole.Beta => "#FFA500",
AccountRole.Translator => "#1f8b4c",
AccountRole.Supporter => "#FFB6C1",
AccountRole.Contributor => "#3498DB",
AccountRole.Developer => "#90EE90",

_ => "#ffffff",
_ => "#FFFFFF",
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace DragonFruit.Six.Api.Services.Verification
public class Dragon6AccountInfo
{
[JsonProperty("Level")]
public AccountType AccountType { get; set; }
public AccountRole AccountRole { get; set; }

[JsonProperty("Guid")]
public string ProfileId { get; set; }
Expand Down

0 comments on commit 7ff6c32

Please sign in to comment.