@@ -3,12 +3,14 @@ use reqwest::{IntoUrl, Url};
3
3
use slog:: { Logger , o} ;
4
4
5
5
use mithril_common:: StdResult ;
6
+ use mithril_common:: api_version:: APIVersionProvider ;
6
7
7
8
use crate :: client:: AggregatorClient ;
8
9
9
10
/// A builder of [AggregatorClient]
10
11
pub struct AggregatorClientBuilder {
11
12
aggregator_url_result : reqwest:: Result < Url > ,
13
+ api_version_provider : Option < APIVersionProvider > ,
12
14
logger : Option < Logger > ,
13
15
}
14
16
@@ -19,6 +21,7 @@ impl AggregatorClientBuilder {
19
21
pub fn new < U : IntoUrl > ( aggregator_url : U ) -> Self {
20
22
Self {
21
23
aggregator_url_result : aggregator_url. into_url ( ) ,
24
+ api_version_provider : None ,
22
25
logger : None ,
23
26
}
24
27
}
@@ -29,16 +32,24 @@ impl AggregatorClientBuilder {
29
32
self
30
33
}
31
34
35
+ /// Set the [APIVersionProvider] to use.
36
+ pub fn with_api_version_provider ( mut self , api_version_provider : APIVersionProvider ) -> Self {
37
+ self . api_version_provider = Some ( api_version_provider) ;
38
+ self
39
+ }
40
+
32
41
/// Returns an [AggregatorClient] based on the builder configuration
33
42
pub fn build ( self ) -> StdResult < AggregatorClient > {
34
43
let aggregator_endpoint =
35
44
enforce_trailing_slash ( self . aggregator_url_result . with_context (
36
45
|| "Invalid aggregator endpoint, it must be a correctly formed url" ,
37
46
) ?) ;
38
47
let logger = self . logger . unwrap_or_else ( || Logger :: root ( slog:: Discard , o ! ( ) ) ) ;
48
+ let api_version_provider = self . api_version_provider . unwrap_or_default ( ) ;
39
49
40
50
Ok ( AggregatorClient {
41
51
aggregator_endpoint,
52
+ api_version_provider,
42
53
client : reqwest:: Client :: new ( ) ,
43
54
logger,
44
55
} )
0 commit comments