Skip to content

Commit

Permalink
feat: adds dynamically loaded vars
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxAndreassenRPM committed Nov 29, 2023
1 parent b5a254d commit 4c9bb4a
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 21 deletions.
10 changes: 7 additions & 3 deletions Runtime/AvatarCreator/Data/Endpoints/AssetEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
namespace ReadyPlayerMe.AvatarCreator
using UnityEngine;

namespace ReadyPlayerMe.AvatarCreator
{
public abstract class AssetEndpoints : Endpoints
public abstract class AssetEndpoints
{
private const string ASSET_ENDPOINT = API_V1_ENDPOINT + "assets?limit={0}&page={1}&filter=viewable-by-user-and-app&filterUserId={2}&filterApplicationId={3}&gender=neutral&gender={4}";
private static readonly string ASSET_ENDPOINT = Env.RPM_API_V1_URL + "assets?limit={0}&page={1}&filter=viewable-by-user-and-app&filterUserId={2}&filterApplicationId={3}&gender=neutral&gender={4}";

public static string GetAssetEndpoint(string type, int limit, int page, string userId, string appId, string gender)
{
Debug.Log(Env.RPM_API_V1_URL);

if (string.IsNullOrEmpty(type))
{
return string.Format(ASSET_ENDPOINT, limit, page, userId, appId, gender);
Expand Down
10 changes: 5 additions & 5 deletions Runtime/AvatarCreator/Data/Endpoints/AuthEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
namespace ReadyPlayerMe.AvatarCreator
{
public abstract class AuthEndpoints : Endpoints
public abstract class AuthEndpoints
{
public static string GetAuthAnonymousEndpoint(string subdomain)
{
return string.Format(API_SUBDOMAIN_ENDPOINT, subdomain, "/users");
return string.Format(Env.RPM_API_SUBDOMAIN_URL, subdomain, "/users");
}

public static string GetAuthStartEndpoint(string subdomain)
{
return string.Format(API_SUBDOMAIN_ENDPOINT, subdomain, "/auth/start");
return string.Format(Env.RPM_API_SUBDOMAIN_URL, subdomain, "/auth/start");
}

public static string GetConfirmCodeEndpoint(string subdomain)
{
return string.Format(API_SUBDOMAIN_ENDPOINT, subdomain, "/auth/login");
return string.Format(Env.RPM_API_SUBDOMAIN_URL, subdomain, "/auth/login");
}

public static string GetTokenRefreshEndpoint(string subdomain)
{
return string.Format(API_SUBDOMAIN_ENDPOINT, subdomain, "/auth/refresh");
return string.Format(Env.RPM_API_SUBDOMAIN_URL, subdomain, "/auth/refresh");
}
}
}
8 changes: 4 additions & 4 deletions Runtime/AvatarCreator/Data/Endpoints/AvatarEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ReadyPlayerMe.AvatarCreator
{
public abstract class AvatarEndpoints : Endpoints
public abstract class AvatarEndpoints
{
private const string AVATAR_API_V2_ENDPOINT = API_V2_ENDPOINT + "avatars";
private const string AVATAR_API_V1_ENDPOINT = API_V1_ENDPOINT + "avatars";
private const string MODELS_URL_PREFIX = "https://models.readyplayer.me";
private static readonly string AVATAR_API_V2_ENDPOINT = Env.RPM_API_V2_URL + "avatars";
private static readonly string AVATAR_API_V1_ENDPOINT = Env.RPM_API_V1_URL + "avatars";
private static readonly string MODELS_URL_PREFIX = "https://models.readyplayer.me";

public static string GetColorEndpoint(string avatarId)
{
Expand Down
9 changes: 0 additions & 9 deletions Runtime/AvatarCreator/Data/Endpoints/Endpoints.cs

This file was deleted.

3 changes: 3 additions & 0 deletions Runtime/Env.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Runtime/Env/Env.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ReadyPlayerMe.AvatarCreator
{
public static class Env
{
public static string RPM_API_SUBDOMAIN_URL => EnvLoader.LoadVar(nameof(RPM_API_SUBDOMAIN_URL), "https://{0}.readyplayer.me/api{1}");
public static string RPM_API_V2_URL => EnvLoader.LoadVar(nameof(RPM_API_V2_URL), "https://api.readyplayer.me/v2/");
public static string RPM_API_V1_URL => EnvLoader.LoadVar(nameof(RPM_API_V1_URL), "https://api.readyplayer.me/v1/");
}
}
File renamed without changes.
19 changes: 19 additions & 0 deletions Runtime/Env/EnvLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json.Linq;
using UnityEngine;

namespace ReadyPlayerMe.AvatarCreator
{
public static class EnvLoader
{
private const string LOCAL_ENV_FILENAME = "env.local";

public static string LoadVar(string varName, string defaultValue)
{
var jsonContent = Resources.Load<TextAsset>(LOCAL_ENV_FILENAME);

var loadedEnv = JObject.Parse(jsonContent.text);

return loadedEnv[varName]?.ToString() ?? defaultValue;
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Env/EnvLoader.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4c9bb4a

Please sign in to comment.