From a074b5ebed8689db3456a4873aba387e1a7cff42 Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Sat, 2 Nov 2019 22:42:14 -0700 Subject: [PATCH] enable setting client builder in config --- src/config.rs | 13 +++++++++++-- src/riot_api.rs | 7 ++++--- tests/tests_na.rs | 1 - 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index d0fedef..6a88f0d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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, } 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 + } } diff --git a/src/riot_api.rs b/src/riot_api.rs index 90641d4..34733ab 100644 --- a/src/riot_api.rs +++ b/src/riot_api.rs @@ -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(), } } diff --git a/tests/tests_na.rs b/tests/tests_na.rs index 3094c51..df88255 100644 --- a/tests/tests_na.rs +++ b/tests/tests_na.rs @@ -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 {