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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//!
//! A basic wrapper around the [Hypixel Public API](https://api.hypixel.net)
//! that's fully asynchronous and can query any data type that implements
//! [`DeserializeOwned`](https://docs.serde.rs/serde/de/trait.DeserializeOwned.html) from serde.
//!
//! Hypixel's Public API imposes a default limit of 120 requests/minute. This crate
//! offers a wrapper around this dynamic limit to avoid hitting it and
//! receiving useless error responses.
//!
//! # Getting started
//!
//! As explained in the [Hypixel Public API](https://api.hypixel.net/), an `ApiKey` is required to
//! query most of the endpoints in the API.
//!
//! The heart of this crate is the [`RequestHandler`].\
//! Internally, it keeps track of how many requests the program has sent in the past minute,
//! keeps an overflow of requests pending when necessary and always stays synchronized
//! with the internal clock of the `Hypixel REST API`.
//!
//! A response from the API can be deserialized into any data structure that implements
//! [`DeserializeOwned`](https://docs.serde.rs/serde/de/trait.DeserializeOwned.html) by [serde](https://serde.rs).
//! #### Basic example
//! ```rust,no_run
//! use hypixel_api::RequestHandler;
//! use hypixel_api::StatusReply;
//! # use uuid::Uuid;
//! # use std::str::FromStr;
//!
//! # #[tokio::main]
//! # async fn main() {
//! let api_key = Uuid::from_str("your-api-key").unwrap(); // get your ApiKey
//! let request_handler = RequestHandler::new(api_key); // initialize a new RequestHandler
//!
//! let response = request_handler.request::<StatusReply>("status?uuid=069a79f4-44e9-4726-a5be-fca90e38aaf5", true); // query the status of Notch
//! // send more requests ...
//!
//! let data: StatusReply = response.await.unwrap().unwrap();
//! // use data ...
//! # }
//! ```
//!
//! Any [`Result::Ok`] response by this crate will guarantee to be a `200 OK` response from
//! the API and thus by consequence guarantee to be deserializable into a corresponding data
//!
//! Currently, many example response data structures are unimplemented. This does not impact
//! this crate's ability to still query that data. Simply define your own data structure and
//! use it with [`RequestHandler`] like usual. You could even replace all pre-made data structures
//! and go fully custom.
//!
//! See the documentation of [`RequestHandler`] for more information on sending requests.
//!
//! #### Example with custom data structure
//! ```rust,no_run
//! use hypixel_api::RequestHandler;
//! # use uuid::Uuid;
//! # use std::str::FromStr;
//! # use serde::Deserialize;
//!
//! // Simplistic Key data
//! #[derive(Deserialize)]
//! pub struct MyCustomKeyReply {
//! success: bool,
//! record: KeyData,
//! }
//!
//! #[derive(Deserialize)]
//! pub struct KeyData {
//! owner: Uuid,
//! limit: i32,
//! }
//!
//! # #[tokio::main]
//! # async fn main() {
//! # let api_key = Uuid::from_str("your-api-key").unwrap();
//! let request_handler = RequestHandler::new(api_key); // initialize a RequestHandler
//!
//! let response = request_handler.request::<MyCustomKeyReply>("key", true); // query https://api.hypixel.net/key
//! // do something ...
//!
//! let data: MyCustomKeyReply = response.await.unwrap().unwrap();
//! // use data ...
//! # }
//! ```
//!
//! # Features
//! - `util` - enables the utility functions to process data returned by the `Hypixel Public API`
//! - `reply` - (*depends on `util`*) - enables ready-to-use data structures as responses from the `Hypixel Public API`
extern crate tracing;
pub use error;
pub use reply;
pub use util;
pub use RequestHandler;
pub use *;
pub use ;