Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.utilities.rest 2.5.0 #66

Merged
merged 8 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
com.utilities.rest 2.5.0
- moved optional debug parameter for multimedia endpoints into RestParameters
  • Loading branch information
StephenHodgson committed Jan 15, 2024
commit 7363f0589561200d95e0f91b3593a5800a7efac2
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public virtual TAuthentication LoadDefaultsReversed()
LoadFromDirectory() ??
LoadFromAsset();

[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>
Expand Down
91 changes: 22 additions & 69 deletions Utilities.Rest/Packages/com.utilities.rest/Runtime/Rest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,31 +498,19 @@ public static bool TryGetFileNameFromUrl(string url, out string fileName)

#endregion Download Cache

[Obsolete("use new overload with debug support")]
public static async Task<Texture2D> DownloadTextureAsync(
string url,
string fileName = null,
RestParameters parameters = null,
CancellationToken cancellationToken = default)
{
return await DownloadTextureAsync(url, fileName, parameters, false, cancellationToken);
}

/// <summary>
/// Download a <see cref="Texture2D"/> from the provided <see cref="url"/>.
/// </summary>
/// <param name="url">The url to download the <see cref="Texture2D"/> from.</param>
/// <param name="fileName">Optional, file name to download (including extension).</param>
/// <param name="parameters">Optional, <see cref="RestParameters"/>.</param>
/// <param name="debug">Optional, debug http request.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns>A new <see cref="Texture2D"/> instance.</returns>
public static async Task<Texture2D> DownloadTextureAsync(
string url,
string fileName = null,
RestParameters parameters = null,
bool debug = false,
CancellationToken cancellationToken = default)
string url,
string fileName = null,
RestParameters parameters = null,
CancellationToken cancellationToken = default)
{
await Awaiters.UnityMainThread;

Expand Down Expand Up @@ -557,7 +545,7 @@ public static async Task<Texture2D> DownloadTextureAsync(
try
{
var response = await webRequest.SendAsync(parameters, cancellationToken);
response.Validate(debug);
response.Validate(parameters.Debug);

if (!isCached)
{
Expand All @@ -580,16 +568,6 @@ public static async Task<Texture2D> DownloadTextureAsync(
return texture;
}

[Obsolete("Use new overload with debug support")]
public static async Task<AudioClip> DownloadAudioClipAsync(
string url,
AudioType audioType,
RestParameters parameters = null,
CancellationToken cancellationToken = default)
{
return await DownloadAudioClipAsync(url, audioType, httpMethod: UnityWebRequest.kHttpVerbGET, parameters: parameters, cancellationToken: cancellationToken);
}

/// <summary>
/// Download a <see cref="AudioClip"/> from the provided <see cref="url"/>.
/// </summary>
Expand All @@ -600,7 +578,6 @@ public static async Task<AudioClip> DownloadAudioClipAsync(
/// <param name="jsonData">Optional, json payload. Only <see cref="jsonData"/> OR <see cref="payload"/> can be supplied.</param>
/// <param name="payload">Optional, raw byte payload. Only <see cref="payload"/> OR <see cref="jsonData"/> can be supplied.</param>
/// <param name="parameters">Optional, <see cref="RestParameters"/>.</param>
/// <param name="debug">Optional, debug http request.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns>A new <see cref="AudioClip"/> instance.</returns>
public static async Task<AudioClip> DownloadAudioClipAsync(
Expand All @@ -611,7 +588,6 @@ public static async Task<AudioClip> DownloadAudioClipAsync(
string jsonData = null,
byte[] payload = null,
RestParameters parameters = null,
bool debug = false,
CancellationToken cancellationToken = default)
{
await Awaiters.UnityMainThread;
Expand Down Expand Up @@ -684,7 +660,7 @@ public static async Task<AudioClip> DownloadAudioClipAsync(
try
{
var response = await webRequest.SendAsync(parameters, cancellationToken);
response.Validate(debug);
response.Validate(parameters.Debug);

if (!isCached)
{
Expand Down Expand Up @@ -721,7 +697,6 @@ public static async Task<AudioClip> DownloadAudioClipAsync(
/// <param name="fileName">Optional, file name to download (including extension).</param>
/// <param name="playbackAmountThreshold">Optional, the amount of data to to download before signaling that streaming is ready.</param>
/// <param name="parameters">Optional, <see cref="RestParameters"/>.</param>
/// <param name="debug">Optional, debug http request.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns>A new <see cref="AudioClip"/> instance.</returns>
public static async Task<AudioClip> StreamAudioAsync(
Expand All @@ -734,7 +709,6 @@ public static async Task<AudioClip> StreamAudioAsync(
byte[] payload = null,
ulong playbackAmountThreshold = 10000,
RestParameters parameters = null,
bool debug = false,
CancellationToken cancellationToken = default)
{
await Awaiters.UnityMainThread;
Expand Down Expand Up @@ -828,7 +802,7 @@ public static async Task<AudioClip> StreamAudioAsync(

var response = await webRequest.SendAsync(parameters, cancellationToken);
uploadHandler?.Dispose();
response.Validate(debug);
response.Validate(parameters.Debug);

var loadedClip = downloadHandler.audioClip;

Expand Down Expand Up @@ -906,61 +880,40 @@ public static async Task<AssetBundle> DownloadAssetBundleAsync(

using (webRequest)
{
Response response;
parameters ??= new RestParameters();
parameters.Timeout = options?.Timeout ?? -1;
parameters.DisposeDownloadHandler = false;
var response = await webRequest.SendAsync(parameters, cancellationToken);
response.Validate(parameters.Debug);

try
{
parameters ??= new RestParameters();
parameters.Timeout = options?.Timeout ?? -1;
parameters.DisposeDownloadHandler = false;
response = await webRequest.SendAsync(parameters, cancellationToken);
}
catch (Exception e)
{
Debug.LogError(e);
throw;
}
var downloadHandler = (DownloadHandlerAssetBundle)webRequest.downloadHandler;
var assetBundle = downloadHandler.assetBundle;
downloadHandler.Dispose();

if (!response.Successful)
if (assetBundle == null)
{
Debug.LogError($"Failed to download asset bundle from \"{url}\"!\n{response.Code}:{response.Body}");
return null;
throw new RestException(response, $"Failed to download asset bundle from \"{url}\"!");
}

var downloadHandler = (DownloadHandlerAssetBundle)webRequest.downloadHandler;
var assetBundle = downloadHandler.assetBundle;
downloadHandler.Dispose();
return assetBundle;
}
}

#endif // UNITY_ADDRESSABLES

[Obsolete("use new overload with debug support")]
public static async Task<string> DownloadFileAsync(
string url,
string fileName = null,
RestParameters parameters = null,
CancellationToken cancellationToken = default)
{
return await DownloadFileAsync(url, fileName, parameters, false, cancellationToken);
}

/// <summary>
/// Download a file from the provided <see cref="url"/>.
/// </summary>
/// <param name="url">The url to download the file from.</param>
/// <param name="fileName">Optional, file name to download (including extension).</param>
/// <param name="parameters">Optional, <see cref="RestParameters"/>.</param>
/// <param name="debug">Optional, debug http request.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns>The path to the downloaded file.</returns>
public static async Task<string> DownloadFileAsync(
string url,
string fileName = null,
RestParameters parameters = null,
bool debug = false,
CancellationToken cancellationToken = default)
string url,
string fileName = null,
RestParameters parameters = null,
CancellationToken cancellationToken = default)
{
await Awaiters.UnityMainThread;

Expand All @@ -979,7 +932,7 @@ public static async Task<string> DownloadFileAsync(
fileDownloadHandler.removeFileOnAbort = true;
webRequest.downloadHandler = fileDownloadHandler;
var response = await webRequest.SendAsync(parameters, cancellationToken);
response.Validate(debug);
response.Validate(parameters?.Debug ?? false);
return filePath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ public class RestParameters
/// <param name="disposeUploadHandler">Optional, dispose the <see cref="UploadHandler"/>?<br/>Default is true.</param>
/// <param name="certificateHandler">Optional, certificate handler for the request.</param>
/// <param name="disposeCertificateHandler">Optional, dispose the <see cref="CertificateHandler"/>?<br/>Default is true.</param>
/// <param name="debug">Optional,Enabled printing for the debug output of the request.</param>
public RestParameters(
IReadOnlyDictionary<string, string> headers = null,
IProgress<Progress> progress = null,
int timeout = -1,
bool disposeDownloadHandler = true,
bool disposeUploadHandler = true,
CertificateHandler certificateHandler = null,
bool disposeCertificateHandler = true)
bool disposeCertificateHandler = true,
bool debug = false)
{
Headers = headers;
Progress = progress;
Expand All @@ -37,6 +39,7 @@ public RestParameters(
DisposeUploadHandler = disposeUploadHandler;
CertificateHandler = certificateHandler;
DisposeCertificateHandler = disposeCertificateHandler;
Debug = debug;
}

/// <summary>
Expand Down Expand Up @@ -78,5 +81,10 @@ public RestParameters(
public bool DisposeUploadHandler { get; internal set; }

internal int ServerSentEventCount { get; set; }

/// <summary>
/// Enabled printing for the debug output of the request.
/// </summary>
public bool Debug { get; set; }
}
}
2 changes: 1 addition & 1 deletion Utilities.Rest/Packages/com.utilities.rest/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.4.6",
"version": "2.5.0",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest/releases",
Expand Down
1 change: 1 addition & 0 deletions Utilities.Rest/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"com.unity.addressables": "1.21.19",
"com.unity.ide.rider": "3.0.27",
"com.unity.ide.visualstudio": "2.0.22",
"com.utilities.buildpipeline": "1.1.9"
Expand Down