Skip to content

Commit

Permalink
Merge pull request #41 from CryZe/deps-for-0-3
Browse files Browse the repository at this point in the history
Release `v0.3.0`
  • Loading branch information
CryZe authored Dec 28, 2022
2 parents 967753f + 5156b34 commit 4fcce82
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 46 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- i686-unknown-linux-gnu
- x86_64-unknown-linux-gnu
- i686-pc-windows-msvc
- i686-pc-windows-gnu
# - i686-pc-windows-gnu
- x86_64-pc-windows-msvc
- x86_64-pc-windows-gnu
- x86_64-apple-darwin
Expand All @@ -42,10 +42,11 @@ jobs:
os: windows-latest
cargo_dir: ''
toolchain: stable
- target: i686-pc-windows-gnu
os: windows-latest
cargo_dir: ''
toolchain: stable-i686-pc-windows-gnu
# The windows crate doesn't work with this target atm.
# - target: i686-pc-windows-gnu
# os: windows-latest
# cargo_dir: ''
# toolchain: stable-i686-pc-windows-gnu
- target: x86_64-pc-windows-msvc
os: windows-latest
cargo_dir: ''
Expand All @@ -60,7 +61,7 @@ jobs:
toolchain: stable

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Install gcc-multilib
if: matrix.target == 'i686-unknown-linux-gnu'
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends g++-multilib
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "splits-io-api"
version = "0.2.0"
version = "0.3.0"
authors = ["Christopher Serr <[email protected]>"]
edition = "2021"
documentation = "https://docs.rs/splits-io-api/"
repository = "https://github.com/LiveSplit/splits-io-api"
license = "Apache-2.0/MIT"
description = "Bindings to the Splits.io API for Rust."
description = "Bindings to the splits.io API for Rust."
readme = "README.md"
keywords = ["splits-io", "speedrun", "livesplit", "web", "async"]
categories = ["network-programming", "api-bindings"]
Expand All @@ -23,9 +23,9 @@ include = [
http = "0.2.0"
serde = { version = "1.0.99", features = ["derive"] }
serde_json = "1.0.40"
snafu = { version = "0.6.0", default-features = false, features = ["std"] }
snafu = { version = "0.7.1", default-features = false, features = ["std"] }
url = "2.1.0"
uuid = { version = "0.8.1", default-features = false, features = ["serde"] }
uuid = { version = "1.1.2", default-features = false, features = ["serde"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
hyper = { version = "0.14.1", default-features = false, features = ["tcp", "client", "http2"] }
Expand Down
14 changes: 10 additions & 4 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
get_json,
platform::Body,
wrapper::{ContainsCategories, ContainsGame, ContainsGames, ContainsRunners, ContainsRuns},
Category, Client, Error, Game, Run, Runner, UnidentifiableResource,
Category, Client, Error, Game, Run, Runner, UnidentifiableResourceSnafu,
};
use http::Request;
use snafu::OptionExt;
Expand All @@ -28,7 +28,9 @@ impl Game {
pub async fn categories(&self, client: &Client) -> Result<Vec<Category>, Error> {
get_categories(
client,
self.shortname.as_ref().context(UnidentifiableResource)?,
self.shortname
.as_ref()
.context(UnidentifiableResourceSnafu)?,
)
.await
}
Expand All @@ -37,7 +39,9 @@ impl Game {
pub async fn runs(&self, client: &Client) -> Result<Vec<Run>, Error> {
get_runs(
client,
self.shortname.as_ref().context(UnidentifiableResource)?,
self.shortname
.as_ref()
.context(UnidentifiableResourceSnafu)?,
)
.await
}
Expand All @@ -46,7 +50,9 @@ impl Game {
pub async fn runners(&self, client: &Client) -> Result<Vec<Runner>, Error> {
get_runners(
client,
self.shortname.as_ref().context(UnidentifiableResource)?,
self.shortname
.as_ref()
.context(UnidentifiableResourceSnafu)?,
)
.await
}
Expand Down
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ async fn get_response_unchecked(
}
}

let response = client.client.request(request).await.context(Download)?;
Ok(response)
client.client.request(request).await.context(DownloadSnafu)
}

async fn get_response(client: &Client, request: Request<Body>) -> Result<Response<Body>, Error> {
Expand All @@ -173,8 +172,10 @@ async fn get_json<T: serde::de::DeserializeOwned>(
request: Request<Body>,
) -> Result<T, Error> {
let response = get_response(client, request).await?;
let reader = recv_reader(response.into_body()).await.context(Download)?;
serde_json::from_reader(reader).context(Json)
let reader = recv_reader(response.into_body())
.await
.context(DownloadSnafu)?;
serde_json::from_reader(reader).context(JsonSnafu)
}

#[derive(serde::Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion src/platform/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Client {
}

pub async fn request(&self, request: Request<Body>) -> Result<Response<Body>, Error> {
let window = window().context(NoWindow)?;
let window = window().context(NoWindowSnafu)?;

let (
Parts {
Expand Down
48 changes: 25 additions & 23 deletions src/race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
ContainsChatMessage, ContainsChatMessages, ContainsEntries, ContainsEntry, ContainsRace,
ContainsRaces,
},
Attachment, ChatMessage, Client, Download, Entry, Error, Race, Visibility,
Attachment, ChatMessage, Client, DownloadSnafu, Entry, Error, Race, Visibility,
};
use http::{header::CONTENT_TYPE, Request};
use snafu::ResultExt;
Expand Down Expand Up @@ -121,7 +121,9 @@ impl Attachment {
)
.await?;

recv_bytes(response.into_body()).await.context(Download)
recv_bytes(response.into_body())
.await
.context(DownloadSnafu)
}
}

Expand All @@ -145,7 +147,7 @@ pub async fn get(client: &Client, id: Uuid) -> Result<Race, Error> {
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut()
.unwrap()
.push(id.to_hyphenated().encode_lower(&mut Uuid::encode_buffer()));
.push(id.hyphenated().encode_lower(&mut Uuid::encode_buffer()));

let ContainsRace { race } = get_json(
client,
Expand Down Expand Up @@ -247,7 +249,7 @@ pub async fn update(
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut()
.unwrap()
.push(id.to_hyphenated().encode_lower(&mut Uuid::encode_buffer()));
.push(id.hyphenated().encode_lower(&mut Uuid::encode_buffer()));

let ContainsRace { race } = get_json(
client,
Expand All @@ -265,7 +267,7 @@ pub async fn update(
pub async fn get_entries(client: &Client, id: Uuid) -> Result<Vec<Entry>, Error> {
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
id.to_hyphenated().encode_lower(&mut Uuid::encode_buffer()),
id.hyphenated().encode_lower(&mut Uuid::encode_buffer()),
"entries",
]);

Expand All @@ -282,7 +284,7 @@ pub async fn get_entries(client: &Client, id: Uuid) -> Result<Vec<Entry>, Error>
pub async fn get_entry(client: &Client, id: Uuid) -> Result<Entry, Error> {
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
id.to_hyphenated().encode_lower(&mut Uuid::encode_buffer()),
id.hyphenated().encode_lower(&mut Uuid::encode_buffer()),
"entry",
]);

Expand Down Expand Up @@ -326,7 +328,7 @@ pub async fn join(
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
race_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
"entries",
]);
Expand Down Expand Up @@ -357,11 +359,11 @@ pub async fn leave(client: &Client, race_id: Uuid, entry_id: Uuid) -> Result<(),
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
race_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
"entries",
entry_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
]);

Expand Down Expand Up @@ -399,11 +401,11 @@ pub async fn ready_up(client: &Client, race_id: Uuid, entry_id: Uuid) -> Result<
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
race_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
"entries",
entry_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
]);

