@@ -20,7 +20,7 @@ use crate::{
20
20
pub struct Client < Http : HttpClient = DefaultHttpClient > {
21
21
pub ( crate ) host : String ,
22
22
pub ( crate ) api_key : Option < String > ,
23
- pub http_client : Http ,
23
+ pub ( crate ) http_client : Http ,
24
24
}
25
25
26
26
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -98,7 +98,6 @@ impl<Http: HttpClient> Client<Http> {
98
98
self . http_client
99
99
. request :: < ( ) , & MultiSearchQuery < Http > , MultiSearchResponse < T > > (
100
100
& format ! ( "{}/multi-search" , & self . host) ,
101
- self . get_api_key ( ) ,
102
101
Method :: Post { body, query : ( ) } ,
103
102
200 ,
104
103
)
@@ -260,7 +259,6 @@ impl<Http: HttpClient> Client<Http> {
260
259
. http_client
261
260
. request :: < ( ) , ( ) , Value > (
262
261
& format ! ( "{}/indexes" , self . host) ,
263
- self . get_api_key ( ) ,
264
262
Method :: Get { query : ( ) } ,
265
263
200 ,
266
264
)
@@ -297,7 +295,6 @@ impl<Http: HttpClient> Client<Http> {
297
295
. http_client
298
296
. request :: < & IndexesQuery < Http > , ( ) , Value > (
299
297
& format ! ( "{}/indexes" , self . host) ,
300
- self . get_api_key ( ) ,
301
298
Method :: Get {
302
299
query : indexes_query,
303
300
} ,
@@ -358,7 +355,6 @@ impl<Http: HttpClient> Client<Http> {
358
355
self . http_client
359
356
. request :: < ( ) , ( ) , Value > (
360
357
& format ! ( "{}/indexes/{}" , self . host, uid. as_ref( ) ) ,
361
- self . get_api_key ( ) ,
362
358
Method :: Get { query : ( ) } ,
363
359
200 ,
364
360
)
@@ -406,7 +402,6 @@ impl<Http: HttpClient> Client<Http> {
406
402
self . http_client
407
403
. request :: < ( ) , Value , TaskInfo > (
408
404
& format ! ( "{}/indexes" , self . host) ,
409
- self . get_api_key ( ) ,
410
405
Method :: Post {
411
406
query : ( ) ,
412
407
body : json ! ( {
@@ -426,7 +421,6 @@ impl<Http: HttpClient> Client<Http> {
426
421
self . http_client
427
422
. request :: < ( ) , ( ) , TaskInfo > (
428
423
& format ! ( "{}/indexes/{}" , self . host, uid. as_ref( ) ) ,
429
- self . get_api_key ( ) ,
430
424
Method :: Delete { query : ( ) } ,
431
425
202 ,
432
426
)
@@ -498,7 +492,6 @@ impl<Http: HttpClient> Client<Http> {
498
492
self . http_client
499
493
. request :: < ( ) , Vec < & SwapIndexes > , TaskInfo > (
500
494
& format ! ( "{}/swap-indexes" , self . host) ,
501
- self . get_api_key ( ) ,
502
495
Method :: Post {
503
496
query : ( ) ,
504
497
body : indexes. into_iter ( ) . collect ( ) ,
@@ -527,7 +520,6 @@ impl<Http: HttpClient> Client<Http> {
527
520
self . http_client
528
521
. request :: < ( ) , ( ) , ClientStats > (
529
522
& format ! ( "{}/stats" , self . host) ,
530
- self . get_api_key ( ) ,
531
523
Method :: Get { query : ( ) } ,
532
524
200 ,
533
525
)
@@ -555,7 +547,6 @@ impl<Http: HttpClient> Client<Http> {
555
547
self . http_client
556
548
. request :: < ( ) , ( ) , Health > (
557
549
& format ! ( "{}/health" , self . host) ,
558
- self . get_api_key ( ) ,
559
550
Method :: Get { query : ( ) } ,
560
551
200 ,
561
552
)
@@ -614,7 +605,6 @@ impl<Http: HttpClient> Client<Http> {
614
605
. http_client
615
606
. request :: < & KeysQuery , ( ) , KeysResults > (
616
607
& format ! ( "{}/keys" , self . host) ,
617
- self . get_api_key ( ) ,
618
608
Method :: Get { query : keys_query } ,
619
609
200 ,
620
610
)
@@ -647,7 +637,6 @@ impl<Http: HttpClient> Client<Http> {
647
637
. http_client
648
638
. request :: < ( ) , ( ) , KeysResults > (
649
639
& format ! ( "{}/keys" , self . host) ,
650
- self . get_api_key ( ) ,
651
640
Method :: Get { query : ( ) } ,
652
641
200 ,
653
642
)
@@ -682,7 +671,6 @@ impl<Http: HttpClient> Client<Http> {
682
671
self . http_client
683
672
. request :: < ( ) , ( ) , Key > (
684
673
& format ! ( "{}/keys/{}" , self . host, key. as_ref( ) ) ,
685
- self . get_api_key ( ) ,
686
674
Method :: Get { query : ( ) } ,
687
675
200 ,
688
676
)
@@ -718,7 +706,6 @@ impl<Http: HttpClient> Client<Http> {
718
706
self . http_client
719
707
. request :: < ( ) , ( ) , ( ) > (
720
708
& format ! ( "{}/keys/{}" , self . host, key. as_ref( ) ) ,
721
- self . get_api_key ( ) ,
722
709
Method :: Delete { query : ( ) } ,
723
710
204 ,
724
711
)
@@ -753,7 +740,6 @@ impl<Http: HttpClient> Client<Http> {
753
740
self . http_client
754
741
. request :: < ( ) , & KeyBuilder , Key > (
755
742
& format ! ( "{}/keys" , self . host) ,
756
- self . get_api_key ( ) ,
757
743
Method :: Post {
758
744
query : ( ) ,
759
745
body : key. as_ref ( ) ,
@@ -794,7 +780,6 @@ impl<Http: HttpClient> Client<Http> {
794
780
self . http_client
795
781
. request :: < ( ) , & KeyUpdater , Key > (
796
782
& format ! ( "{}/keys/{}" , self . host, key. as_ref( ) . key) ,
797
- self . get_api_key ( ) ,
798
783
Method :: Patch {
799
784
body : key. as_ref ( ) ,
800
785
query : ( ) ,
@@ -823,7 +808,6 @@ impl<Http: HttpClient> Client<Http> {
823
808
self . http_client
824
809
. request :: < ( ) , ( ) , Version > (
825
810
& format ! ( "{}/version" , self . host) ,
826
- self . get_api_key ( ) ,
827
811
Method :: Get { query : ( ) } ,
828
812
200 ,
829
813
)
@@ -927,7 +911,6 @@ impl<Http: HttpClient> Client<Http> {
927
911
self . http_client
928
912
. request :: < ( ) , ( ) , Task > (
929
913
& format ! ( "{}/tasks/{}" , self . host, task_id. as_ref( ) ) ,
930
- self . get_api_key ( ) ,
931
914
Method :: Get { query : ( ) } ,
932
915
200 ,
933
916
)
@@ -960,7 +943,6 @@ impl<Http: HttpClient> Client<Http> {
960
943
. http_client
961
944
. request :: < & TasksSearchQuery < Http > , ( ) , TasksResults > (
962
945
& format ! ( "{}/tasks" , self . host) ,
963
- self . get_api_key ( ) ,
964
946
Method :: Get { query : tasks_query } ,
965
947
200 ,
966
948
)
@@ -995,7 +977,6 @@ impl<Http: HttpClient> Client<Http> {
995
977
. http_client
996
978
. request :: < & TasksCancelQuery < Http > , ( ) , TaskInfo > (
997
979
& format ! ( "{}/tasks/cancel" , self . host) ,
998
- self . get_api_key ( ) ,
999
980
Method :: Post {
1000
981
query : filters,
1001
982
body : ( ) ,
@@ -1033,7 +1014,6 @@ impl<Http: HttpClient> Client<Http> {
1033
1014
. http_client
1034
1015
. request :: < & TasksDeleteQuery < Http > , ( ) , TaskInfo > (
1035
1016
& format ! ( "{}/tasks" , self . host) ,
1036
- self . get_api_key ( ) ,
1037
1017
Method :: Delete { query : filters } ,
1038
1018
200 ,
1039
1019
)
@@ -1064,7 +1044,6 @@ impl<Http: HttpClient> Client<Http> {
1064
1044
. http_client
1065
1045
. request :: < ( ) , ( ) , TasksResults > (
1066
1046
& format ! ( "{}/tasks" , self . host) ,
1067
- self . get_api_key ( ) ,
1068
1047
Method :: Get { query : ( ) } ,
1069
1048
200 ,
1070
1049
)
@@ -1233,12 +1212,9 @@ mod tests {
1233
1212
. match_header( "User-Agent" , user_agent)
1234
1213
. create_async( )
1235
1214
. await ,
1236
- client. http_client. request:: <( ) , ( ) , ( ) >(
1237
- address,
1238
- None ,
1239
- Method :: Get { query: ( ) } ,
1240
- 200 ,
1241
- ) ,
1215
+ client
1216
+ . http_client
1217
+ . request:: <( ) , ( ) , ( ) >( address, Method :: Get { query: ( ) } , 200 ) ,
1242
1218
) ,
1243
1219
(
1244
1220
s. mock( "POST" , path)
@@ -1247,7 +1223,6 @@ mod tests {
1247
1223
. await ,
1248
1224
client. http_client. request:: <( ) , ( ) , ( ) >(
1249
1225
address,
1250
- None ,
1251
1226
Method :: Post {
1252
1227
query: ( ) ,
1253
1228
body: { } ,
@@ -1262,7 +1237,6 @@ mod tests {
1262
1237
. await ,
1263
1238
client. http_client. request:: <( ) , ( ) , ( ) >(
1264
1239
address,
1265
- None ,
1266
1240
Method :: Delete { query: ( ) } ,
1267
1241
200 ,
1268
1242
) ,
@@ -1274,7 +1248,6 @@ mod tests {
1274
1248
. await ,
1275
1249
client. http_client. request:: <( ) , ( ) , ( ) >(
1276
1250
address,
1277
- None ,
1278
1251
Method :: Put {
1279
1252
query: ( ) ,
1280
1253
body: ( ) ,
@@ -1289,7 +1262,6 @@ mod tests {
1289
1262
. await ,
1290
1263
client. http_client. request:: <( ) , ( ) , ( ) >(
1291
1264
address,
1292
- None ,
1293
1265
Method :: Patch {
1294
1266
query: ( ) ,
1295
1267
body: ( ) ,
@@ -1344,7 +1316,7 @@ mod tests {
1344
1316
}
1345
1317
1346
1318
#[ meilisearch_test]
1347
- async fn test_error_delete_key ( mut client : Client , name : String ) {
1319
+ async fn test_error_delete_key ( client : Client , name : String ) {
1348
1320
// ==> accessing a key that does not exist
1349
1321
let error = client. delete_key ( "invalid_key" ) . await . unwrap_err ( ) ;
1350
1322
insta:: assert_snapshot!( error, @"Meilisearch invalid_request: api_key_not_found: API key `invalid_key` not found.. https://docs.meilisearch.com/errors#api_key_not_found" ) ;
@@ -1355,8 +1327,9 @@ mod tests {
1355
1327
key. with_name ( & name) ;
1356
1328
let key = client. create_key ( key) . await . unwrap ( ) ;
1357
1329
let master_key = client. api_key . clone ( ) ;
1358
- // this key has no right
1359
- client. api_key = Some ( key. key . clone ( ) ) ;
1330
+
1331
+ // create a new client with no right
1332
+ let client = Client :: new ( client. host , Some ( key. key . clone ( ) ) ) ;
1360
1333
// with a wrong key
1361
1334
let error = client. delete_key ( "invalid_key" ) . await . unwrap_err ( ) ;
1362
1335
insta:: assert_snapshot!( error, @"Meilisearch auth: invalid_api_key: The provided API key is invalid.. https://docs.meilisearch.com/errors#invalid_api_key" ) ;
@@ -1381,7 +1354,7 @@ mod tests {
1381
1354
) ) ;
1382
1355
1383
1356
// cleanup
1384
- client. api_key = master_key;
1357
+ let client = Client :: new ( client . host , master_key) ;
1385
1358
client. delete_key ( key) . await . unwrap ( ) ;
1386
1359
}
1387
1360
@@ -1409,7 +1382,7 @@ mod tests {
1409
1382
}
1410
1383
1411
1384
#[ meilisearch_test]
1412
- async fn test_error_create_key ( mut client : Client , name : String ) {
1385
+ async fn test_error_create_key ( client : Client , name : String ) {
1413
1386
// ==> Invalid index name
1414
1387
/* TODO: uncomment once meilisearch fix this bug: https://github.com/meilisearch/meilisearch/issues/2158
1415
1388
let mut key = KeyBuilder::new();
@@ -1432,7 +1405,7 @@ mod tests {
1432
1405
1433
1406
// backup the master key for cleanup at the end of the test
1434
1407
let master_client = client. clone ( ) ;
1435
- client. api_key = Some ( no_right_key. key . clone ( ) ) ;
1408
+ let client = Client :: new ( & master_client . host , Some ( no_right_key. key . clone ( ) ) ) ;
1436
1409
1437
1410
let mut key = KeyBuilder :: new ( ) ;
1438
1411
key. with_name ( format ! ( "{name}_2" ) ) ;
0 commit comments