use anyhow::Result;
use vrchatapi::apis::worlds_api;
pub async fn search_worlds(
api_config: &vrchatapi::apis::configuration::Configuration,
query: &str,
limit: i32,
offset: i32,
) -> Result<Vec<vrchatapi::models::LimitedWorld>> {
let worlds = worlds_api::search_worlds(
api_config,
None, None, None, None, Some(limit),
None, Some(offset),
Some(query),
None, None, None, None, None, None, None, )
.await?;
Ok(worlds)
}
pub async fn fetch_world_by_id(
api_config: &vrchatapi::apis::configuration::Configuration,
world_id: &str,
) -> Result<vrchatapi::models::World> {
let world = worlds_api::get_world(api_config, world_id)
.await
.map_err(|e| {
match e {
vrchatapi::apis::Error::ResponseError(ref response_content) => {
if response_content.status == 404 {
return anyhow::anyhow!("No world found with ID '{}'", world_id);
}
anyhow::anyhow!(
"Failed to fetch world '{}' - HTTP {}",
world_id,
response_content.status
)
}
_ => {
anyhow::anyhow!("Failed to fetch world '{}' - {}", world_id, e)
}
}
})?;
Ok(world)
}