Skip to content

Commit 5810f97

Browse files
committed
rm pluck data
1 parent 6603c61 commit 5810f97

File tree

15 files changed

+101
-117
lines changed

15 files changed

+101
-117
lines changed

src/apify_client/_resource_clients/actor.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
encode_webhook_list_to_base64,
2626
filter_out_none_values_recursively,
2727
maybe_extract_enum_member_value,
28-
pluck_data,
28+
response_to_dict,
2929
)
3030

3131
if TYPE_CHECKING:
@@ -295,8 +295,8 @@ def start(
295295
params=request_params,
296296
)
297297

298-
result = pluck_data(response.json())
299-
return Run.model_validate(result)
298+
data = response_to_dict(response)
299+
return Run.model_validate(data)
300300

301301
def call(
302302
self,
@@ -414,8 +414,7 @@ def build(
414414
params=request_params,
415415
)
416416

417-
result = pluck_data(response.json())
418-
return Build.model_validate(result)
417+
return Build.model_validate(response_to_dict(response))
419418

420419
def builds(self) -> BuildCollectionClient:
421420
"""Retrieve a client for the builds of this Actor."""
@@ -446,7 +445,7 @@ async def default_build(
446445
)
447446

448447
response = self.http_client.call(url=self._url('builds/default'), method='GET', params=request_params)
449-
data = pluck_data(response.json())
448+
data = response_to_dict(response)
450449

451450
return BuildClient(
452451
base_url=self.base_url,
@@ -722,8 +721,8 @@ async def start(
722721
params=request_params,
723722
)
724723

725-
result = pluck_data(response.json())
726-
return Run.model_validate(result)
724+
data = response_to_dict(response)
725+
return Run.model_validate(data)
727726

728727
async def call(
729728
self,
@@ -845,8 +844,8 @@ async def build(
845844
params=request_params,
846845
)
847846

848-
result = pluck_data(response.json())
849-
return Build.model_validate(result)
847+
data = response_to_dict(response)
848+
return Build.model_validate(data)
850849

851850
def builds(self) -> BuildCollectionClientAsync:
852851
"""Retrieve a client for the builds of this Actor."""
@@ -881,7 +880,7 @@ async def default_build(
881880
method='GET',
882881
params=request_params,
883882
)
884-
data = pluck_data(response.json())
883+
data = response_to_dict(response)
885884

886885
return BuildClientAsync(
887886
base_url=self.base_url,

src/apify_client/_resource_clients/base/actor_job_base_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from apify_shared.consts import ActorJobStatus
99

1010
from apify_client._resource_clients.base.resource_client import ResourceClient, ResourceClientAsync
11-
from apify_client._utils import catch_not_found_or_throw, pluck_data
11+
from apify_client._utils import catch_not_found_or_throw, response_to_dict
1212
from apify_client.errors import ApifyApiError
1313

1414
DEFAULT_WAIT_FOR_FINISH_SEC = 999999
@@ -37,7 +37,7 @@ def _wait_for_finish(self, wait_secs: int | None = None) -> dict | None:
3737
method='GET',
3838
params=self._params(waitForFinish=wait_for_finish),
3939
)
40-
job = pluck_data(response.json())
40+
job = response_to_dict(response)
4141

4242
seconds_elapsed = math.floor((datetime.now(timezone.utc) - started_at).total_seconds())
4343
if ActorJobStatus(job['status']).is_terminal or (
@@ -68,7 +68,7 @@ def _abort(self, *, gracefully: bool | None = None) -> dict:
6868
method='POST',
6969
params=self._params(gracefully=gracefully),
7070
)
71-
return pluck_data(response.json())
71+
return response_to_dict(response)
7272

7373

7474
class ActorJobBaseClientAsync(ResourceClientAsync):
@@ -91,7 +91,7 @@ async def _wait_for_finish(self, wait_secs: int | None = None) -> dict | None:
9191
method='GET',
9292
params=self._params(waitForFinish=wait_for_finish),
9393
)
94-
job = pluck_data(response.json())
94+
job = response_to_dict(response)
9595

9696
seconds_elapsed = math.floor((datetime.now(timezone.utc) - started_at).total_seconds())
9797
if ActorJobStatus(job['status']).is_terminal or (
@@ -122,4 +122,4 @@ async def _abort(self, *, gracefully: bool | None = None) -> dict:
122122
method='POST',
123123
params=self._params(gracefully=gracefully),
124124
)
125-
return pluck_data(response.json())
125+
return response_to_dict(response)

src/apify_client/_resource_clients/base/resource_client.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from apify_client._resource_clients.base.base_client import BaseClient, BaseClientAsync
4-
from apify_client._utils import catch_not_found_or_throw, pluck_data
4+
from apify_client._utils import catch_not_found_or_throw, response_to_dict
55
from apify_client.errors import ApifyApiError
66

77

@@ -16,8 +16,7 @@ def _get(self, timeout_secs: int | None = None) -> dict | None:
1616
params=self._params(),
1717
timeout_secs=timeout_secs,
1818
)
19-
20-
return pluck_data(response.json())
19+
return response_to_dict(response)
2120

2221
except ApifyApiError as exc:
2322
catch_not_found_or_throw(exc)
@@ -33,7 +32,7 @@ def _update(self, updated_fields: dict, timeout_secs: int | None = None) -> dict
3332
timeout_secs=timeout_secs,
3433
)
3534

36-
return pluck_data(response.json())
35+
return response_to_dict(response)
3736

3837
def _delete(self, timeout_secs: int | None = None) -> None:
3938
try:
@@ -60,7 +59,7 @@ async def _get(self, timeout_secs: int | None = None) -> dict | None:
6059
timeout_secs=timeout_secs,
6160
)
6261