Expand Down Expand Up @@ -431,11 +433,11 @@ pub async fn unready(client: &Client, race_id: Uuid, entry_id: Uuid) -> Result<E
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
race_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
"entries",
entry_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
]);

Expand All @@ -461,11 +463,11 @@ pub async fn finish(client: &Client, race_id: Uuid, entry_id: Uuid) -> Result<En
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
race_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
"entries",
entry_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
]);

Expand Down Expand Up @@ -493,11 +495,11 @@ pub async fn undo_finish(client: &Client, race_id: Uuid, entry_id: Uuid) -> Resu
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
race_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
"entries",
entry_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
]);

Expand All @@ -523,11 +525,11 @@ pub async fn forfeit(client: &Client, race_id: Uuid, entry_id: Uuid) -> Result<E
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
race_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
"entries",
entry_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
]);

Expand Down Expand Up @@ -555,11 +557,11 @@ pub async fn undo_forfeit(client: &Client, race_id: Uuid, entry_id: Uuid) -> Res
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
race_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
"entries",
entry_id
.to_hyphenated()
.hyphenated()
.encode_lower(&mut Uuid::encode_buffer()),
]);

Expand All @@ -584,7 +586,7 @@ pub async fn undo_forfeit(client: &Client, race_id: Uuid, entry_id: Uuid) -> Res
pub async fn get_chat(client: &Client, id: Uuid) -> Result<Vec<ChatMessage>, Error> {
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
id.to_hyphenated().encode_lower(&mut Uuid::encode_buffer()),
id.hyphenated().encode_lower(&mut Uuid::encode_buffer()),
"chat",
]);

Expand Down Expand Up @@ -615,7 +617,7 @@ pub async fn send_chat_message(
) -> Result<ChatMessage, Error> {
let mut url = Url::parse("https://splits.io/api/v4/races").unwrap();
url.path_segments_mut().unwrap().extend(&[
id.to_hyphenated().encode_lower(&mut Uuid::encode_buffer()),
id.hyphenated().encode_lower(&mut Uuid::encode_buffer()),
"chat",
]);

Expand Down
14 changes: 10 additions & 4 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
platform::{recv_bytes, Body},
schema::Run,
wrapper::ContainsRun,
Client, Download, Error, UnidentifiableResource,
Client, DownloadSnafu, Error, UnidentifiableResourceSnafu,
};
use http::{header::CONTENT_TYPE, Request};
use snafu::{OptionExt, ResultExt};
Expand All @@ -20,7 +20,11 @@ use url::Url;
impl Run {
/// Downloads the splits for the Run.
pub async fn download(&self, client: &Client) -> Result<impl Deref<Target = [u8]>, Error> {
self::download(client, self.id.as_ref().context(UnidentifiableResource)?).await
self::download(
client,
self.id.as_ref().context(UnidentifiableResourceSnafu)?,
)
.await
}

/// Gets a Run.
Expand All @@ -46,7 +50,7 @@ impl Run {
let mut url = Url::parse("https://splits.io").unwrap();
url.path_segments_mut()
.unwrap()
.push(self.id.as_ref().context(UnidentifiableResource)?);
.push(self.id.as_ref().context(UnidentifiableResourceSnafu)?);
Ok(url)
}
}
Expand All @@ -65,7 +69,9 @@ pub async fn download(client: &Client, id: &str) -> Result<impl Deref<Target = [
)
.await?;

recv_bytes(response.into_body()).await.context(Download)
recv_bytes(response.into_body())
.await
.context(DownloadSnafu)
}

/// Gets a Run.
Expand Down

0 comments on commit 4fcce82

Please sign in to comment.