Skip to content

Commit c04d762

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(urlscanner): swap to v2 create (#2225)
1 parent 2cad4a0 commit c04d762

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6522,7 +6522,7 @@ from cloudflare.types.url_scanner import (
65226522

65236523
Methods:
65246524

6525-
- <code title="post /accounts/{accountId}/urlscanner/scan">client.url_scanner.scans.<a href="./src/cloudflare/resources/url_scanner/scans.py">create</a>(account_id, \*\*<a href="src/cloudflare/types/url_scanner/scan_create_params.py">params</a>) -> <a href="./src/cloudflare/types/url_scanner/scan_create_response.py">ScanCreateResponse</a></code>
6525+
- <code title="post /accounts/{accountId}/urlscanner/v2/scan">client.url_scanner.scans.<a href="./src/cloudflare/resources/url_scanner/scans.py">create</a>(account_id, \*\*<a href="src/cloudflare/types/url_scanner/scan_create_params.py">params</a>) -> <a href="./src/cloudflare/types/url_scanner/scan_create_response.py">str</a></code>
65266526
- <code title="get /accounts/{accountId}/urlscanner/scan">client.url_scanner.scans.<a href="./src/cloudflare/resources/url_scanner/scans.py">list</a>(account_id, \*\*<a href="src/cloudflare/types/url_scanner/scan_list_params.py">params</a>) -> <a href="./src/cloudflare/types/url_scanner/scan_list_response.py">ScanListResponse</a></code>
65276527
- <code title="get /accounts/{accountId}/urlscanner/scan/{scanId}">client.url_scanner.scans.<a href="./src/cloudflare/resources/url_scanner/scans.py">get</a>(scan_id, \*, account_id, \*\*<a href="src/cloudflare/types/url_scanner/scan_get_params.py">params</a>) -> <a href="./src/cloudflare/types/url_scanner/scan_get_response.py">ScanGetResponse</a></code>
65286528
- <code title="get /accounts/{accountId}/urlscanner/scan/{scanId}/har">client.url_scanner.scans.<a href="./src/cloudflare/resources/url_scanner/scans.py">har</a>(scan_id, \*, account_id) -> <a href="./src/cloudflare/types/url_scanner/scan_har_response.py">ScanHARResponse</a></code>

src/cloudflare/resources/url_scanner/scans.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def create(
6565
account_id: str,
6666
*,
6767
url: str,
68+
customagent: str | NotGiven = NOT_GIVEN,
6869
custom_headers: Dict[str, str] | NotGiven = NOT_GIVEN,
70+
referer: str | NotGiven = NOT_GIVEN,
6971
screenshots_resolutions: List[Literal["desktop", "mobile", "tablet"]] | NotGiven = NOT_GIVEN,
7072
visibility: Literal["Public", "Unlisted"] | NotGiven = NOT_GIVEN,
7173
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -74,11 +76,10 @@ def create(
7476
extra_query: Query | None = None,
7577
extra_body: Body | None = None,
7678
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
77-
) -> ScanCreateResponse:
79+
) -> str:
7880
"""Submit a URL to scan.
7981
80-
You can also set some options, like the visibility level
81-
and custom headers. Check limits at
82+
Check limits at
8283
https://developers.cloudflare.com/security-center/investigate/scan-limits/.
8384
8485
Args:
@@ -105,11 +106,13 @@ def create(
105106
if not account_id:
106107
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
107108
return self._post(
108-
f"/accounts/{account_id}/urlscanner/scan",
109+
f"/accounts/{account_id}/urlscanner/v2/scan",
109110
body=maybe_transform(
110111
{
111112
"url": url,
113+
"customagent": customagent,
112114
"custom_headers": custom_headers,
115+
"referer": referer,
113116
"screenshots_resolutions": screenshots_resolutions,
114117
"visibility": visibility,
115118
},
@@ -122,7 +125,7 @@ def create(
122125
timeout=timeout,
123126
post_parser=ResultWrapper[ScanCreateResponse]._unwrapper,
124127
),
125-
cast_to=cast(Type[ScanCreateResponse], ResultWrapper[ScanCreateResponse]),
128+
cast_to=cast(Type[str], ResultWrapper[str]),
126129
)
127130

128131
def list(
@@ -415,7 +418,9 @@ async def create(
415418
account_id: str,
416419
*,
417420
url: str,
421+
customagent: str | NotGiven = NOT_GIVEN,
418422
custom_headers: Dict[str, str] | NotGiven = NOT_GIVEN,
423+
referer: str | NotGiven = NOT_GIVEN,
419424
screenshots_resolutions: List[Literal["desktop", "mobile", "tablet"]] | NotGiven = NOT_GIVEN,
420425
visibility: Literal["Public", "Unlisted"] | NotGiven = NOT_GIVEN,
421426
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -424,11 +429,10 @@ async def create(
424429
extra_query: Query | None = None,
425430
extra_body: Body | None = None,
426431
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
427-
) -> ScanCreateResponse:
432+
) -> str:
428433
"""Submit a URL to scan.
429434
430-
You can also set some options, like the visibility level
431-
and custom headers. Check limits at
435+
Check limits at
432436
https://developers.cloudflare.com/security-center/investigate/scan-limits/.
433437
434438
Args:
@@ -455,11 +459,13 @@ async def create(
455459
if not account_id:
456460
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
457461
return await self._post(
458-
f"/accounts/{account_id}/urlscanner/scan",
462+
f"/accounts/{account_id}/urlscanner/v2/scan",
459463
body=await async_maybe_transform(
460464
{
461465
"url": url,
466+
"customagent": customagent,
462467
"custom_headers": custom_headers,
468+
"referer": referer,
463469
"screenshots_resolutions": screenshots_resolutions,
464470
"visibility": visibility,
465471
},
@@ -472,7 +478,7 @@ async def create(
472478
timeout=timeout,
473479
post_parser=ResultWrapper[ScanCreateResponse]._unwrapper,
474480
),
475-
cast_to=cast(Type[ScanCreateResponse], ResultWrapper[ScanCreateResponse]),
481+
cast_to=cast(Type[str], ResultWrapper[str]),
476482
)
477483

478484
async def list(

src/cloudflare/types/url_scanner/scan_create_params.py

+4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
class ScanCreateParams(TypedDict, total=False):
1414
url: Required[str]
1515

16+
customagent: str
17+
1618
custom_headers: Annotated[Dict[str, str], PropertyInfo(alias="customHeaders")]
1719
"""Set custom headers."""
1820

21+
referer: str
22+
1923
screenshots_resolutions: Annotated[
2024
List[Literal["desktop", "mobile", "tablet"]], PropertyInfo(alias="screenshotsResolutions")
2125
]
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
from datetime import datetime
4-
5-
from ..._models import BaseModel
3+
from typing_extensions import TypeAlias
64

75
__all__ = ["ScanCreateResponse"]
86

9-
10-
class ScanCreateResponse(BaseModel):
11-
time: datetime
12-
"""Time when url was submitted for scanning."""
13-
14-
url: str
15-
"""Canonical form of submitted URL. Use this if you want to later search by URL."""
16-
17-
uuid: str
18-
"""Scan ID."""
19-
20-
visibility: str
21-
"""Submitted visibility status."""
7+
ScanCreateResponse: TypeAlias = str

tests/api_resources/url_scanner/test_scans.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
ScanGetResponse,
2323
ScanHARResponse,
2424
ScanListResponse,
25-
ScanCreateResponse,
2625
)
2726

2827
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
@@ -37,18 +36,20 @@ def test_method_create(self, client: Cloudflare) -> None:
3736
account_id="accountId",
3837
url="https://www.example.com",
3938
)
40-
assert_matches_type(ScanCreateResponse, scan, path=["response"])
39+
assert_matches_type(str, scan, path=["response"])
4140

4241
@parametrize
4342
def test_method_create_with_all_params(self, client: Cloudflare) -> None:
4443
scan = client.url_scanner.scans.create(
4544
account_id="accountId",
4645
url="https://www.example.com",
46+
customagent="customagent",
4747
custom_headers={"foo": "string"},
48+
referer="referer",
4849
screenshots_resolutions=["desktop"],
4950
visibility="Public",
5051
)
51-
assert_matches_type(ScanCreateResponse, scan, path=["response"])
52+
assert_matches_type(str, scan, path=["response"])
5253

5354
@parametrize
5455
def test_raw_response_create(self, client: Cloudflare) -> None:
@@ -60,7 +61,7 @@ def test_raw_response_create(self, client: Cloudflare) -> None:
6061
assert response.is_closed is True
6162
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
6263
scan = response.parse()
63-
assert_matches_type(ScanCreateResponse, scan, path=["response"])
64+
assert_matches_type(str, scan, path=["response"])
6465

6566
@parametrize
6667
def test_streaming_response_create(self, client: Cloudflare) -> None:
@@ -72,7 +73,7 @@ def test_streaming_response_create(self, client: Cloudflare) -> None:
7273
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
7374

7475
scan = response.parse()
75-
assert_matches_type(ScanCreateResponse, scan, path=["response"])
76+
assert_matches_type(str, scan, path=["response"])
7677

7778
assert cast(Any, response.is_closed) is True
7879

@@ -344,18 +345,20 @@ async def test_method_create(self, async_client: AsyncCloudflare) -> None:
344345
account_id="accountId",
345346
url="https://www.example.com",
346347
)
347-
assert_matches_type(ScanCreateResponse, scan, path=["response"])
348+
assert_matches_type(str, scan, path=["response"])
348349

349350
@parametrize
350351
async def test_method_create_with_all_params(self, async_client: AsyncCloudflare) -> None:
351352
scan = await async_client.url_scanner.scans.create(
352353
account_id="accountId",
353354
url="https://www.example.com",
355+
customagent="customagent",
354356
custom_headers={"foo": "string"},
357+
referer="referer",
355358
screenshots_resolutions=["desktop"],
356359
visibility="Public",
357360
)
358-
assert_matches_type(ScanCreateResponse, scan, path=["response"])
361+
assert_matches_type(str, scan, path=["response"])
359362

360363
@parametrize
361364
async def test_raw_response_create(self, async_client: AsyncCloudflare) -> None:
@@ -367,7 +370,7 @@ async def test_raw_response_create(self, async_client: AsyncCloudflare) -> None:
367370
assert response.is_closed is True
368371
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
369372
scan = await response.parse()
370-
assert_matches_type(ScanCreateResponse, scan, path=["response"])
373+
assert_matches_type(str, scan, path=["response"])
371374

372375
@parametrize
373376
async def test_streaming_response_create(self, async_client: AsyncCloudflare) -> None:
@@ -379,7 +382,7 @@ async def test_streaming_response_create(self, async_client: AsyncCloudflare) ->
379382
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
380383

381384
scan = await response.parse()
382-
assert_matches_type(ScanCreateResponse, scan, path=["response"])
385+
assert_matches_type(str, scan, path=["response"])
383386

384387
assert cast(Any, response.is_closed) is True
385388

0 commit comments

Comments
 (0)