11from __future__ import annotations
22
3- import logging
43from typing import TYPE_CHECKING , Any
54
65from apify_shared .utils import (
109 parse_date_fields ,
1110)
1211
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
1413from apify_client .clients .base import ResourceClient , ResourceClientAsync
1514from apify_client .clients .resource_clients .actor_version import ActorVersionClient , ActorVersionClientAsync
1615from apify_client .clients .resource_clients .actor_version_collection import (
3130
3231 from apify_shared .consts import ActorJobStatus , MetaOrigin
3332
34- logger = logging .getLogger (__name__ )
35-
3633
3734def get_actor_representation (
3835 * ,
@@ -219,7 +216,7 @@ def delete(self) -> None:
219216 def start (
220217 self ,
221218 * ,
222- run_input : str | dict | None = None ,
219+ run_input : Any = None ,
223220 content_type : str | None = None ,
224221 build : str | None = None ,
225222 max_items : int | None = None ,
@@ -235,7 +232,7 @@ def start(
235232
236233 Args:
237234 run_input: The input to pass to the Actor run.
238- content_type: Deprecated .
235+ content_type: The content type of the input .
239236 build: Specifies the Actor build to run. It can be either a build tag or build number. By default,
240237 the run uses the build specified in the default run configuration for the Actor (typically latest).
241238 max_items: Maximum number of results that will be returned by this run. If the Actor is charged
@@ -258,11 +255,7 @@ def start(
258255 Returns:
259256 The run object.
260257 """
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 )
266259
267260 request_params = self ._params (
268261 build = build ,
@@ -277,7 +270,7 @@ def start(
277270 response = self .http_client .call (
278271 url = self ._url ('runs' ),
279272 method = 'POST' ,
280- headers = {'content-type' : 'application/json' },
273+ headers = {'content-type' : content_type },
281274 data = run_input ,
282275 params = request_params ,
283276 )
@@ -466,22 +459,22 @@ def webhooks(self) -> WebhookCollectionClient:
466459 """Retrieve a client for webhooks associated with this Actor."""
467460 return WebhookCollectionClient (** self ._sub_resource_init_options ())
468461
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 :
470463 """Validate the input for the Actor.
471464
472465 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.
474468
475469 Returns:
476470 True if the input is valid, else raise an exception with validation error details.
477471 """
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 )
480473
481474 self .http_client .call (
482475 url = self ._url ('validate-input' ),
483476 method = 'POST' ,
484- headers = {'content-type' : 'application/json' },
477+ headers = {'content-type' : content_type },
485478 data = run_input ,
486479 )
487480
@@ -611,7 +604,7 @@ async def delete(self) -> None:
611604 async def start (
612605 self ,
613606 * ,
614- run_input : str | dict | None = None ,
607+ run_input : Any = None ,
615608 content_type : str | None = None ,
616609 build : str | None = None ,
617610 max_items : int | None = None ,
@@ -627,7 +620,7 @@ async def start(
627620
628621 Args:
629622 run_input: The input to pass to the Actor run.
630- content_type: Deprecated .
623+ content_type: The content type of the input .
631624 build: Specifies the Actor build to run. It can be either a build tag or build number. By default,
632625 the run uses the build specified in the default run configuration for the Actor (typically latest).
633626 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(
650643 Returns:
651644 The run object.
652645 """
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 )
658647
659648 request_params = self ._params (
660649 build = build ,
@@ -669,7 +658,7 @@ async def start(
669658 response = await self .http_client .call (
670659 url = self ._url ('runs' ),
671660 method = 'POST' ,
672- headers = {'content-type' : 'application/json' },
661+ headers = {'content-type' : content_type },
673662 data = run_input ,
674663 params = request_params ,
675664 )
@@ -862,22 +851,22 @@ def webhooks(self) -> WebhookCollectionClientAsync:
862851 """Retrieve a client for webhooks associated with this Actor."""
863852 return WebhookCollectionClientAsync (** self ._sub_resource_init_options ())
864853
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 :
866855 """Validate the input for the Actor.
867856
868857 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.
870860
871861 Returns:
872862 True if the input is valid, else raise an exception with validation error details.
873863 """
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 )
876865
877866 await self .http_client .call (
878867 url = self ._url ('validate-input' ),
879868 method = 'POST' ,
880- headers = {'content-type' : 'application/json' },
869+ headers = {'content-type' : content_type },
881870 data = run_input ,
882871 )
883872
0 commit comments