1
1
from __future__ import annotations
2
2
3
- import logging
4
3
from typing import TYPE_CHECKING , Any
5
4
6
5
from apify_shared .utils import (
10
9
parse_date_fields ,
11
10
)
12
11
13
- from apify_client ._utils import _to_json , encode_webhook_list_to_base64 , pluck_data
12
+ from apify_client ._utils import encode_key_value_store_record_value , encode_webhook_list_to_base64 , pluck_data
14
13
from apify_client .clients .base import ResourceClient , ResourceClientAsync
15
14
from apify_client .clients .resource_clients .actor_version import ActorVersionClient , ActorVersionClientAsync
16
15
from apify_client .clients .resource_clients .actor_version_collection import (
31
30
32
31
from apify_shared .consts import ActorJobStatus , MetaOrigin
33
32
34
- logger = logging .getLogger (__name__ )
35
-
36
33
37
34
def get_actor_representation (
38
35
* ,
@@ -219,7 +216,7 @@ def delete(self) -> None:
219
216
def start (
220
217
self ,
221
218
* ,
222
- run_input : str | dict | None = None ,
219
+ run_input : Any = None ,
223
220
content_type : str | None = None ,
224
221
build : str | None = None ,
225
222
max_items : int | None = None ,
@@ -235,7 +232,7 @@ def start(
235
232
236
233
Args:
237
234
run_input: The input to pass to the Actor run.
238
- content_type: Deprecated .
235
+ content_type: The content type of the input .
239
236
build: Specifies the Actor build to run. It can be either a build tag or build number. By default,
240
237
the run uses the build specified in the default run configuration for the Actor (typically latest).
241
238
max_items: Maximum number of results that will be returned by this run. If the Actor is charged
@@ -258,11 +255,7 @@ def start(
258
255
Returns:
259
256
The run object.
260
257
"""
261
- if content_type :
262
- logger .warning ('`content_type` is deprecated and not used anymore.' )
263
-
264
- if not isinstance (run_input , str ):
265
- run_input = _to_json (run_input )
258
+ run_input , content_type = encode_key_value_store_record_value (run_input , content_type )
266
259
267
260
request_params = self ._params (
268
261
build = build ,
@@ -277,7 +270,7 @@ def start(
277
270
response = self .http_client .call (
278
271
url = self ._url ('runs' ),
279
272
method = 'POST' ,
280
- headers = {'content-type' : 'application/json' },
273
+ headers = {'content-type' : content_type },
281
274
data = run_input ,
282
275
params = request_params ,
283
276
)
@@ -466,22 +459,22 @@ def webhooks(self) -> WebhookCollectionClient:
466
459
"""Retrieve a client for webhooks associated with this Actor."""
467
460
return WebhookCollectionClient (** self ._sub_resource_init_options ())
468
461
469
- def validate_input (self , run_input : str | bytes | dict | None = None ) -> bool :
462
+ def validate_input (self , run_input : Any = None , content_type : str | None = None ) -> bool :
470
463
"""Validate the input for the Actor.
471
464
472
465
Args:
473
- run_input: The input to validate. Either json string or a dictionary.
466
+ run_input: The input to validate.
467
+ content_type: The content type of the input.
474
468
475
469
Returns:
476
470
True if the input is valid, else raise an exception with validation error details.
477
471
"""
478
- if not isinstance (run_input , str ):
479
- run_input = _to_json (run_input )
472
+ run_input , content_type = encode_key_value_store_record_value (run_input , content_type )
480
473
481
474
self .http_client .call (
482
475
url = self ._url ('validate-input' ),
483
476
method = 'POST' ,
484
- headers = {'content-type' : 'application/json' },
477
+ headers = {'content-type' : content_type },
485
478
data = run_input ,
486
479
)
487
480
@@ -611,7 +604,7 @@ async def delete(self) -> None:
611
604
async def start (
612
605
self ,
613
606
* ,
614
- run_input : str | dict | None = None ,
607
+ run_input : Any = None ,
615
608
content_type : str | None = None ,
616
609
build : str | None = None ,
617
610
max_items : int | None = None ,
@@ -627,7 +620,7 @@ async def start(
627
620
628
621
Args:
629
622
run_input: The input to pass to the Actor run.
630
- content_type: Deprecated .
623
+ content_type: The content type of the input .
631
624
build: Specifies the Actor build to run. It can be either a build tag or build number. By default,
632
625
the run uses the build specified in the default run configuration for the Actor (typically latest).
633
626
max_items: Maximum number of results that will be returned by this run. If the Actor is charged
@@ -650,11 +643,7 @@ async def start(
650
643
Returns:
651
644
The run object.
652
645
"""
653
- if content_type :
654
- logger .warning ('`content_type` is deprecated and not used anymore.' )
655
-
656
- if not isinstance (run_input , str ):
657
- run_input = _to_json (run_input )
646
+ run_input , content_type = encode_key_value_store_record_value (run_input , content_type )
658
647
659
648
request_params = self ._params (
660
649
build = build ,
@@ -669,7 +658,7 @@ async def start(
669
658
response = await self .http_client .call (
670
659
url = self ._url ('runs' ),
671
660
method = 'POST' ,
672
- headers = {'content-type' : 'application/json' },
661
+ headers = {'content-type' : content_type },
673
662
data = run_input ,
674
663
params = request_params ,
675
664
)
@@ -862,22 +851,22 @@ def webhooks(self) -> WebhookCollectionClientAsync:
862
851
"""Retrieve a client for webhooks associated with this Actor."""
863
852
return WebhookCollectionClientAsync (** self ._sub_resource_init_options ())
864
853
865
- async def validate_input (self , run_input : str | dict | None = None ) -> bool :
854
+ async def validate_input (self , run_input : Any = None , content_type : str | None = None ) -> bool :
866
855
"""Validate the input for the Actor.
867
856
868
857
Args:
869
- run_input: The input to validate. Either json string or a dictionary.
858
+ run_input: The input to validate.
859
+ content_type: The content type of the input.
870
860
871
861
Returns:
872
862
True if the input is valid, else raise an exception with validation error details.
873
863
"""
874
- if not isinstance (run_input , str ):
875
- run_input = _to_json (run_input )
864
+ run_input , content_type = encode_key_value_store_record_value (run_input , content_type )
876
865
877
866
await self .http_client .call (
878
867
url = self ._url ('validate-input' ),
879
868
method = 'POST' ,
880
- headers = {'content-type' : 'application/json' },
869
+ headers = {'content-type' : content_type },
881
870
data = run_input ,
882
871
)
883
872
0 commit comments