1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! rosu is a rust api wrapper for the game [osu!](https://osu.ppy.sh/home)
//!
//! The basic internal ratelimiter limits the amount of requests to
//! roughly 10 requests per second.
//!
//! Simply initialize an [osu client][osu], formulate a request such as a [UserRequest][user_req],
//! and then retrieve the data by calling the request's `queue` method with a reference to the
//! client as argument.
//!
//! [osu]: backend/struct.Osu.html
//! [user_req]: backend/requests/struct.UserRequest.html
//!
//! ## Examples
//!
//! ```no_run
//! use chrono::{offset::TimeZone, DateTime, Utc};
//! use rosu::{
//!     backend::{BeatmapRequest, BestRequest, MatchRequest, UserRequest},
//!     models::*,
//!     Osu, OsuError,
//! };
//!
//! #[tokio::main]
//! async fn main() -> Result<(), OsuError> {
//!     // Initialize the client
//!     let osu = Osu::new("osu_api_key");
//!
//!     // --- Retrieving top scores ---
//!
//!     // Accumulate all important arguments for the request
//!     let request = BestRequest::with_username("Badewanne3")
//!         .mode(GameMode::MNA)
//!         .limit(4);
//!     // Asynchronously send the request through the osu client
//!     let mut scores: Vec<Score> = request.queue(&osu).await?;
//!     match scores.pop() {
//!         Some(score) => {
//!             // Retrieve user of the score
//!             let user = score.get_user(&osu, GameMode::STD).await?;
//!             // ...
//!         }
//!         None => println!("No top scores found"),
//!     }
//!
//!     // --- Retrieving beatmaps ---
//!
//!     let since_date: DateTime<Utc> = Utc
//!         .datetime_from_str("2018-11-13 23:01:28", "%Y-%m-%d %H:%M:%S")
//!         .unwrap();
//!     let request = BeatmapRequest::new()
//!         .mode(GameMode::MNA)
//!         .limit(3)
//!         .mods(&GameMods::new(vec![GameMod::Key4, GameMod::Hidden]))
//!         .since(since_date)
//!         .mapset_id(945496);
//!     let mut maps: Vec<Beatmap> = request.queue(&osu).await?;
//!     if let Some(map) = maps.pop() {
//!         let leaderboard: Vec<Score> = map.get_global_leaderboard(&osu, 13).await?;
//!         // ...
//!     }
//!
//!     // --- Retrieving user ---
//!
//!     let user = UserRequest::with_username("Badewanne3")
//!         .queue_single(&osu)
//!         .await?;
//!     // ...
//!
//!     // --- Retrieving match ---
//!
//!     let osu_match = MatchRequest::with_match_id(58494587)
//!         .queue_single(&osu)
//!         .await?;
//!
//!     // ...
//!
//!     Ok(())
//! }
//! ```

#![deny(rust_2018_idioms)]

/// Contains the client and the request logic
pub mod backend;
/// Contains all osu! related data structs
pub mod models;

mod util;

#[macro_use]
extern crate log;

pub use backend::{Osu, OsuError, OsuResult};