Skip to content

Commit

Permalink
feat: makes request class names more uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxAndreassenRPM committed Nov 30, 2023
1 parent 9066624 commit ad81dd0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 28 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
15 changes: 3 additions & 12 deletions Runtime/AvatarCreator/WebRequests/AuthorizedRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
using ReadyPlayerMe.Core;
using UnityEngine.Networking;
Expand All @@ -23,15 +21,8 @@ public class AuthorizedRequest

if (response is { IsSuccess: false, ResponseCode: 401 })
{
try
{
await AuthManager.RefreshToken();
}
catch (Exception)
{
throw;
}

await AuthManager.RefreshToken();

response = await Send<T>(requestData, ctx);
}

Expand Down

0 comments on commit ad81dd0

Please sign in to comment.