Use Vec<Limit> instead of Limit because there are multiple limits

This commit is contained in:
bitfl0wer 2023-04-08 14:37:20 +02:00
parent f237de7353
commit 8d30e1461b
1 changed files with 19 additions and 12 deletions

View File

@ -10,7 +10,7 @@ pub struct Limit {
pub struct LimitedRequester { pub struct LimitedRequester {
http: Client, http: Client,
limit: Limit, limit: Vec<Limit>,
requests: VecDeque<Request>, requests: VecDeque<Request>,
} }
@ -19,27 +19,34 @@ impl LimitedRequester {
/// send them to the server using a `Client`. It keeps track of the remaining requests that can /// send them to the server using a `Client`. It keeps track of the remaining requests that can
/// be send within the `Limit` of an external API Ratelimiter, and looks at the returned request /// be send within the `Limit` of an external API Ratelimiter, and looks at the returned request
/// headers to see if it can find Ratelimit info to update itself. /// headers to see if it can find Ratelimit info to update itself.
pub fn new() -> Self { pub fn new(api_url: String) -> Self {
LimitedRequester { LimitedRequester {
limit: Limit { limit: LimitedRequester::check_limits(api_url),
limit: -1,
remaining: -1,
reset: -1,
bucket: String::new(),
},
http: Client::new(), http: Client::new(),
requests: VecDeque::new(), requests: VecDeque::new(),
} }
} }
pub fn check_limits(url: String) -> Limit { pub fn check_limits(url: String) -> Vec<Limit> {
let client = Client::new(); let client = Client::new();
let url_parsed = crate::URLBundle::parse_url(url); let url_parsed = crate::URLBundle::parse_url(url) + "/api/policies/instance/limits";
Limit { let mut limit_vector = Vec::new();
limit_vector.push(Limit {
limit: -1, limit: -1,
remaining: -1, remaining: -1,
reset: -1, reset: -1,
bucket: String::new(), bucket: String::new(),
} // TODO: Implement }); // TODO: Implement
limit_vector
} }
} }
/* #[cfg(test)] Tests work here as well, neat!
mod tests {
use super::*;
#[test]
fn test_parse_url() {
assert_eq!(1, 1)
}
} */