mirror of https://github.com/MingweiSamuel/Riven
enable setting client builder in config
parent
eac7e27f95
commit
a074b5ebed
|
@ -12,7 +12,7 @@ pub struct RiotApiConfig {
|
|||
pub(crate) retries: u8,
|
||||
pub(crate) burst_pct: f32,
|
||||
pub(crate) duration_overhead: Duration,
|
||||
pub(crate) reqwest_client: ClientBuilder,
|
||||
pub(crate) client_builder: Option<ClientBuilder>,
|
||||
}
|
||||
|
||||
impl RiotApiConfig {
|
||||
|
@ -42,7 +42,7 @@ impl RiotApiConfig {
|
|||
retries: 3,
|
||||
burst_pct: Self::PRECONFIG_BURST_BURST_PCT,
|
||||
duration_overhead: Duration::from_millis(Self::PRECONFIG_BURST_DURATION_OVERHEAD_MILLIS),
|
||||
reqwest_client: ClientBuilder::new(),
|
||||
client_builder: Some(ClientBuilder::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,4 +147,13 @@ impl RiotApiConfig {
|
|||
self.duration_overhead = duration_overhead;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the reqwest `ClientBuilder`.
|
||||
///
|
||||
/// # Returns
|
||||
/// `self`, for chaining.
|
||||
pub fn set_client_builder(mut self, client_builder: ClientBuilder) -> Self {
|
||||
self.client_builder = Some(client_builder);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,11 +31,12 @@ pub struct RiotApi {
|
|||
}
|
||||
|
||||
impl RiotApi {
|
||||
pub fn with_config(config: RiotApiConfig) -> Self {
|
||||
log::trace!("Creating client (TODO: configuration).");
|
||||
pub fn with_config(mut config: RiotApiConfig) -> Self {
|
||||
let client_builder = config.client_builder.take()
|
||||
.expect("!NONE CLIENT_BUILDER IN CONFIG.");
|
||||
Self {
|
||||
config: config,
|
||||
client: Client::new(),
|
||||
client: client_builder.build().expect("Failed to create client from builder."),
|
||||
regional_requesters: InsertOnlyCHashMap::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ async_tests!{
|
|||
// match_get_old: async {
|
||||
// let p = RIOT_API.match_v4().get_match(Region::NA, 2632789562);
|
||||
// let m = p.await.map_err(|e| e.to_string())?.ok_or("Failed to get match.".to_owned())?;
|
||||
// // TODO.
|
||||
// Ok(())
|
||||
// },
|
||||
match_get_aram: async {
|
||||
|
|
Loading…
Reference in New Issue