Skip to content

Commit

Permalink
Feature: Uniform request naming (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxAndreassenRPM authored Nov 30, 2023
1 parent 9066624 commit 2fea523
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
14 changes: 7 additions & 7 deletions Runtime/AvatarCreator/AuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ReadyPlayerMe.AvatarCreator
public static class AuthManager
{
private const string TAG = nameof(AuthManager);
private static readonly AuthenticationRequests AuthenticationRequests;
private static readonly AuthAPIRequests AuthAPIRequests;
private static UserSession userSession;
public static UserSession UserSession => userSession;

Expand All @@ -25,12 +25,12 @@ public static class AuthManager

static AuthManager()
{
AuthenticationRequests = new AuthenticationRequests(CoreSettingsHandler.CoreSettings.Subdomain);
AuthAPIRequests = new AuthAPIRequests(CoreSettingsHandler.CoreSettings.Subdomain);
}

public static async Task LoginAsAnonymous()
{
userSession = await AuthenticationRequests.LoginAsAnonymous();
userSession = await AuthAPIRequests.LoginAsAnonymous();
IsSignedInAnonymously = true;
}

Expand All @@ -43,14 +43,14 @@ public static void SetUser(UserSession session)

public static async void SendEmailCode(string email)
{
await AuthenticationRequests.SendCodeToEmail(email, userSession.Id);
await AuthAPIRequests.SendCodeToEmail(email, userSession.Id);
}

public static async Task<bool> LoginWithCode(string otp)
{
try
{
userSession = await AuthenticationRequests.LoginWithCode(otp);
userSession = await AuthAPIRequests.LoginWithCode(otp);
IsSignedIn = true;
OnSignedIn?.Invoke(userSession);
return true;
Expand All @@ -64,15 +64,15 @@ public static async Task<bool> LoginWithCode(string otp)

public static async void Signup(string email)
{
await AuthenticationRequests.Signup(email, userSession.Id);
await AuthAPIRequests.Signup(email, userSession.Id);
}

public static async Task RefreshToken()
{
(string, string) newTokens;
try
{
newTokens = await AuthenticationRequests.RefreshToken(userSession.Token, userSession.RefreshToken);
newTokens = await AuthAPIRequests.RefreshToken(userSession.Token, userSession.RefreshToken);
}
catch (Exception e)
{
Expand Down
8 changes: 4 additions & 4 deletions Runtime/AvatarCreator/PartnerAssetsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ public class PartnerAssetsManager : IDisposable
private const string EYE_MASK_SIZE_SIZE = "?w=256";
private const string ASSET_ICON_SIZE = "?w=64";

private readonly PartnerAssetsRequests partnerAssetsRequests;
private readonly AssetAPIRequests assetAPIRequests;

private Dictionary<Category, List<PartnerAsset>> assetsByCategory;
public Action<string> OnError { get; set; }

public PartnerAssetsManager()
{
partnerAssetsRequests = new PartnerAssetsRequests(CoreSettingsHandler.CoreSettings.AppId);
assetAPIRequests = new AssetAPIRequests(CoreSettingsHandler.CoreSettings.AppId);
assetsByCategory = new Dictionary<Category, List<PartnerAsset>>();
}

public async Task<Dictionary<Category, List<PartnerAsset>>> GetAssets(BodyType bodyType, OutfitGender gender, CancellationToken token = default)
{
var startTime = Time.time;

var assets = await partnerAssetsRequests.Get(bodyType, gender, token);
var assets = await assetAPIRequests.Get(bodyType, gender, token);

assetsByCategory = assets.GroupBy(asset => asset.Category).ToDictionary(
group => group.Key,
Expand Down Expand Up @@ -98,7 +98,7 @@ private async Task DownloadIcons(List<PartnerAsset> chunk, Action<string, Textur
{
var url = $"{asset.ImageUrl}{ASSET_ICON_SIZE}";
var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token);
var iconTask = partnerAssetsRequests.GetAssetIcon(url, icon =>
var iconTask = assetAPIRequests.GetAssetIcon(url, icon =>
{
onDownload?.Invoke(asset.Id, icon);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

namespace ReadyPlayerMe.AvatarCreator
{
public class PartnerAssetsRequests
public class AssetAPIRequests
{
private const string TAG = nameof(PartnerAssetsRequests);
private const string TAG = nameof(AssetAPIRequests);
private const int LIMIT = 100;

private readonly AuthorizedRequest authorizedRequest;
private readonly string appId;
private readonly Dictionary<string, Texture> icons;

public PartnerAssetsRequests(string appId)
public AssetAPIRequests(string appId)
{
authorizedRequest = new AuthorizedRequest();
icons = new Dictionary<string, Texture>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

namespace ReadyPlayerMe.AvatarCreator
{
public class AuthenticationRequests
public class AuthAPIRequests
{
private readonly string domain;
private readonly IDictionary<string, string> headers = CommonHeaders.GetHeadersWithAppId();

private readonly WebRequestDispatcher webRequestDispatcher;

public AuthenticationRequests(string domain)
public AuthAPIRequests(string domain)
{
this.domain = domain;
webRequestDispatcher = new WebRequestDispatcher();
Expand Down
3 changes: 2 additions & 1 deletion Runtime/AvatarCreator/WebRequests/AuthorizedRequest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ReadyPlayerMe.Core;
Expand Down Expand Up @@ -27,6 +26,8 @@ public class AuthorizedRequest
{
await AuthManager.RefreshToken();
}
// Despite this seeming redundant, it prevents an issue with any error within AuthManager.RefreshToken not being propagated without it.
// TODO: Figure out why this is needed and work out a way to clean it up.
catch (Exception)
{
throw;
Expand Down

0 comments on commit 2fea523

Please sign in to comment.