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

Updated readme examples based on changes, and added clarity in places. #75

Merged
merged 4 commits into from
May 10, 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
Prev Previous commit
updated docs
  • Loading branch information
StephenHodgson committed May 10, 2024
commit 26c36bd476497a60caeea27b875525a925d142b8
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var restParameters = new RestParameters(
disposeUploadHandler, // Optional, dispose the UploadHandler. Default is true.
certificateHandler, // Optional, certificate handler for the request.
disposeCertificateHandler, // Optional, dispose the CertificateHandler. Default is true.
cacheDownloads, // Optional, cache downloaded content. Default is true
cacheDownloads, // Optional, cache downloaded content. Default is true.
debug); // Optional, enable debug output of the request. Default is false.

// Rest call passing a pre-configured set of RestParameters
Expand Down Expand Up @@ -175,7 +175,7 @@ Debug.Log(Rest.DownloadCacheDirectory);
// Application.persistentDataPath,
// Application.dataPath,
// Application.streamingAssetsPath
Rest.DownloadLocation = Application.dataPath;
Rest.DownloadLocation = Application.streamingAssetsPath;

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

Expand Down Expand Up @@ -212,26 +212,27 @@ if (!string.IsNullOrWhiteSpace(downloadedFilePath) && File.Exists(downloadedFile
}
else
{
Debug.Log($"Unable to download file to {downloadedFilePath}");
Debug.LogError($"Failed to download file!");
}
```

Download a file, and get the raw byte data.
Download a file, then return the raw byte data.

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

if (downloadedBytes != null && downloadedBytes.Length > 0)
{
// do some custom loading of your binary file.
Debug.Log(downloadedBytes.Length);
}
else
{
Debug.Log($"Unable to download file");
Debug.LogError($"Failed to download file!");
}
```

Download raw file bytes.
Download raw file bytes directly into memory.

> This request does not cache data

Expand All @@ -244,7 +245,7 @@ if (downloadedBytes != null && downloadedBytes.Length > 0)
}
else
{
Debug.Log($"Unable to download file");
Debug.LogError($"Failed to download file!");
}
```

Expand All @@ -262,7 +263,7 @@ if (texture != null)
}
else
{
Debug.Log($"Unable to download texture");
Debug.LogError($"Failed to download texture!");
}
```

Expand All @@ -281,7 +282,7 @@ if (audioClip != null)
}
else
{
Debug.Log($"Unable to download audio clip");
Debug.LogError($"Failed to download audio clip!");
}
```

Expand Down Expand Up @@ -315,6 +316,6 @@ if (assetBundle != null)
}
else
{
Debug.Log($"Unable to download asset bundle");
Debug.LogError($"Failed to download and load asset bundle!");
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ var basicAuthentication = Rest.GetBasicAuthentication("username", "password");
var bearerToken = Rest.GetBearerOAuthToken("authToken");
```

These methods will generate the necessary data to apply to your authentication headers, they DO NOT set the authentication for any Rest calls.

### Rest Parameters

Rest parameters have been bundled into a single object to make the method signatures a bit more uniform.
Rest parameters have been bundled into a single object to make the method signatures a bit more uniform, these can be provided with all requests made using the `com.utilities.rest` library to control how the operation performs.

```csharp
var restParameters = new RestParameters(
Expand All @@ -82,11 +84,17 @@ var restParameters = new RestParameters(
disposeUploadHandler, // Optional, dispose the UploadHandler. Default is true.
certificateHandler, // Optional, certificate handler for the request.
disposeCertificateHandler, // Optional, dispose the CertificateHandler. Default is true.
cacheDownloads, // Optional, cache downloaded content. Default is true
cacheDownloads, // Optional, cache downloaded content. Default is true.
debug); // Optional, enable debug output of the request. Default is false.

// Rest call passing a pre-configured set of RestParameters
var response = await Rest.GetAsync("www.your.api/endpoint", restParameters);
```

If you require any of the above options when making calls, ensure to add a `RestParameters` construct to the request, as shown above.

> Pro Tip: If you have multiple requests using the same "Parameters", then cache a single instance of the `RestParameters` and use this for all calls instead of recreating it for each request.

### Get

```csharp
Expand Down Expand Up @@ -149,7 +157,7 @@ response.Validate(debug: true);
### Delete

```csharp
var response = await Rest.DeleteAsync("www.your.api/endpoint", restParameters);
var response = await Rest.DeleteAsync("www.your.api/endpoint");
// Validates the response for you and will throw a RestException if the response is unsuccessful.
response.Validate(debug: true);
```
Expand All @@ -167,7 +175,7 @@ Debug.Log(Rest.DownloadCacheDirectory);
// Application.persistentDataPath,
// Application.dataPath,
// Application.streamingAssetsPath
Rest.DownloadCacheDirectory = Application.dataPath;
Rest.DownloadLocation = Application.streamingAssetsPath;

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

Expand All @@ -182,6 +190,10 @@ if (Rest.TryGetDownloadCacheItem(uri, out var cachedFilePath))
Debug.Log($"Deleted {cachedFilePath}");
}
}
else
{
Debug.Log($"Unable to download from {uri}");
}

// Clear the whole download cache directory
Rest.DeleteDownloadCache();
Expand All @@ -194,24 +206,33 @@ Download a file.
```csharp
var downloadedFilePath = await Rest.DownloadFileAsync("www.your.api/your_file.pdf");

if (!string.IsNullOrWhiteSpace(downloadedFilePath))
if (!string.IsNullOrWhiteSpace(downloadedFilePath) && File.Exists(downloadedFilePath))
{
Debug.Log(downloadedFilePath);
}
else
{
Debug.LogError($"Failed to download file!");
}
```

Download a file, and get the raw byte data.
Download a file, then return the raw byte data.

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

if (downloadedBytes != null && downloadedBytes.Length > 0)
{
// do some custom loading of your binary file.
Debug.Log(downloadedBytes.Length);
}
else
{
Debug.LogError($"Failed to download file!");
}
```

Download raw file bytes.
Download raw file bytes directly into memory.

> This request does not cache data

Expand All @@ -222,6 +243,10 @@ if (downloadedBytes != null && downloadedBytes.Length > 0)
{
Debug.Log(downloadedBytes.Length);
}
else
{
Debug.LogError($"Failed to download file!");
}
```

#### Textures
Expand All @@ -236,6 +261,10 @@ if (texture != null)
// assign it to your renderer
rawImage.texture = texture;
}
else
{
Debug.LogError($"Failed to download texture!");
}
```

#### Audio
Expand All @@ -251,6 +280,10 @@ if (audioClip != null)
audioSource.clip = audioClip;
audioSource.PlayOneShot(audioClip);
}
else
{
Debug.LogError($"Failed to download audio clip!");
}
```

##### Audio Streaming
Expand All @@ -273,11 +306,16 @@ audioSource.clip = audioClip;
#### Asset Bundles

```csharp
var assetBundle = await Rest.DownloadAssetBundleAsync("www.your.api/asset.bundle");
var bundleOptions = new AssetBundleRequestOptions();
var assetBundle = await Rest.DownloadAssetBundleAsync("www.your.api/asset.bundle", bundleOptions);

if (assetBundle != null)
{
var cube = bundle.LoadAsset<GameObject>("Cube");
var cube = assetBundle.LoadAsset<GameObject>("Cube");
Instantiate(cube);
}
else
{
Debug.LogError($"Failed to download and load asset bundle!");
}
```