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
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
Updated readme examples based on changes, and added clarity in places.
  • Loading branch information
SimonDarksideJ committed May 4, 2024
commit aa2d0b7d07b683649831682090534cda055e402b
21 changes: 15 additions & 6 deletions README.md
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 @@ -84,9 +86,15 @@ var restParameters = new RestParameters(
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.

// 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.dataPath;

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

Expand All @@ -194,7 +202,7 @@ 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))
SimonDarksideJ marked this conversation as resolved.
Show resolved Hide resolved
{
Debug.Log(downloadedFilePath);
}
Expand Down Expand Up @@ -273,11 +281,12 @@ 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);
}
```