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
33
36
34
37
35
def get_actor_representation (
@@ -219,7 +217,7 @@ def delete(self) -> None:
219
217
def start (
220
218
self ,
221
219
* ,
222
- run_input : str | dict | None = None ,
220
+ run_input : Any = None ,
223
221
content_type : str | None = None ,
224
222
build : str | None = None ,
225
223
max_items : int | None = None ,
@@ -235,7 +233,7 @@ def start(
235
233
236
234
Args:
237
235
run_input: The input to pass to the Actor run.
238
- content_type: Deprecated .
236
+ content_type: The content type of the input .
239
237
build: Specifies the Actor build to run. It can be either a build tag or build number. By default,
240
238
the run uses the build specified in the default run configuration for the Actor (typically latest).
241
239
max_items: Maximum number of results that will be returned by this run. If the Actor is charged
@@ -258,11 +256,7 @@ def start(
258
256
Returns:
259
257
The run object.
260
258
"""
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 )
259
+ run_input , content_type = encode_key_value_store_record_value (run_input , content_type )
266
260
267
261
request_params = self ._params (
268
262
build = build ,
@@ -277,7 +271,7 @@ def start(
277
271
response = self .http_client .call (
278
272
url = self ._url ('runs' ),
279
273
method = 'POST' ,
280
- headers = {'content-type' : 'application/json' },
274
+ headers = {'content-type' : content_type },
281
275
data = run_input ,
282
276
params = request_params ,
283
277
)
@@ -466,22 +460,22 @@ def webhooks(self) -> WebhookCollectionClient:
466
460
"""Retrieve a client for webhooks associated with this Actor."""
467
461
return WebhookCollectionClient (** self ._sub_resource_init_options ())
468
462
469
- def validate_input (self , run_input : str | bytes | dict | None = None ) -> bool :
463
+ def validate_input (self , run_input : Any = None , content_type : str | None = None ) -> bool :
470
464
"""Validate the input for the Actor.
471
465
472
466
Args:
473
- run_input: The input to validate. Either json string or a dictionary.
467
+ run_input: The input to validate.
468
+ content_type: The content type of the input.
474
469
475
470
Returns:
476
471
True if the input is valid, else raise an exception with validation error details.
477
472
"""
478
- if not isinstance (run_input , str ):
479
- run_input = _to_json (run_input )
473
+ run_input , content_type = encode_key_value_store_record_value (run_input , content_type )
480
474
481
475
self .http_client .call (
482
476
url = self ._url ('validate-input' ),
483
477
method = 'POST' ,
484
- headers = {'content-type' : 'application/json' },
478
+ headers = {'content-type' : content_type },
485
479
data = run_input ,
486
480
)
487
481
@@ -611,7 +605,7 @@ async def delete(self) -> None:
611
605
async def start (
612
606
self ,
613
607
* ,
614
- run_input : str | dict | None = None ,
608
+ run_input : Any = None ,
615
609
content_type : str | None = None ,
616
610
build : str | None = None ,
617
611
max_items : int | None = None ,
@@ -627,7 +621,7 @@ async def start(
627
621
628
622
Args:
629
623
run_input: The input to pass to the Actor run.
630
- content_type: Deprecated .
624
+ content_type: The content type of the input .
631
625
build: Specifies the Actor build to run. It can be either a build tag or build number. By default,
632
626
the run uses the build specified in the default run configuration for the Actor (typically latest).
633
627
max_items: Maximum number of results that will be returned by this run. If the Actor is charged
@@ -650,11 +644,7 @@ async def start(
650
644
Returns:
651
645
The run object.
652
646
"""
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 )
647
+ run_input , content_type = encode_key_value_store_record_value (run_input , content_type )
658
648
659
649
request_params = self ._params (
660
650
build = build ,
@@ -669,7 +659,7 @@ async def start(
669
659
response = await self .http_client .call (
670
660
url = self ._url ('runs' ),
671
661
method = 'POST' ,
672
- headers = {'content-type' : 'application/json' },
662
+ headers = {'content-type' : content_type },
673
663
data = run_input ,
674
664
params = request_params ,
675
665
)
@@ -862,22 +852,22 @@ def webhooks(self) -> WebhookCollectionClientAsync:
862
852
"""Retrieve a client for webhooks associated with this Actor."""
863
853
return WebhookCollectionClientAsync (** self ._sub_resource_init_options ())
864
854
865
- async def validate_input (self , run_input : str | dict | None = None ) -> bool :
855
+ async def validate_input (self , run_input : Any = None , content_type : str | None = None ) -> bool :
866
856
"""Validate the input for the Actor.
867
857
868
858
Args:
869
- run_input: The input to validate. Either json string or a dictionary.
859
+ run_input: The input to validate.
860
+ content_type: The content type of the input.
870
861
871
862
Returns:
872
863
True if the input is valid, else raise an exception with validation error details.
873
864
"""
874
- if not isinstance (run_input , str ):
875
- run_input = _to_json (run_input )
865
+ run_input , content_type = encode_key_value_store_record_value (run_input , content_type )
876
866
877
867
await self .http_client .call (
878
868
url = self ._url ('validate-input' ),
879
869
method = 'POST' ,
880
- headers = {'content-type' : 'application/json' },
870
+ headers = {'content-type' : content_type },
881
871
data = run_input ,
882
872
)
883
873
0 commit comments