speedrun_api/api.rs
1//! API endpoint modules
2//!
3//! All endpoints use a builder pattern to construct their parameters.
4//!
5//! # Example
6//!
7//! ```rust ,no_run
8//! use futures::{StreamExt, TryStreamExt};
9//! use serde::Deserialize;
10//! use speedrun_api::{
11//! api::{self, AsyncQuery, PagedEndpointExt},
12//! error::SpeedrunApiResult,
13//! SpeedrunApiBuilder,
14//! };
15//!
16//! // The return type for the endpoints we are interested in. More information
17//! // is returned by the endpoints, but you can deserialize only what is needed.
18//! #[derive(Debug, Deserialize)]
19//! struct Game {
20//! names: Names,
21//! weblink: String,
22//! }
23//!
24//! #[derive(Debug, Deserialize)]
25//! struct Names {
26//! international: String,
27//! }
28//!
29//! #[tokio::main]
30//! pub async fn main() -> SpeedrunApiResult<()> {
31//! // Create a new client
32//! let client = SpeedrunApiBuilder::new().build_async()?;
33//!
34//! // Create an endpoint. This endpoint gets Super Mario Sunshine.
35//! let endpoint = api::games::Game::builder().id("v1pxjz68").build().unwrap();
36//! // Call the endpoint. The return type decides how to represent the returned value.
37//! let game: Game = endpoint.query_async(&client).await?;
38//!
39//! // Create a paginated endpoint. This retrievs a list of all games.
40//! let paginated_endpoint = api::games::Games::builder().build().unwrap();
41//! // The `PagedEndpointExt` adapters consume the endpoint, so we create a copy.
42//! let async_stream = paginated_endpoint.clone();
43//! // Call the `PagedEndpointExt::stream()` method to get an async Stream of results.
44//! let games: Vec<Game> = async_stream.stream(&client).take(200).try_collect().await?;
45//! // Call the `PagedEndpointExt::single_page()` method to retrieve a single page builder.
46//! // This retrieves 100 results starting at offset 100.
47//! let single_page_endpoint = paginated_endpoint
48//! .single_page()
49//! .offset(100)
50//! .max(100)
51//! .build()
52//! .unwrap();
53//! // This wrapped endpoint can be queried like any normal endpoint, but always returns a
54//! // `Vec<T: Deserialize>`.
55//! let games: Vec<Game> = single_page_endpoint.query_async(&client).await?;
56//! }
57//! ```
58
59mod client;
60mod common;
61mod endpoint;
62mod error;
63mod pagination;
64mod query;
65mod query_params;
66mod utils;
67
68pub mod categories;
69pub mod developers;
70pub mod engines;
71pub mod games;
72pub mod gametypes;
73pub mod genres;
74pub mod guests;
75pub mod leaderboards;
76pub mod levels;
77pub mod notifications;
78pub mod platforms;
79pub mod profile;
80pub mod publishers;
81pub mod regions;
82pub mod runs;
83pub mod series;
84pub mod users;
85pub mod variables;
86
87pub use crate::types::Root;
88pub use client::{AsyncClient, Client, RestClient};
89pub use common::{CategoriesSorting, Direction, VariablesSorting};
90pub use error::ApiError;
91pub use pagination::{Pageable, PagedEndpointExt, PagedIter, SinglePage, SinglePageBuilder};
92pub use query::{AsyncQuery, Query};