Skip to content

Commit 63200d1

Browse files
algolia-botkai687
andcommitted
feat(templates): add request_options to python helpers consistently (#3868) (generated) [skip ci]
Co-authored-by: Kai Welke <[email protected]>
1 parent f377640 commit 63200d1

File tree

22 files changed

+90
-70
lines changed

22 files changed

+90
-70
lines changed

clients/algoliasearch-client-python/algoliasearch/search/client.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ async def _func(_prev: SearchRulesResponse) -> SearchRulesResponse:
420420
async def generate_secured_api_key(
421421
self,
422422
parent_api_key: str,
423-
restrictions: Optional[SecuredApiKeyRestrictions] = SecuredApiKeyRestrictions(),
423+
restrictions: Optional[
424+
Union[dict, SecuredApiKeyRestrictions]
425+
] = SecuredApiKeyRestrictions(),
424426
) -> str:
425427
"""
426428
Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
@@ -470,18 +472,23 @@ async def save_objects(
470472
self,
471473
index_name: str,
472474
objects: List[Dict[str, Any]],
475+
request_options: Optional[Union[dict, RequestOptions]] = None,
473476
) -> List[BatchResponse]:
474477
"""
475478
Helper: Saves the given array of objects in the given index. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
476479
"""
477480
return await self.chunked_batch(
478-
index_name=index_name, objects=objects, action=Action.ADDOBJECT
481+
index_name=index_name,
482+
objects=objects,
483+
action=Action.ADDOBJECT,
484+
request_options=request_options,
479485
)
480486

481487
async def delete_objects(
482488
self,
483489
index_name: str,
484490
object_ids: List[str],
491+
request_options: Optional[Union[dict, RequestOptions]] = None,
485492
) -> List[BatchResponse]:
486493
"""
487494
Helper: Deletes every records for the given objectIDs. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
@@ -490,13 +497,15 @@ async def delete_objects(
490497
index_name=index_name,
491498
objects=[{"objectID": id} for id in object_ids],
492499
action=Action.DELETEOBJECT,
500+
request_options=request_options,
493501
)
494502

495503
async def partial_update_objects(
496504
self,
497505
index_name: str,
498506
objects: List[Dict[str, Any]],
499507
create_if_not_exists: Optional[bool] = False,
508+
request_options: Optional[Union[dict, RequestOptions]] = None,
500509
) -> List[BatchResponse]:
501510
"""
502511
Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
@@ -507,6 +516,7 @@ async def partial_update_objects(
507516
action=Action.PARTIALUPDATEOBJECT
508517
if create_if_not_exists
509518
else Action.PARTIALUPDATEOBJECTNOCREATE,
519+
request_options=request_options,
510520
)
511521

512522
async def chunked_batch(
@@ -5346,7 +5356,9 @@ def _func(_prev: SearchRulesResponse) -> SearchRulesResponse:
53465356
def generate_secured_api_key(
53475357
self,
53485358
parent_api_key: str,
5349-
restrictions: Optional[SecuredApiKeyRestrictions] = SecuredApiKeyRestrictions(),
5359+
restrictions: Optional[
5360+
Union[dict, SecuredApiKeyRestrictions]
5361+
] = SecuredApiKeyRestrictions(),
53505362
) -> str:
53515363
"""
53525364
Helper: Generates a secured API key based on the given `parent_api_key` and given `restrictions`.
@@ -5396,18 +5408,23 @@ def save_objects(
53965408
self,
53975409
index_name: str,
53985410
objects: List[Dict[str, Any]],
5411+
request_options: Optional[Union[dict, RequestOptions]] = None,
53995412
) -> List[BatchResponse]:
54005413
"""
54015414
Helper: Saves the given array of objects in the given index. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
54025415
"""
54035416
return self.chunked_batch(
5404-
index_name=index_name, objects=objects, action=Action.ADDOBJECT
5417+
index_name=index_name,
5418+
objects=objects,
5419+
action=Action.ADDOBJECT,
5420+
request_options=request_options,
54055421
)
54065422

54075423
def delete_objects(
54085424
self,
54095425
index_name: str,
54105426
object_ids: List[str],
5427+
request_options: Optional[Union[dict, RequestOptions]] = None,
54115428
) -> List[BatchResponse]:
54125429
"""
54135430
Helper: Deletes every records for the given objectIDs. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
@@ -5416,13 +5433,15 @@ def delete_objects(
54165433
index_name=index_name,
54175434
objects=[{"objectID": id} for id in object_ids],
54185435
action=Action.DELETEOBJECT,
5436+
request_options=request_options,
54195437
)
54205438

54215439
def partial_update_objects(
54225440
self,
54235441
index_name: str,
54245442
objects: List[Dict[str, Any]],
54255443
create_if_not_exists: Optional[bool] = False,
5444+
request_options: Optional[Union[dict, RequestOptions]] = None,
54265445
) -> List[BatchResponse]:
54275446
"""
54285447
Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
@@ -5433,6 +5452,7 @@ def partial_update_objects(
54335452
action=Action.PARTIALUPDATEOBJECT
54345453
if create_if_not_exists
54355454
else Action.PARTIALUPDATEOBJECTNOCREATE,
5455+
request_options=request_options,
54365456
)
54375457

54385458
def chunked_batch(

tests/output/csharp/src/generated/e2e/Insights.test.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public async Task PushEventsTest1()
6363
Index = "products",
6464
UserToken = "user-123456",
6565
AuthenticatedUserToken = "user-123456",
66-
Timestamp = 1727568000000L,
66+
Timestamp = 1727827200000L,
6767
ObjectIDs = new List<string> { "9780545139700", "9780439784542" },
6868
QueryID = "43b15df305339e827f0ac0bdc5ebcaa7",
6969
}
@@ -76,7 +76,7 @@ public async Task PushEventsTest1()
7676
Index = "products",
7777
UserToken = "user-123456",
7878
AuthenticatedUserToken = "user-123456",
79-
Timestamp = 1727568000000L,
79+
Timestamp = 1727827200000L,
8080
ObjectIDs = new List<string> { "9780545139700", "9780439784542" },
8181
}
8282
),

