Skip to content

Commit

Permalink
com.utilities.rest 2.3.0 (RageAgainstThePixel#54)
Browse files Browse the repository at this point in the history
- refactor AbstractAuthentication to include TConfiguration : ScriptableObject, IConfiguration
- marked LoadFromAsset<T>(T asset = null) obsolete -> LoadFromAsset(TConfiguration configuration = null)
- added LoadDefault()
- added LoadDefaultsReversed()
  • Loading branch information
StephenHodgson committed Nov 29, 2023
1 parent ceb98e5 commit 8bb8171
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
41 changes: 39 additions & 2 deletions Runtime/AbstractAuthentication.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,61 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.IO;
using UnityEngine;

namespace Utilities.WebRequestRest.Interfaces
{
public abstract class AbstractAuthentication<TAuthentication, TAuthInfo> : IAuthentication<TAuthInfo>
public abstract class AbstractAuthentication<TAuthentication, TAuthInfo, TConfiguration> : IAuthentication<TAuthInfo>
where TAuthentication : IAuthentication
where TAuthInfo : IAuthInfo
where TConfiguration : ScriptableObject, IConfiguration
{
/// <inheritdoc />
public abstract TAuthInfo Info { get; }

/// <summary>
/// Attempts to load the default authentication based on order of precedence.<br/>
/// 1. ScriptableObject<br/>
/// 2. Directory<br/>
/// 3. User Directory<br/>
/// 4. Environment Variables<br/>
/// </summary>
/// <returns>
/// The loaded <see cref="IAuthentication{T}"/> or <see langword="null"/>.
/// </returns>
public virtual TAuthentication LoadDefault()
=> LoadFromAsset() ??
LoadFromDirectory() ??
LoadFromDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) ??
LoadFromEnvironment();

/// <summary>
/// Attempts to load the default authentication based on order of precedence.<br/>
/// 1. Environment Variables<br/>
/// 2. User Directory<br/>
/// 3. Directory<br/>
/// 4. ScriptableObject<br/>
/// </summary>
/// <returns>
/// The loaded <see cref="IAuthentication{T}"/> or <see langword="null"/>.
/// </returns>
public virtual TAuthentication LoadDefaultsReversed()
=> LoadFromEnvironment() ??
LoadFromDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) ??
LoadFromAsset() ??
LoadFromDirectory();

[Obsolete("Use LoadFromAsset (remove angle bracket type specification)")]
public TAuthentication LoadFromAsset<T>() => LoadFromAsset();

/// <summary>
/// Attempts to load the authentication from a <see cref="ScriptableObject"/> asset that implements <see cref="IConfiguration"/>.
/// </summary>
/// <returns>
/// The loaded <see cref="IAuthentication{T}"/> or <see langword="null"/>.
/// </returns>
public abstract TAuthentication LoadFromAsset<T>(T asset = null) where T : ScriptableObject, IConfiguration;
public abstract TAuthentication LoadFromAsset(TConfiguration configuration = null);

/// <summary>
/// Attempts to load the authentication from the system environment variables.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Utilities.Rest",
"description": "This package contains useful RESTful utilities for the Unity Game Engine.",
"keywords": [],
"version": "2.2.7",
"version": "2.3.0",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest/releases",
Expand Down

0 comments on commit 8bb8171

Please sign in to comment.