-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_get-record-leaderboard.rs
57 lines (49 loc) · 1.74 KB
/
07_get-record-leaderboard.rs
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
//! Gets the record leaderboard fulfilling the search criteria.
//!
//! Run the following Cargo command to run this example:
//!
//! ```bash
//! cargo run --example 07_get-record-leaderboard
//! ```
//!
//! Want to paginate over this data?
//! Remember to pass an `X-Session-ID` header using the [`Client::with_session_id`] to ensure data consistency.
//! For more details, see the example in `/examples/15_pagination-for-leaderboard.rs`.
use tetr_ch::prelude::*;
#[tokio::main]
async fn main() {
let client = Client::new();
// Set the record leaderboard ID to look up.
// Record leaderboard ID: `zenith_country_JP@2024w31`
let leaderboard_id = RecordsLeaderboardId::new(
// Game mode: `zenith` (QUICK PLAY)
"zenith",
// Scope: `JP` (Japan)
Scope::Country("JP".to_string()),
// Revolution ID: `@2024w31`
Some("@2024w31"),
);
// Set the search criteria to filter records by.
let criteria = record_leaderboard::SearchCriteria::new()
// Upper bound is `[500000, 0, 0]`
.after([500000., 0., 0.])
// Three entries
.limit(3);
// Get the information.
let response = match client
.get_records_leaderboard(leaderboard_id, Some(criteria))
.await
{
Ok(res) => res,
Err(err) => panic!("Response error: {}\n", err),
};
if let Some(err) = response.error {
panic!("Error: {}\n", err.msg.expect("no error message"));
}
let data = response.data.unwrap();
data.entries
.iter()
.for_each(|entry| println!("{}", entry.replay_url()));
// For more information about the data structure, see:
// https://docs.rs/tetr_ch/latest/tetr_ch/model/records_leaderboard/struct.RecordsLeaderboard.html
}