@@ -15,7 +15,8 @@ import 'package:logging/logging.dart' show Logger;
1515/// response conversion and error handling.
1616class ChopperRequester implements Requester {
1717 /// The underlying Chopper client.
18- final ChopperClient _client;
18+ AuthInterceptor _authInterceptor;
19+ late final ChopperClient _client;
1920
2021 /// Constructs a [ChopperClient] with the given [appId] and [apiKey] .
2122 ChopperRequester ({
@@ -27,30 +28,32 @@ class ChopperRequester implements Requester {
2728 Iterable <Interceptor >? interceptors,
2829 http.Client ? client,
2930 JsonConverter ? converter,
30- }) : _client = ChopperClient (
31- client: client,
32- converter: converter ?? JsonConverter (),
33- interceptors: [
34- AuthInterceptor (
35- appId: appId,
36- apiKey: apiKey,
37- ),
38- AgentInterceptor (
39- agent: AlgoliaAgent (packageVersion)
40- ..addAll ([
41- ...? clientSegments,
42- ...Platform .agentSegments (),
43- ]),
44- ),
45- if (logger != null )
46- HttpLoggingInterceptor (
47- level: Level .body,
48- onlyErrors: false ,
49- logger: logger,
50- ),
51- ...? interceptors,
52- ],
53- );
31+ }) : _authInterceptor = AuthInterceptor (
32+ appId: appId,
33+ apiKey: apiKey,
34+ ) {
35+ _client = ChopperClient (
36+ client: client,
37+ converter: converter ?? JsonConverter (),
38+ interceptors: [
39+ _authInterceptor,
40+ AgentInterceptor (
41+ agent: AlgoliaAgent (packageVersion)
42+ ..addAll ([
43+ ...? clientSegments,
44+ ...Platform .agentSegments (),
45+ ]),
46+ ),
47+ if (logger != null )
48+ HttpLoggingInterceptor (
49+ level: Level .body,
50+ onlyErrors: false ,
51+ logger: logger,
52+ ),
53+ ...? interceptors,
54+ ],
55+ );
56+ }
5457
5558 @override
5659 Future <HttpResponse > perform (HttpRequest request) async {
@@ -114,4 +117,12 @@ class ChopperRequester implements Requester {
114117
115118 @override
116119 void close () => _client.dispose ();
120+
121+ @override
122+ void setClientApiKey (String apiKey) {
123+ _authInterceptor = AuthInterceptor (
124+ appId: _authInterceptor.appId,
125+ apiKey: apiKey,
126+ );
127+ }
117128}
0 commit comments