tests/output/csharp/src/generated/requests/Insights.test.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ await client.PushEventsAsync(
580580
Index = "products",
581581
UserToken = "user-123456",
582582
AuthenticatedUserToken = "user-123456",
583-
Timestamp = 1727568000000L,
583+
Timestamp = 1727827200000L,
584584
ObjectIDs = new List<string> { "9780545139700", "9780439784542" },
585585
QueryID = "43b15df305339e827f0ac0bdc5ebcaa7",
586586
}
@@ -593,7 +593,7 @@ await client.PushEventsAsync(
593593
Index = "products",
594594
UserToken = "user-123456",
595595
AuthenticatedUserToken = "user-123456",
596-
Timestamp = 1727568000000L,
596+
Timestamp = 1727827200000L,
597597
ObjectIDs = new List<string> { "9780545139700", "9780439784542" },
598598
}
599599
),
@@ -605,7 +605,7 @@ await client.PushEventsAsync(
605605
Assert.Equal("/1/events", req.Path);
606606
Assert.Equal("POST", req.Method.ToString());
607607
JsonAssert.EqualOverrideDefault(
608-
"{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1727568000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1727568000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}",
608+
"{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1727827200000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1727827200000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}",
609609
req.Body,
610610
new JsonDiffConfig(false)
611611
);

tests/output/dart/test/requests/insights_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ void main() {
635635
index: "products",
636636
userToken: "user-123456",
637637
authenticatedUserToken: "user-123456",
638-
timestamp: 1727568000000,
638+
timestamp: 1727827200000,
639639
objectIDs: [
640640
"9780545139700",
641641
"9780439784542",
@@ -648,7 +648,7 @@ void main() {
648648
index: "products",
649649
userToken: "user-123456",
650650
authenticatedUserToken: "user-123456",
651-
timestamp: 1727568000000,
651+
timestamp: 1727827200000,
652652
objectIDs: [
653653
"9780545139700",
654654
"9780439784542",
@@ -661,7 +661,7 @@ void main() {
661661
expectPath(request.path, '/1/events');
662662
expect(request.method, 'post');
663663
expectBody(request.body,
664-
"""{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727568000000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727568000000,"objectIDs":["9780545139700","9780439784542"]}]}""");
664+
"""{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727827200000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1727827200000,"objectIDs":["9780545139700","9780439784542"]}]}""");
665665
},
666666
),
667667
);

tests/output/go/tests/e2e/insights_test.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/output/go/tests/requests/insights_test.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/output/java/src/test/java/com/algolia/e2e/Insights.test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void pushEventsTest1() {
5050
.setIndex("products")
5151
.setUserToken("user-123456")
5252
.setAuthenticatedUserToken("user-123456")
53-
.setTimestamp(1727568000000L)
53+
.setTimestamp(1727827200000L)
5454
.setObjectIDs(Arrays.asList("9780545139700", "9780439784542"))
5555
.setQueryID("43b15df305339e827f0ac0bdc5ebcaa7"),
5656
new ViewedObjectIDs()
@@ -59,7 +59,7 @@ void pushEventsTest1() {
5959
.setIndex("products")
6060
.setUserToken("user-123456")
6161
.setAuthenticatedUserToken("user-123456")
62-
.setTimestamp(1727568000000L)
62+
.setTimestamp(1727827200000L)
6363
.setObjectIDs(Arrays.asList("9780545139700", "9780439784542"))
6464
)
6565
)

tests/output/java/src/test/java/com/algolia/requests/Insights.test.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ void pushEventsTest1() {
720720
.setIndex("products")
721721
.setUserToken("user-123456")
722722
.setAuthenticatedUserToken("user-123456")
723-
.setTimestamp(1727568000000L)
723+
.setTimestamp(1727827200000L)
724724
.setObjectIDs(Arrays.asList("9780545139700", "9780439784542"))
725725
.setQueryID("43b15df305339e827f0ac0bdc5ebcaa7"),
726726
new ViewedObjectIDs()
@@ -729,7 +729,7 @@ void pushEventsTest1() {
729729
.setIndex("products")
730730
.setUserToken("user-123456")
731731
.setAuthenticatedUserToken("user-123456")
732-
.setTimestamp(1727568000000L)
732+
.setTimestamp(1727827200000L)
733733
.setObjectIDs(Arrays.asList("9780545139700", "9780439784542"))
734734
)
735735
)
@@ -741,9 +741,9 @@ void pushEventsTest1() {
741741
assertDoesNotThrow(() ->
742742
JSONAssert.assertEquals(
743743
"{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product" +
744-
" Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1727568000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product" +
744+
" Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1727827200000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product" +
745745
" Detail Page" +
746-
" Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1727568000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}",
746+
" Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1727827200000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}",
747747
req.body,
748748
JSONCompareMode.STRICT
749749
)

tests/output/javascript/src/e2e/insights.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('pushEvents', () => {
2727
index: 'products',
2828
userToken: 'user-123456',
2929
authenticatedUserToken: 'user-123456',
30-
timestamp: 1727568000000,
30+
timestamp: 1727827200000,
3131
objectIDs: ['9780545139700', '9780439784542'],
3232
queryID: '43b15df305339e827f0ac0bdc5ebcaa7',
3333
},
@@ -37,7 +37,7 @@ describe('pushEvents', () => {
3737
index: 'products',
3838
userToken: 'user-123456',
3939
authenticatedUserToken: 'user-123456',
40-
timestamp: 1727568000000,
40+
timestamp: 1727827200000,
4141
objectIDs: ['9780545139700', '9780439784542'],
4242
},
4343
],

tests/output/javascript/src/requests/insights.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ describe('pushEvents', () => {
308308
index: 'products',
309309
userToken: 'user-123456',
310310
authenticatedUserToken: 'user-123456',
311-
timestamp: 1727568000000,
311+
timestamp: 1727827200000,
312312
objectIDs: ['9780545139700', '9780439784542'],
313313
queryID: '43b15df305339e827f0ac0bdc5ebcaa7',
314314
},
@@ -318,7 +318,7 @@ describe('pushEvents', () => {
318318
index: 'products',
319319
userToken: 'user-123456',
320320
authenticatedUserToken: 'user-123456',
321-
timestamp: 1727568000000,
321+
timestamp: 1727827200000,
322322
objectIDs: ['9780545139700', '9780439784542'],
323323
},
324324
],
@@ -334,7 +334,7 @@ describe('pushEvents', () => {
334334
index: 'products',
335335
userToken: 'user-123456',
336336
authenticatedUserToken: 'user-123456',
337-
timestamp: 1727568000000,
337+
timestamp: 1727827200000,
338338
objectIDs: ['9780545139700', '9780439784542'],
339339
queryID: '43b15df305339e827f0ac0bdc5ebcaa7',
340340
},
@@ -344,7 +344,7 @@ describe('pushEvents', () => {
344344
index: 'products',
345345
userToken: 'user-123456',
346346
authenticatedUserToken: 'user-123456',
347-
timestamp: 1727568000000,
347+
timestamp: 1727827200000,
348348
objectIDs: ['9780545139700', '9780439784542'],
349349
},
350350
],

tests/output/kotlin/src/commonTest/kotlin/com/algolia/e2e/InsightsTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class InsightsTest {
4141
index = "products",
4242
userToken = "user-123456",
4343
authenticatedUserToken = "user-123456",
44-
timestamp = 1727568000000L,
44+
timestamp = 1727827200000L,
4545
objectIDs = listOf("9780545139700", "9780439784542"),
4646
queryID = "43b15df305339e827f0ac0bdc5ebcaa7",
4747
),
@@ -51,7 +51,7 @@ class InsightsTest {
5151
index = "products",
5252
userToken = "user-123456",
5353
authenticatedUserToken = "user-123456",
54-
timestamp = 1727568000000L,
54+
timestamp = 1727827200000L,
5555
objectIDs = listOf("9780545139700", "9780439784542"),
5656
),
5757
),

0 commit comments

Comments
 (0)