unity-release-client/README.md
2024-10-06 23:14:08 -05:00

54 lines
2 KiB
Markdown

# Unity Release API Client
This library makes it easier to interact with [Unity's Release API](https://services.docs.unity.com/release/v1/#tag/Release) for querying information about available Unity editor versions.
## Usage
```rust
let client = UnityReleaseClient::default();
let response: Result<OffsetConnection, Error> = client
.request()
.with_order(Order::Ascending) // order by ascending release date
.with_limit(5) // 5 results per query
.with_offset(20) // offset by 20 results
.with_stream(Stream::LTS) // filter for only LTS versions
.with_platform(Platform::Linux) // filter for only Linux releases
.with_architecture(Architecture::Arm64) // filter for only ARM64 support
.with_version("2020.3.44f1".to_string()) // filter for version 2020.3.44f1
.send()
.await?;
```
## Documentation
To use the client, create a `UnityReleaseClient` by using `Default::default` or `UnityReleaseClient::new(client)` where `client` is a [`reqwuest::Client`](https://docs.rs/reqwest/latest/reqwest/struct.Client.html).
```rust
let client = UnityReleaseClient::default();
```
```rust
// with a custom client
let client = reqwest::Client::default();
let unity_client = UnityReleaseClient::new(client);
```
To prepare a request, get a new `RequestBuilder` and configure the parameters.
```rust
let request_builder = client.request().with_limit(10);
```
In order to send the request, either build the `Request` or call `RequestBuilder::send`
```rust
let request: Request = request_builder.into();
let response = request.send();
```
```rust
let response = request_builder.send(); // build and send in the same step
```
The response is a `Result<OffsetConnection, Error>` and the schema is defined by Unity's OpenAPI spec [available from the API documentation](https://services.docs.unity.com/release/v1/). It's also possible to look through [`response.rs`](https://fem.mint.lgbt/kitsunecafe/unity-release-client/src/commit/dc4b909c5a78a6b639d06cb74b4be3b459c64153/src/response.rs#L160).