63-
return pluck_data(response.json())
62+
return response_to_dict(response)
6463

6564
except ApifyApiError as exc:
6665
catch_not_found_or_throw(exc)
@@ -76,7 +75,7 @@ async def _update(self, updated_fields: dict, timeout_secs: int | None = None) -
7675
timeout_secs=timeout_secs,
7776
)
7877

79-
return pluck_data(response.json())
78+
return response_to_dict(response)
8079

8180
async def _delete(self, timeout_secs: int | None = None) -> None:
8281
try:

src/apify_client/_resource_clients/base/resource_collection_client.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from apify_client._resource_clients.base.base_client import BaseClient, BaseClientAsync
66
from apify_client._types import ListPage
7-
from apify_client._utils import pluck_data
7+
from apify_client._utils import response_to_dict
88

99

1010
class ResourceCollectionClient(BaseClient):
@@ -17,7 +17,8 @@ def _list(self, **kwargs: Any) -> ListPage:
1717
params=self._params(**kwargs),
1818
)
1919

20-
return ListPage(pluck_data(response.json()))
20+
data = response_to_dict(response)
21+
return ListPage(data)
2122

2223
def _create(self, resource: dict) -> dict:
2324
response = self.http_client.call(
@@ -27,7 +28,7 @@ def _create(self, resource: dict) -> dict:
2728
json=resource,
2829
)
2930

30-
return pluck_data(response.json())
31+
return response_to_dict(response)
3132

3233
def _get_or_create(self, name: str | None = None, resource: dict | None = None) -> dict:
3334
response = self.http_client.call(
@@ -37,7 +38,7 @@ def _get_or_create(self, name: str | None = None, resource: dict | None = None)
3738
json=resource,
3839
)
3940

40-
return pluck_data(response.json())
41+
return response_to_dict(response)
4142

4243

4344
class ResourceCollectionClientAsync(BaseClientAsync):
@@ -50,7 +51,8 @@ async def _list(self, **kwargs: Any) -> ListPage:
5051
params=self._params(**kwargs),
5152
)
5253

53-
return ListPage(pluck_data(response.json()))
54+
data = response_to_dict(response)
55+
return ListPage(data)
5456

5557
async def _create(self, resource: dict) -> dict:
5658
response = await self.http_client.call(
@@ -60,7 +62,7 @@ async def _create(self, resource: dict) -> dict:
6062
json=resource,
6163
)
6264

63-
return pluck_data(response.json())
65+
return response_to_dict(response)
6466

6567
async def _get_or_create(
6668
self,
@@ -74,4 +76,4 @@ async def _get_or_create(
7476
json=resource,
7577
)
7678

77-
return pluck_data(response.json())
79+
return response_to_dict(response)

src/apify_client/_resource_clients/dataset.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from apify_client._models import Dataset, GetDatasetStatisticsResponse
1111
from apify_client._resource_clients.base import ResourceClient, ResourceClientAsync
1212
from apify_client._types import ListPage
13-
from apify_client._utils import catch_not_found_or_throw, filter_out_none_values_recursively, pluck_data
13+
from apify_client._utils import catch_not_found_or_throw, filter_out_none_values_recursively, response_to_dict
1414
from apify_client.errors import ApifyApiError
1515

1616
if TYPE_CHECKING:
@@ -142,7 +142,7 @@ def list_items(
142142
params=request_params,
143143
)
144144

145-
data = response.json()
145+
data = response_to_dict(response)
146146

147147
return ListPage(
148148
{
@@ -572,7 +572,7 @@ def get_statistics(self) -> GetDatasetStatisticsResponse | None:
572572
params=self._params(),
573573
timeout_secs=_SMALL_TIMEOUT,
574574
)
575-
result = pluck_data(response.json())
575+
result = response.json()
576576
return GetDatasetStatisticsResponse.model_validate(result) if result is not None else None
577577
except ApifyApiError as exc:
578578
catch_not_found_or_throw(exc)
@@ -758,7 +758,7 @@ async def list_items(
758758
params=request_params,
759759
)
760760

761-
data = response.json()
761+
data = response_to_dict(response)
762762

763763
return ListPage(
764764
{
@@ -1094,7 +1094,7 @@ async def get_statistics(self) -> GetDatasetStatisticsResponse | None:
10941094
params=self._params(),
10951095
timeout_secs=_SMALL_TIMEOUT,
10961096
)
1097-
result = pluck_data(response.json())
1097+
result = response.json()
10981098
return GetDatasetStatisticsResponse.model_validate(result) if result is not None else None
10991099
except ApifyApiError as exc:
11001100
catch_not_found_or_throw(exc)

src/apify_client/_resource_clients/key_value_store.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
encode_key_value_store_record_value,
1515
filter_out_none_values_recursively,
1616
maybe_parse_response,
17-
pluck_data,
1817
)
1918
from apify_client.errors import ApifyApiError
2019

@@ -110,7 +109,7 @@ def list_keys(
110109
timeout_secs=_MEDIUM_TIMEOUT,
111110
)
112111

113-
result = pluck_data(response.json())
112+
result = response.json()
114113
return ListOfKeysResponse.model_validate(result)
115114

116115
def get_record(self, key: str, signature: str | None = None) -> dict | None:
@@ -442,7 +441,7 @@ async def list_keys(
442441
timeout_secs=_MEDIUM_TIMEOUT,
443442
)
444443

445-
result = pluck_data(response.json())
444+
result = response.json()
446445
return ListOfKeysResponse.model_validate(result)
447446

448447
async def get_record(self, key: str, signature: str | None = None) -> dict | None:

0 commit comments

Comments
 (0)