rosu_v2/lib.rs
1//! rosu-v2 is a wrapper for the [osu!api v2].
2//! As such, it provides a bunch of additional endpoints and data over [`rosu`] which wraps the [osu!api v1].
3//!
4//! Feel free to open an issue when things don't work as expected.
5//!
6//! The branch `rosu-v2/main` should mirror the last published version. Upcoming changes
7//! will generally be added to the `rosu-v2/lazer` branch. If you want to stay up-to-date
8//! and use the `lazer` branch, you can add this in your `Cargo.toml`:
9//!
10//! ```toml
11//! rosu-v2 = { git = "https://github.com/MaxOhn/rosu-v2", branch = "lazer" }
12//! ```
13//!
14//! ## Authentication
15//!
16//! Unlike api v1, api v2 does not require an api key by users. Instead, it requires a client id and a client secret.
17//!
18//! To get those, you must register an application [here](https://osu.ppy.sh/home/account/edit#new-oauth-application).
19//! Unless you're interested in logging into the API through an osu! account, the callback URL here does not matter and can be left blank.
20//!
21//! If you went through the OAuth process for a user, you can provide the callback URL and received code
22//! when creating the client in order to make requests on behalf of the authenticated user.
23//!
24//! ## Endpoints
25//!
26//! The following endpoints are currently supported:
27//!
28//! - `beatmaps/lookup`: A specific beatmap including its beatmapset
29//! - `beatmaps`: Up to 50 beatmaps at once including their beatmapsets
30//! - `beatmaps/{map_id}/attributes`: The difficulty attributes of a beatmap
31//! - `beatmaps/{map_id}/scores`: The global score leaderboard for a beatmap
32//! - `beatmaps/{map_id}/scores/users/{user_id}[/all]`: Get (all) top score(s) of a user on a beatmap. Defaults to the play with the __max score__, not pp
33//! - `beatmapsets/{mapset_id}`: The beatmapset including all of its difficulty beatmaps
34//! - `beatmapsets/events`: Various events around a beatmapset such as status, genre, or language updates, kudosu transfers, or new issues
35//! - `beatmapsets/search`: Search for beatmapsets; the same search as on the osu! website
36//! - `comments`: Most recent comments and their replies up to two levels deep
37//! - `events`: Collection of events in order of creation time
38//! - `forums/topics/{topic_id}`: A forum topic and its posts
39//! - `friends`: List of authenticated user's friends
40//! - `matches`: List of currently open multiplayer lobbies
41//! - `matches/{match_id}`: More specific data about a specific multiplayer lobby including participating players and occured events
42//! - `me[/{mode}]`: Detailed info about the authenticated user [in the specified mode] (requires OAuth)
43//! - `news`: Recent news
44//! - `rankings/{mode}/{ranking_type}`: The global leaderboard of either performance points, ranked score, countries, or a spotlight
45//! - `users/{user_id}/{recent_activity}`: List of a user's recent events like achieved medals, ranks on a beatmaps, username changes, supporter status updates, beatmapset status updates, ...
46//! - `scores/{mode}/{score_id}`: A specific score including its beatmap, beatmapset, and user
47//! - `scores`: Up to 1000 most recently processed scores (passes)
48//! - `seasonal-backgrounds`: List of seasonal backgrounds i.e. their URL and artists
49//! - `spotlights`: List of overviews of all spotlights
50//! - `users/{user_id}[/{mode}]`: Detailed info about a user [in the specified mode]
51//! - `users/{user_id}/{beatmapsets/{map_type}`: List of beatmapsets either created, favourited, or most played by the user
52//! - `users/{user_id}/kudosu`: A user's recent kudosu transfers
53//! - `users/{user_id}/scores/{score_type}`: Either top, recent, pinned, or global #1 scores of a user
54//! - `users`: Up to 50 users at once including statistics for all modes
55//! - `wiki/{locale}[/{path}]`: The general wiki page or a specific topic if the path is specified
56//!
57//! The api itself provides a bunch more endpoints which are not yet implemented because they're either niche and/or missing any documentation.
58//!
59//! If you find an endpoint on the [api page](https://osu.ppy.sh/docs/index.html) that you want to use but is missing in rosu-v2, feel free to open an issue.
60//!
61//! ## Usage
62//!
63//! ```no_run
64//! // For convenience sake, all types can be found in the prelude module
65//! use rosu_v2::prelude::*;
66//!
67//! # fn main() {
68//! # /*
69//! #[tokio::main]
70//! async fn main() {
71//! # */
72//! # let _ = async {
73//! // Initialize the client
74//! let client_id: u64 = 123;
75//! let client_secret = String::from("my_secret");
76//! let osu = Osu::new(client_id, client_secret).await.unwrap();
77//!
78//! // Get peppy's top 10-15 scores in osu!standard.
79//! // Note that the username here can only be used because of the `cache` feature.
80//! // If you are fine with just providing user ids, consider disabling this feature.
81//! let scores: Vec<Score> = osu.user_scores("peppy")
82//! .mode(GameMode::Osu)
83//! .best() // top scores; alternatively .recent(), .pinned(), or .firsts()
84//! .offset(10)
85//! .limit(5)
86//! .await
87//! .unwrap();
88//!
89//! // Search non-nsfw loved mania maps matching the given query.
90//! // Note that the order of called methods doesn't matter for any endpoint.
91//! let search_result: BeatmapsetSearchResult = osu.beatmapset_search()
92//! .nsfw(false)
93//! .status(Some(RankStatus::Loved))
94//! .mode(GameMode::Mania)
95//! .query("blue army stars>3")
96//! .await
97//! .unwrap();
98//!
99//! // Get the french wiki page on the osu file format
100//! let wiki_page: WikiPage = osu.wiki("fr")
101//! .page("Client/File_formats/osu_%28file_format%29")
102//! .await
103//! .unwrap();
104//! # };
105//! }
106//! ```
107//!
108//! ## Features
109//!
110//! | Flag | Description | Dependencies
111//! | ------------- | ---------------------------------------- | ------------
112//! | `default` | Enable the `cache` and `macros` features |
113//! | `cache` | Cache username-userid pairs so that fetching data by username does one instead of two requests | [`dashmap`]
114//! | `macros` | Re-exports `rosu-mods`'s `mods!` macro to easily create mods for a given mode | [`paste`]
115//! | `serialize` | Implement `serde::Serialize` for most types, allowing for manual serialization |
116//! | `metrics` | Uses the global metrics registry to store response time for each endpoint | [`metrics`]
117//! | `replay` | Enables the method `Osu::replay` to parse a replay. Note that `Osu::replay_raw` is available without this feature but provides raw bytes instead of a parsed replay | [`osu-db`]
118//! | `local_oauth` | Enables the method `OsuBuilder::with_local_authorization` to perform the full OAuth procedure | `tokio/net` feature
119//!
120//! [osu!api v2]: https://osu.ppy.sh/docs/index.html
121//! [`rosu`]: https://github.com/MaxOhn/rosu
122//! [osu!api v1]: https://github.com/ppy/osu-api/wiki
123//! [`dashmap`]: https://docs.rs/dashmap
124//! [`paste`]: https://docs.rs/paste
125//! [`metrics`]: https://docs.rs/metrics
126//! [`osu-db`]: https://docs.rs/osu-db
127
128#![cfg_attr(docsrs, feature(doc_cfg))]
129#![deny(rustdoc::broken_intra_doc_links, rustdoc::missing_crate_level_docs)]
130#![warn(clippy::missing_const_for_fn, clippy::pedantic)]
131#![allow(
132 clippy::missing_errors_doc,
133 clippy::module_name_repetitions,
134 clippy::must_use_candidate,
135 clippy::struct_excessive_bools,
136 clippy::match_same_arms,
137 clippy::cast_possible_truncation,
138 clippy::cast_precision_loss,
139 clippy::cast_sign_loss,
140 clippy::explicit_iter_loop,
141 clippy::similar_names,
142 clippy::cast_possible_wrap,
143 clippy::default_trait_access,
144 clippy::ignored_unit_patterns
145)]
146
147mod client;
148mod future;
149mod routing;
150
151/// Errors types
152pub mod error;
153
154/// All available data types provided by the api
155pub mod model;
156
157/// Request related types to fetch from endpoints
158pub mod request;
159
160mod metrics;
161
162pub use self::client::{Osu, OsuBuilder};
163
164#[macro_use]
165extern crate tracing;
166
167#[cfg(feature = "macros")]
168extern crate rosu_mods;
169
170#[cfg(feature = "macros")]
171#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
172pub use rosu_mods::mods;
173
174/// `Result<_, OsuError>`
175pub type OsuResult<T> = Result<T, error::OsuError>;
176
177/// All types except requesting, stuffed into one module
178pub mod prelude {
179 pub use crate::{
180 client::{Scopes, Token},
181 error::OsuError,
182 model::{
183 beatmap::*,
184 comments::*,
185 event::*,
186 forum::*,
187 kudosu::*,
188 matches::*,
189 mods::{generated_mods::*, Acronym, GameMods, GameModsIntermode, GameModsLegacy},
190 news::*,
191 ranking::*,
192 score::*,
193 seasonal_backgrounds::*,
194 user::*,
195 wiki::*,
196 GameMode, Grade,
197 },
198 request::UserId,
199 Osu, OsuBuilder, OsuResult,
200 };
201
202 pub use hyper::StatusCode;
203 pub use smallstr::SmallString;
204
205 #[cfg(feature = "macros")]
206 #[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
207 pub use rosu_mods::mods;
208}