From 15a2d20ab1b7de1c1c3e45a9b7ac719eeb505f2f Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Tue, 20 Feb 2024 16:45:29 +0000 Subject: [PATCH] feat(api): create new sandbox job --- .stats.yml | 2 +- api.md | 10 ++ src/finch/resources/sandbox/jobs/jobs.py | 98 +++++++++++++++++++ src/finch/types/sandbox/__init__.py | 2 + src/finch/types/sandbox/job_create_params.py | 12 +++ .../types/sandbox/job_create_response.py | 19 ++++ tests/api_resources/sandbox/test_jobs.py | 84 ++++++++++++++++ 7 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 src/finch/types/sandbox/job_create_params.py create mode 100644 src/finch/types/sandbox/job_create_response.py create mode 100644 tests/api_resources/sandbox/test_jobs.py diff --git a/.stats.yml b/.stats.yml index 966331a1..397ee0a4 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 34 +configured_endpoints: 35 diff --git a/api.md b/api.md index 21650e84..34051553 100644 --- a/api.md +++ b/api.md @@ -330,6 +330,16 @@ Methods: ## Jobs +Types: + +```python +from finch.types.sandbox import JobCreateResponse +``` + +Methods: + +- client.sandbox.jobs.create(\*\*params) -> JobCreateResponse + ### Configuration Types: diff --git a/src/finch/resources/sandbox/jobs/jobs.py b/src/finch/resources/sandbox/jobs/jobs.py index 916e4057..a65d5bb2 100644 --- a/src/finch/resources/sandbox/jobs/jobs.py +++ b/src/finch/resources/sandbox/jobs/jobs.py @@ -2,8 +2,16 @@ from __future__ import annotations +from typing_extensions import Literal + +import httpx + +from .... import _legacy_response +from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ...._utils import maybe_transform from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource +from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper from .configuration import ( Configuration, AsyncConfiguration, @@ -12,6 +20,10 @@ ConfigurationWithStreamingResponse, AsyncConfigurationWithStreamingResponse, ) +from ...._base_client import ( + make_request_options, +) +from ....types.sandbox import JobCreateResponse, job_create_params __all__ = ["Jobs", "AsyncJobs"] @@ -29,6 +41,41 @@ def with_raw_response(self) -> JobsWithRawResponse: def with_streaming_response(self) -> JobsWithStreamingResponse: return JobsWithStreamingResponse(self) + def create( + self, + *, + type: Literal["data_sync_all"], + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> JobCreateResponse: + """Enqueue a new sandbox job + + Args: + type: The type of job to start. + + Currently the only supported type is `data_sync_all` + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return self._post( + "/sandbox/jobs", + body=maybe_transform({"type": type}, job_create_params.JobCreateParams), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=JobCreateResponse, + ) + class AsyncJobs(AsyncAPIResource): @cached_property @@ -43,11 +90,50 @@ def with_raw_response(self) -> AsyncJobsWithRawResponse: def with_streaming_response(self) -> AsyncJobsWithStreamingResponse: return AsyncJobsWithStreamingResponse(self) + async def create( + self, + *, + type: Literal["data_sync_all"], + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> JobCreateResponse: + """Enqueue a new sandbox job + + Args: + type: The type of job to start. + + Currently the only supported type is `data_sync_all` + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return await self._post( + "/sandbox/jobs", + body=maybe_transform({"type": type}, job_create_params.JobCreateParams), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=JobCreateResponse, + ) + class JobsWithRawResponse: def __init__(self, jobs: Jobs) -> None: self._jobs = jobs + self.create = _legacy_response.to_raw_response_wrapper( + jobs.create, + ) + @cached_property def configuration(self) -> ConfigurationWithRawResponse: return ConfigurationWithRawResponse(self._jobs.configuration) @@ -57,6 +143,10 @@ class AsyncJobsWithRawResponse: def __init__(self, jobs: AsyncJobs) -> None: self._jobs = jobs + self.create = _legacy_response.async_to_raw_response_wrapper( + jobs.create, + ) + @cached_property def configuration(self) -> AsyncConfigurationWithRawResponse: return AsyncConfigurationWithRawResponse(self._jobs.configuration) @@ -66,6 +156,10 @@ class JobsWithStreamingResponse: def __init__(self, jobs: Jobs) -> None: self._jobs = jobs + self.create = to_streamed_response_wrapper( + jobs.create, + ) + @cached_property def configuration(self) -> ConfigurationWithStreamingResponse: return ConfigurationWithStreamingResponse(self._jobs.configuration) @@ -75,6 +169,10 @@ class AsyncJobsWithStreamingResponse: def __init__(self, jobs: AsyncJobs) -> None: self._jobs = jobs + self.create = async_to_streamed_response_wrapper( + jobs.create, + ) + @cached_property def configuration(self) -> AsyncConfigurationWithStreamingResponse: return AsyncConfigurationWithStreamingResponse(self._jobs.configuration) diff --git a/src/finch/types/sandbox/__init__.py b/src/finch/types/sandbox/__init__.py index 74361b09..7a4d41fa 100644 --- a/src/finch/types/sandbox/__init__.py +++ b/src/finch/types/sandbox/__init__.py @@ -2,6 +2,8 @@ from __future__ import annotations +from .job_create_params import JobCreateParams as JobCreateParams +from .job_create_response import JobCreateResponse as JobCreateResponse from .company_update_params import CompanyUpdateParams as CompanyUpdateParams from .payment_create_params import PaymentCreateParams as PaymentCreateParams from .company_update_response import CompanyUpdateResponse as CompanyUpdateResponse diff --git a/src/finch/types/sandbox/job_create_params.py b/src/finch/types/sandbox/job_create_params.py new file mode 100644 index 00000000..a3a89770 --- /dev/null +++ b/src/finch/types/sandbox/job_create_params.py @@ -0,0 +1,12 @@ +# File generated from our OpenAPI spec by Stainless. + +from __future__ import annotations + +from typing_extensions import Literal, Required, TypedDict + +__all__ = ["JobCreateParams"] + + +class JobCreateParams(TypedDict, total=False): + type: Required[Literal["data_sync_all"]] + """The type of job to start. Currently the only supported type is `data_sync_all`""" diff --git a/src/finch/types/sandbox/job_create_response.py b/src/finch/types/sandbox/job_create_response.py new file mode 100644 index 00000000..0832ef7f --- /dev/null +++ b/src/finch/types/sandbox/job_create_response.py @@ -0,0 +1,19 @@ +# File generated from our OpenAPI spec by Stainless. + +from ..._models import BaseModel + +__all__ = ["JobCreateResponse"] + + +class JobCreateResponse(BaseModel): + allowed_refreshes: int + """The number of allowed refreshes per hour (per hour, fixed window)""" + + job_id: str + """The id of the job that has been created.""" + + job_url: str + """The url that can be used to retrieve the job status""" + + remaining_refreshes: int + """The number of remaining refreshes available (per hour, fixed window)""" diff --git a/tests/api_resources/sandbox/test_jobs.py b/tests/api_resources/sandbox/test_jobs.py new file mode 100644 index 00000000..f0db9c28 --- /dev/null +++ b/tests/api_resources/sandbox/test_jobs.py @@ -0,0 +1,84 @@ +# File generated from our OpenAPI spec by Stainless. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from finch import Finch, AsyncFinch +from tests.utils import assert_matches_type +from finch.types.sandbox import JobCreateResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestJobs: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_create(self, client: Finch) -> None: + job = client.sandbox.jobs.create( + type="data_sync_all", + ) + assert_matches_type(JobCreateResponse, job, path=["response"]) + + @parametrize + def test_raw_response_create(self, client: Finch) -> None: + response = client.sandbox.jobs.with_raw_response.create( + type="data_sync_all", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + job = response.parse() + assert_matches_type(JobCreateResponse, job, path=["response"]) + + @parametrize + def test_streaming_response_create(self, client: Finch) -> None: + with client.sandbox.jobs.with_streaming_response.create( + type="data_sync_all", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + job = response.parse() + assert_matches_type(JobCreateResponse, job, path=["response"]) + + assert cast(Any, response.is_closed) is True + + +class TestAsyncJobs: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_create(self, async_client: AsyncFinch) -> None: + job = await async_client.sandbox.jobs.create( + type="data_sync_all", + ) + assert_matches_type(JobCreateResponse, job, path=["response"]) + + @parametrize + async def test_raw_response_create(self, async_client: AsyncFinch) -> None: + response = await async_client.sandbox.jobs.with_raw_response.create( + type="data_sync_all", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + job = response.parse() + assert_matches_type(JobCreateResponse, job, path=["response"]) + + @parametrize + async def test_streaming_response_create(self, async_client: AsyncFinch) -> None: + async with async_client.sandbox.jobs.with_streaming_response.create( + type="data_sync_all", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + job = await response.parse() + assert_matches_type(JobCreateResponse, job, path=["response"]) + + assert cast(Any, response.is_closed) is True