Skip to content

Commit 0ecbed2

Browse files
committed
refactor: clean up
1 parent d90ac9e commit 0ecbed2

File tree

6 files changed

+80
-75
lines changed

6 files changed

+80
-75
lines changed

src/apify_client/clients/resource_clients/dataset.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
from typing import TYPE_CHECKING, Any
77
from urllib.parse import urlencode, urlparse, urlunparse
88

9+
from apify_shared.utils import create_storage_content_signature
10+
911
from apify_client._types import ListPage
10-
from apify_client._utils import catch_not_found_or_throw, filter_out_none_values_recursively, pluck_data, create_storage_content_signature
12+
from apify_client._utils import (
13+
catch_not_found_or_throw,
14+
filter_out_none_values_recursively,
15+
pluck_data,
16+
)
1117
from apify_client.clients.base import ResourceClient, ResourceClientAsync
1218
from apify_client.errors import ApifyApiError
1319

@@ -573,15 +579,15 @@ def create_items_public_url(
573579
skip_hidden: bool | None = None,
574580
flatten: list[str] | None = None,
575581
view: str | None = None,
576-
expires_in_millis: int | None = None,
582+
expires_in_seconds: int | None = None,
577583
) -> str:
578584
"""Generate a URL that can be used to access dataset items.
579585
580586
If the client has permission to access the dataset's URL signing key,
581587
the URL will include a signature to verify its authenticity.
582588
583-
You can optionally control how long the signed URL should be valid using the `expires_in_millis` option.
584-
This value sets the expiration duration in milliseconds from the time the URL is generated.
589+
You can optionally control how long the signed URL should be valid using the `expires_in_seconds` option.
590+
This value sets the expiration duration in seconds from the time the URL is generated.
585591
If not provided, the URL will not expire.
586592
587593
Any other options (like `limit` or `offset`) will be included as query parameters in the URL.
@@ -609,7 +615,7 @@ def create_items_public_url(
609615
signature = create_storage_content_signature(
610616
resource_id=dataset['id'],
611617
url_signing_secret_key=dataset['urlSigningSecretKey'],
612-
expires_in_millis=expires_in_millis,
618+
expires_in_millis=expires_in_seconds * 1000 if expires_in_seconds is not None else None,
613619
)
614620
request_params['signature'] = signature
615621

@@ -1080,15 +1086,15 @@ async def create_items_public_url(
10801086
skip_hidden: bool | None = None,
10811087
flatten: list[str] | None = None,
10821088
view: str | None = None,
1083-
expires_in_millis: int | None = None,
1089+
expires_in_seconds: int | None = None,
10841090
) -> str:
10851091
"""Generate a URL that can be used to access dataset items.
10861092
10871093
If the client has permission to access the dataset's URL signing key,
10881094
the URL will include a signature to verify its authenticity.
10891095
1090-
You can optionally control how long the signed URL should be valid using the `expires_in_millis` option.
1091-
This value sets the expiration duration in milliseconds from the time the URL is generated.
1096+
You can optionally control how long the signed URL should be valid using the `expires_in_seconds` option.
1097+
This value sets the expiration duration in seconds from the time the URL is generated.
10921098
If not provided, the URL will not expire.
10931099
10941100
Any other options (like `limit` or `offset`) will be included as query parameters in the URL.
@@ -1116,7 +1122,7 @@ async def create_items_public_url(
11161122
signature = create_storage_content_signature(
11171123
resource_id=dataset['id'],
11181124
url_signing_secret_key=dataset['urlSigningSecretKey'],
1119-
expires_in_millis=expires_in_millis,
1125+
expires_in_millis=expires_in_seconds * 1000 if expires_in_seconds is not None else None,
11201126
)
11211127
request_params['signature'] = signature
11221128

src/apify_client/clients/resource_clients/key_value_store.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
from typing import TYPE_CHECKING, Any
77
from urllib.parse import urlencode, urlparse, urlunparse
88

9-
from apify_shared.utils import (
10-
create_storage_content_signature,
11-
filter_out_none_values_recursively,
12-
ignore_docs,
13-
parse_date_fields,
14-
)
9+
from apify_shared.utils import create_storage_content_signature
1510

1611
from apify_client._utils import (
1712
catch_not_found_or_throw,
@@ -279,15 +274,15 @@ def create_keys_public_url(
279274
exclusive_start_key: str | None = None,
280275
collection: str | None = None,
281276
prefix: str | None = None,
282-
expires_in_millis: int | None = None,
277+
expires_in_seconds: int | None = None,
283278
) -> str:
284279
"""Generate a URL that can be used to access key-value store keys.
285280
286281
If the client has permission to access the key-value store's URL signing key,
287282
the URL will include a signature to verify its authenticity.
288283
289-
You can optionally control how long the signed URL should be valid using the `expires_in_millis` option.
290-
This value sets the expiration duration in milliseconds from the time the URL is generated.
284+
You can optionally control how long the signed URL should be valid using the `expires_in_seconds` option.
285+
This value sets the expiration duration in seconds from the time the URL is generated.
291286
If not provided, the URL will not expire.
292287
293288
Any other options (like `limit` or `prefix`) will be included as query parameters in the URL.
@@ -308,7 +303,7 @@ def create_keys_public_url(
308303
signature = create_storage_content_signature(
309304
resource_id=store['id'],
310305
url_signing_secret_key=store['urlSigningSecretKey'],
311-
expires_in_millis=expires_in_millis,
306+
expires_in_millis=expires_in_seconds * 1000 if expires_in_seconds is not None else None,
312307
)
313308
request_params['signature'] = signature
314309

@@ -567,15 +562,15 @@ async def create_keys_public_url(
567562
exclusive_start_key: str | None = None,
568563
collection: str | None = None,
569564
prefix: str | None = None,
570-
expires_in_millis: int | None = None,
565+
expires_in_seconds: int | None = None,
571566
) -> str:
572567
"""Generate a URL that can be used to access key-value store keys.
573568
574569
If the client has permission to access the key-value store's URL signing key,
575570
the URL will include a signature to verify its authenticity.
576571
577-
You can optionally control how long the signed URL should be valid using the `expires_in_millis` option.
578-
This value sets the expiration duration in milliseconds from the time the URL is generated.
572+
You can optionally control how long the signed URL should be valid using the `expires_in_seconds` option.
573+
This value sets the expiration duration in seconds from the time the URL is generated.
579574
If not provided, the URL will not expire.
580575
581576
Any other options (like `limit` or `prefix`) will be included as query parameters in the URL.
@@ -598,7 +593,7 @@ async def create_keys_public_url(
598593
signature = create_storage_content_signature(
599594
resource_id=store['id'],
600595
url_signing_secret_key=store['urlSigningSecretKey'],
601-
expires_in_millis=expires_in_millis,
596+
expires_in_millis=expires_in_seconds * 1000 if expires_in_seconds is not None else None,
602597
)
603598
request_params['signature'] = signature
604599

tests/integration/test_dataset.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
from typing import TYPE_CHECKING
44

5-
import httpx
6-
from integration_test_utils import random_resource_name
5+
import impit
6+
7+
from integration.integration_test_utils import random_resource_name
78

89
if TYPE_CHECKING:
910
from apify_client import ApifyClient, ApifyClientAsync
@@ -15,7 +16,7 @@ def test_dataset_should_create_public_items_expiring_url_with_params(self, apify
1516

1617
dataset = apify_client.dataset(created_dataset['id'])
1718
items_public_url = dataset.create_items_public_url(
18-
expires_in_millis=2000,
19+
expires_in_seconds=2000,
1920
limit=10,
2021
offset=0,
2122
)
@@ -24,8 +25,8 @@ def test_dataset_should_create_public_items_expiring_url_with_params(self, apify
2425
assert 'limit=10' in items_public_url
2526
assert 'offset=0' in items_public_url
2627

27-
httpx_client = httpx.Client()
28-
response = httpx_client.get(items_public_url, timeout=5)
28+
impit_client = impit.Client()
29+
response = impit_client.get(items_public_url, timeout=5)
2930
assert response.status_code == 200
3031

3132
dataset.delete()
@@ -39,8 +40,8 @@ def test_dataset_should_create_public_items_non_expiring_url(self, apify_client:
3940

4041
assert 'signature=' in items_public_url
4142

42-
httpx_client = httpx.Client()
43-
response = httpx_client.get(items_public_url, timeout=5)
43+
impit_client = impit.Client()
44+
response = impit_client.get(items_public_url, timeout=5)
4445
assert response.status_code == 200
4546

4647
dataset.delete()
@@ -55,7 +56,7 @@ async def test_dataset_should_create_public_items_expiring_url_with_params(
5556

5657
dataset = apify_client_async.dataset(created_dataset['id'])
5758
items_public_url = await dataset.create_items_public_url(
58-
expires_in_millis=2000,
59+
expires_in_seconds=2000,
5960
limit=10,
6061
offset=0,
6162
)
@@ -64,8 +65,8 @@ async def test_dataset_should_create_public_items_expiring_url_with_params(
6465
assert 'limit=10' in items_public_url
6566
assert 'offset=0' in items_public_url
6667

67-
httpx_async_client = httpx.AsyncClient()
68-
response = await httpx_async_client.get(items_public_url, timeout=5)
68+
impit_async_client = impit.AsyncClient()
69+
response = await impit_async_client.get(items_public_url, timeout=5)
6970
assert response.status_code == 200
7071

7172
await dataset.delete()
@@ -81,8 +82,8 @@ async def test_dataset_should_create_public_items_non_expiring_url(
8182

8283
assert 'signature=' in items_public_url
8384

84-
httpx_async_client = httpx.AsyncClient()
85-
response = await httpx_async_client.get(items_public_url, timeout=5)
85+
impit_async_client = impit.AsyncClient()
86+
response = await impit_async_client.get(items_public_url, timeout=5)
8687
assert response.status_code == 200
8788

8889
await dataset.delete()

tests/integration/test_key_value_store.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
from typing import TYPE_CHECKING
44

5-
import httpx
6-
from integration_test_utils import random_resource_name
5+
import impit
6+
7+
from integration.integration_test_utils import random_resource_name
78

89
if TYPE_CHECKING:
910
from apify_client import ApifyClient, ApifyClientAsync
@@ -17,15 +18,15 @@ def test_key_value_store_should_create_expiring_keys_public_url_with_params(
1718

1819
store = apify_client.key_value_store(created_store['id'])
1920
keys_public_url = store.create_keys_public_url(
20-
expires_in_millis=2000,
21+
expires_in_seconds=2000,
2122
limit=10,
2223
)
2324

2425
assert 'signature=' in keys_public_url
2526
assert 'limit=10' in keys_public_url
2627

27-
httpx_client = httpx.Client()
28-
response = httpx_client.get(keys_public_url, timeout=5)
28+
impit_client = impit.Client()
29+
response = impit_client.get(keys_public_url, timeout=5)
2930
assert response.status_code == 200
3031

3132
store.delete()
@@ -39,8 +40,8 @@ def test_key_value_store_should_create_public_keys_non_expiring_url(self, apify_
3940

4041
assert 'signature=' in keys_public_url
4142

42-
httpx_client = httpx.Client()
43-
response = httpx_client.get(keys_public_url, timeout=5)
43+
impit_client = impit.Client()
44+
response = impit_client.get(keys_public_url, timeout=5)
4445
assert response.status_code == 200
4546

4647
store.delete()
@@ -57,15 +58,15 @@ async def test_key_value_store_should_create_expiring_keys_public_url_with_param
5758

5859
store = apify_client_async.key_value_store(created_store['id'])
5960
keys_public_url = await store.create_keys_public_url(
60-
expires_in_millis=2000,
61+
expires_in_seconds=2000,
6162
limit=10,
6263
)
6364

6465
assert 'signature=' in keys_public_url
6566
assert 'limit=10' in keys_public_url
6667

67-
httpx_async_client = httpx.AsyncClient()
68-
response = await httpx_async_client.get(keys_public_url, timeout=5)
68+
impit_async_client = impit.AsyncClient()
69+
response = await impit_async_client.get(keys_public_url, timeout=5)
6970
assert response.status_code == 200
7071

7172
await store.delete()
@@ -83,8 +84,8 @@ async def test_key_value_store_should_create_public_keys_non_expiring_url(
8384

8485
assert 'signature=' in keys_public_url
8586

86-
httpx_async_client = httpx.AsyncClient()
87-
response = await httpx_async_client.get(keys_public_url, timeout=5)
87+
impit_async_client = impit.AsyncClient()
88+
response = await impit_async_client.get(keys_public_url, timeout=5)
8889
assert response.status_code == 200
8990

9091
await store.delete()

tests/integration/test_request_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import TYPE_CHECKING
44

5-
from integration_test_utils import random_resource_name, random_string
5+
from integration.integration_test_utils import random_resource_name, random_string
66

77
if TYPE_CHECKING:
88
from apify_client import ApifyClient, ApifyClientAsync

0 commit comments

Comments
 (0)