Skip to content

Commit

Permalink
com.utilities.rest 2.5.0 (#66)
Browse files Browse the repository at this point in the history
- moved optional debug parameter for multimedia requests into RestParameters
- added optional DownloadCache flag to RestParameters (defaults to true)
- added Rest.DownloadFIleBytesAsync
- added Rest.DownloadBytesAsync
- enabled DownloadLocation to be set (must be an approved download location)

---------

Co-authored-by: Simon (Darkside) Jackson <[email protected]>
  • Loading branch information
StephenHodgson and SimonDarksideJ committed Jan 15, 2024
1 parent e29801f commit cea876e
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 134 deletions.
42 changes: 40 additions & 2 deletions Documentation~/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ A Utilities.Rest package for the [Unity](https://unity.com/) Game Engine.

## Installing

Requires Unity 2021.3 LTS or higher.

The recommended installation method is though the unity package manager and [OpenUPM](https://openupm.com/packages/com.utilities.rest).

### Via Unity Package Manager and OpenUPM

- Open your Unity project settings
Expand Down Expand Up @@ -77,7 +81,9 @@ var restParameters = new RestParameters(
disposeDownloadHandler, // Optional, dispose the DownloadHandler. Default is true.
disposeUploadHandler, // Optional, dispose the UploadHandler. Default is true.
certificateHandler, // Optional, certificate handler for the request.
disposeCertificateHandler); // Optional, dispose the CertificateHandler. Default is true.
disposeCertificateHandler, // Optional, dispose the CertificateHandler. Default is true.
cacheDownloads, // Optional, cache downloaded content. Default is true
debug); // Optional, enable debug output of the request. Default is false.
var response = await Rest.GetAsync("www.your.api/endpoint", restParameters);
```

Expand Down Expand Up @@ -154,9 +160,15 @@ response.Validate(debug: true);

```csharp
// cache directory defaults to {Application.temporaryCachePath}/download_cache/
// it is currently not possible to set this value, but is likely a nice feature request.
Debug.Log(Rest.DownloadCacheDirectory);

// cache directory can be set to one of:
// Application.temporaryCachePath,
// Application.persistentDataPath,
// Application.dataPath,
// Application.streamingAssetsPath
Rest.DownloadCacheDirectory = Application.dataPath;

var uri = "www.url.to/remote/resource";

if (Rest.TryGetDownloadCacheItem(uri, out var cachedFilePath))
Expand All @@ -177,6 +189,8 @@ Rest.DeleteDownloadCache();

#### Files

Download a file.

```csharp
var downloadedFilePath = await Rest.DownloadFileAsync("www.your.api/your_file.pdf");

Expand All @@ -186,6 +200,30 @@ if (!string.IsNullOrWhiteSpace(downloadedFilePath))
}
```

Download a file, and get the raw byte data.

```csharp
var downloadedBytes = await Rest.DownloadFileBytesAsync("www.your.api/your_file.pdf");

if (downloadedBytes != null && downloadedBytes.Length > 0)
{
Debug.Log(downloadedBytes.Length);
}
```

Download raw file bytes.

> This request does not cache data
```csharp
var downloadedBytes = await Rest.DownloadBytesAsync("www.your.api/your_file.pdf");

if (downloadedBytes != null && downloadedBytes.Length > 0)
{
Debug.Log(downloadedBytes.Length);
}
```

#### Textures

> Pro Tip: This also works with local file paths to load textures async at runtime!
Expand Down
3 changes: 0 additions & 3 deletions Runtime/AbstractAuthentication.cs
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
Loading

0 comments on commit cea876e

Please sign in to comment.