Closed joelkoen closed 1 year ago
Currently it is not enumerated as a type in the docs and we can only see it in examples. Perhaps i missed this type, or maybe it did not exist yet during implementation stage of the wrapper.
I will implement it. Thank you!
I believe the implementation is likely done... https://github.com/Rinrin0413/tetr-ch-rs/tree/missing-stream-type
Wow, that was fast! I've had a look and have been able to use it in my code. Thank you!
I think this is a separate issue, but I noticed that some of the Client
functions are using self
instead of &self
. I'm new to Rust so I might be doing something wrong, but I expected to be able to reuse the client without constructing a new one:
use anyhow::{Context, Result};
use tetr_ch::client::{
stream::{StreamContext, StreamType},
Client,
};
#[tokio::main]
async fn main() -> Result<()> {
let client = Client::new();
let user = client
.get_user("272")
.await?
.data
.context("Missing user data")?
.user;
// let client = Client::new(); // uncommenting this causes code to compile
let stream = client
.get_stream(
StreamType::League,
StreamContext::UserRecent,
Some(user.id.id()),
)
.await?
.data
.context("Missing stream data")?;
let replays: Vec<_> = stream.records.iter().map(|x| &x.replay_id).collect();
println!("{:#?}", replays);
Ok(())
}
error[E0382]: use of moved value: `client`
--> src/main.rs:18:18
|
9 | let client = Client::new();
| ------ move occurs because `client` has type `Client`, which does not implement the `Copy` trait
10 | let user = client
11 | .get_user("272")
| --------------- `client` moved due to this method call
...
18 | let stream = client
| ^^^^^^ value used here after move
|
note: `Client::get_user` takes ownership of the receiver `self`, which moves `client`
--> /home/joel/.cargo/git/checkouts/tetr-ch-rs-af3fcfa2a23e9bf5/55a3b4f/src/client.rs:93:27
|
93 | pub async fn get_user(self, user: &str) -> RspErr<UserResponse> {
| ^^^^
Client
is disposable, so create a new one each time you use it.
Ok, thank you!
There is a missing stream type -
league
. This returns a user's recent league games. For example, osk's games can be fetched usingch.tetr.io/api/streams/league_userrecent_5e32fc85ab319c2ab1beb07c
.I tried adding this myself, but the stream returns records that contain multiple games, and the current models do not support this. I thought I'd contact you as you have added this comment:
https://github.com/Rinrin0413/tetr-ch-rs/blob/b57ae22a36b803f22f1addaafd00ebdbeedecbfd/src/model/record.rs#L25-L30