From 7ec652f6fa93d09b3c3ccc2009b5de9f2b784738 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Mon, 22 Jul 2024 15:06:09 +0000 Subject: [PATCH] feat(api): OpenAPI spec update via Stainless API --- .stats.yml | 4 +- api.md | 12 ++ src/onebusaway/_client.py | 8 + src/onebusaway/resources/__init__.py | 14 ++ src/onebusaway/resources/stop.py | 141 ++++++++++++++++++ src/onebusaway/types/__init__.py | 1 + .../types/stop_retrieve_response.py | 54 +++++++ tests/api_resources/test_stop.py | 98 ++++++++++++ 8 files changed, 330 insertions(+), 2 deletions(-) create mode 100644 src/onebusaway/resources/stop.py create mode 100644 src/onebusaway/types/stop_retrieve_response.py create mode 100644 tests/api_resources/test_stop.py diff --git a/.stats.yml b/.stats.yml index 74bfdc8..0ee6a7f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 13 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/open-transit%2Fopen-transit-6c051801071707e025c582891048beeb3c06d10d13c852f8401a71604b81ac5d.yml +configured_endpoints: 14 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/open-transit%2Fopen-transit-3a44d3a64c0f613f81e7dd42644c2b2df90e8be20210428450149f771c7f13d8.yml diff --git a/api.md b/api.md index 29c129c..4d50a2d 100644 --- a/api.md +++ b/api.md @@ -76,6 +76,18 @@ Methods: - client.stops_for_route.list(route_id, \*\*params) -> StopsForRouteListResponse +# Stop + +Types: + +```python +from onebusaway.types import StopRetrieveResponse +``` + +Methods: + +- client.stop.retrieve(stop_id) -> StopRetrieveResponse + # Route Types: diff --git a/src/onebusaway/_client.py b/src/onebusaway/_client.py index f75c441..e8ea4d1 100644 --- a/src/onebusaway/_client.py +++ b/src/onebusaway/_client.py @@ -52,6 +52,7 @@ class OnebusawaySDK(SyncAPIClient): current_time: resources.CurrentTimeResource stops_for_location: resources.StopsForLocationResource stops_for_route: resources.StopsForRouteResource + stop: resources.StopResource route: resources.RouteResource arrival_and_departure: resources.ArrivalAndDepartureResource trip: resources.TripResource @@ -121,6 +122,7 @@ def __init__( self.current_time = resources.CurrentTimeResource(self) self.stops_for_location = resources.StopsForLocationResource(self) self.stops_for_route = resources.StopsForRouteResource(self) + self.stop = resources.StopResource(self) self.route = resources.RouteResource(self) self.arrival_and_departure = resources.ArrivalAndDepartureResource(self) self.trip = resources.TripResource(self) @@ -249,6 +251,7 @@ class AsyncOnebusawaySDK(AsyncAPIClient): current_time: resources.AsyncCurrentTimeResource stops_for_location: resources.AsyncStopsForLocationResource stops_for_route: resources.AsyncStopsForRouteResource + stop: resources.AsyncStopResource route: resources.AsyncRouteResource arrival_and_departure: resources.AsyncArrivalAndDepartureResource trip: resources.AsyncTripResource @@ -318,6 +321,7 @@ def __init__( self.current_time = resources.AsyncCurrentTimeResource(self) self.stops_for_location = resources.AsyncStopsForLocationResource(self) self.stops_for_route = resources.AsyncStopsForRouteResource(self) + self.stop = resources.AsyncStopResource(self) self.route = resources.AsyncRouteResource(self) self.arrival_and_departure = resources.AsyncArrivalAndDepartureResource(self) self.trip = resources.AsyncTripResource(self) @@ -449,6 +453,7 @@ def __init__(self, client: OnebusawaySDK) -> None: self.current_time = resources.CurrentTimeResourceWithRawResponse(client.current_time) self.stops_for_location = resources.StopsForLocationResourceWithRawResponse(client.stops_for_location) self.stops_for_route = resources.StopsForRouteResourceWithRawResponse(client.stops_for_route) + self.stop = resources.StopResourceWithRawResponse(client.stop) self.route = resources.RouteResourceWithRawResponse(client.route) self.arrival_and_departure = resources.ArrivalAndDepartureResourceWithRawResponse(client.arrival_and_departure) self.trip = resources.TripResourceWithRawResponse(client.trip) @@ -467,6 +472,7 @@ def __init__(self, client: AsyncOnebusawaySDK) -> None: self.current_time = resources.AsyncCurrentTimeResourceWithRawResponse(client.current_time) self.stops_for_location = resources.AsyncStopsForLocationResourceWithRawResponse(client.stops_for_location) self.stops_for_route = resources.AsyncStopsForRouteResourceWithRawResponse(client.stops_for_route) + self.stop = resources.AsyncStopResourceWithRawResponse(client.stop) self.route = resources.AsyncRouteResourceWithRawResponse(client.route) self.arrival_and_departure = resources.AsyncArrivalAndDepartureResourceWithRawResponse( client.arrival_and_departure @@ -487,6 +493,7 @@ def __init__(self, client: OnebusawaySDK) -> None: self.current_time = resources.CurrentTimeResourceWithStreamingResponse(client.current_time) self.stops_for_location = resources.StopsForLocationResourceWithStreamingResponse(client.stops_for_location) self.stops_for_route = resources.StopsForRouteResourceWithStreamingResponse(client.stops_for_route) + self.stop = resources.StopResourceWithStreamingResponse(client.stop) self.route = resources.RouteResourceWithStreamingResponse(client.route) self.arrival_and_departure = resources.ArrivalAndDepartureResourceWithStreamingResponse( client.arrival_and_departure @@ -509,6 +516,7 @@ def __init__(self, client: AsyncOnebusawaySDK) -> None: client.stops_for_location ) self.stops_for_route = resources.AsyncStopsForRouteResourceWithStreamingResponse(client.stops_for_route) + self.stop = resources.AsyncStopResourceWithStreamingResponse(client.stop) self.route = resources.AsyncRouteResourceWithStreamingResponse(client.route) self.arrival_and_departure = resources.AsyncArrivalAndDepartureResourceWithStreamingResponse( client.arrival_and_departure diff --git a/src/onebusaway/resources/__init__.py b/src/onebusaway/resources/__init__.py index 65b959b..9c3ef40 100644 --- a/src/onebusaway/resources/__init__.py +++ b/src/onebusaway/resources/__init__.py @@ -1,5 +1,13 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +from .stop import ( + StopResource, + AsyncStopResource, + StopResourceWithRawResponse, + AsyncStopResourceWithRawResponse, + StopResourceWithStreamingResponse, + AsyncStopResourceWithStreamingResponse, +) from .trip import ( TripResource, AsyncTripResource, @@ -134,6 +142,12 @@ "AsyncStopsForRouteResourceWithRawResponse", "StopsForRouteResourceWithStreamingResponse", "AsyncStopsForRouteResourceWithStreamingResponse", + "StopResource", + "AsyncStopResource", + "StopResourceWithRawResponse", + "AsyncStopResourceWithRawResponse", + "StopResourceWithStreamingResponse", + "AsyncStopResourceWithStreamingResponse", "RouteResource", "AsyncRouteResource", "RouteResourceWithRawResponse", diff --git a/src/onebusaway/resources/stop.py b/src/onebusaway/resources/stop.py new file mode 100644 index 0000000..e1939d1 --- /dev/null +++ b/src/onebusaway/resources/stop.py @@ -0,0 +1,141 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import httpx + +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from .._compat import cached_property +from .._resource import SyncAPIResource, AsyncAPIResource +from .._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from .._base_client import make_request_options +from ..types.stop_retrieve_response import StopRetrieveResponse + +__all__ = ["StopResource", "AsyncStopResource"] + + +class StopResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> StopResourceWithRawResponse: + return StopResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> StopResourceWithStreamingResponse: + return StopResourceWithStreamingResponse(self) + + def retrieve( + self, + stop_id: str, + *, + # 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, + ) -> StopRetrieveResponse: + """ + Retrieve information for a specific stop identified by its unique ID. + + Args: + 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 + """ + if not stop_id: + raise ValueError(f"Expected a non-empty value for `stop_id` but received {stop_id!r}") + return self._get( + f"/api/where/stop/stopID.json", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=StopRetrieveResponse, + ) + + +class AsyncStopResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncStopResourceWithRawResponse: + return AsyncStopResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncStopResourceWithStreamingResponse: + return AsyncStopResourceWithStreamingResponse(self) + + async def retrieve( + self, + stop_id: str, + *, + # 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, + ) -> StopRetrieveResponse: + """ + Retrieve information for a specific stop identified by its unique ID. + + Args: + 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 + """ + if not stop_id: + raise ValueError(f"Expected a non-empty value for `stop_id` but received {stop_id!r}") + return await self._get( + f"/api/where/stop/stopID.json", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=StopRetrieveResponse, + ) + + +class StopResourceWithRawResponse: + def __init__(self, stop: StopResource) -> None: + self._stop = stop + + self.retrieve = to_raw_response_wrapper( + stop.retrieve, + ) + + +class AsyncStopResourceWithRawResponse: + def __init__(self, stop: AsyncStopResource) -> None: + self._stop = stop + + self.retrieve = async_to_raw_response_wrapper( + stop.retrieve, + ) + + +class StopResourceWithStreamingResponse: + def __init__(self, stop: StopResource) -> None: + self._stop = stop + + self.retrieve = to_streamed_response_wrapper( + stop.retrieve, + ) + + +class AsyncStopResourceWithStreamingResponse: + def __init__(self, stop: AsyncStopResource) -> None: + self._stop = stop + + self.retrieve = async_to_streamed_response_wrapper( + stop.retrieve, + ) diff --git a/src/onebusaway/types/__init__.py b/src/onebusaway/types/__init__.py index 3ea05d3..7a04693 100644 --- a/src/onebusaway/types/__init__.py +++ b/src/onebusaway/types/__init__.py @@ -3,6 +3,7 @@ from __future__ import annotations from .shared import References as References, ResponseWrapper as ResponseWrapper +from .stop_retrieve_response import StopRetrieveResponse as StopRetrieveResponse from .trip_retrieve_response import TripRetrieveResponse as TripRetrieveResponse from .route_retrieve_response import RouteRetrieveResponse as RouteRetrieveResponse from .agency_retrieve_response import AgencyRetrieveResponse as AgencyRetrieveResponse diff --git a/src/onebusaway/types/stop_retrieve_response.py b/src/onebusaway/types/stop_retrieve_response.py new file mode 100644 index 0000000..cfebd4f --- /dev/null +++ b/src/onebusaway/types/stop_retrieve_response.py @@ -0,0 +1,54 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List, Optional + +from pydantic import Field as FieldInfo + +from .._models import BaseModel +from .shared.references import References +from .shared.response_wrapper import ResponseWrapper + +__all__ = [ + "StopRetrieveResponse", + "StopRetrieveResponseData", + "StopRetrieveResponseDataData", + "StopRetrieveResponseDataDataEntry", +] + + +class StopRetrieveResponseDataDataEntry(BaseModel): + id: str + + code: str + + lat: float + + lon: float + + name: str + + direction: Optional[str] = None + + location_type: Optional[int] = FieldInfo(alias="locationType", default=None) + + parent: Optional[str] = None + + route_ids: Optional[List[str]] = FieldInfo(alias="routeIds", default=None) + + static_route_ids: Optional[List[str]] = FieldInfo(alias="staticRouteIds", default=None) + + wheelchair_boarding: Optional[str] = FieldInfo(alias="wheelchairBoarding", default=None) + + +class StopRetrieveResponseDataData(BaseModel): + entry: Optional[StopRetrieveResponseDataDataEntry] = None + + references: Optional[References] = None + + +class StopRetrieveResponseData(BaseModel): + data: Optional[StopRetrieveResponseDataData] = None + + +class StopRetrieveResponse(ResponseWrapper): + data: Optional[StopRetrieveResponseData] = None diff --git a/tests/api_resources/test_stop.py b/tests/api_resources/test_stop.py new file mode 100644 index 0000000..9286176 --- /dev/null +++ b/tests/api_resources/test_stop.py @@ -0,0 +1,98 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from onebusaway import OnebusawaySDK, AsyncOnebusawaySDK +from tests.utils import assert_matches_type +from onebusaway.types import StopRetrieveResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestStop: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_retrieve(self, client: OnebusawaySDK) -> None: + stop = client.stop.retrieve( + "stopID", + ) + assert_matches_type(StopRetrieveResponse, stop, path=["response"]) + + @parametrize + def test_raw_response_retrieve(self, client: OnebusawaySDK) -> None: + response = client.stop.with_raw_response.retrieve( + "stopID", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + stop = response.parse() + assert_matches_type(StopRetrieveResponse, stop, path=["response"]) + + @parametrize + def test_streaming_response_retrieve(self, client: OnebusawaySDK) -> None: + with client.stop.with_streaming_response.retrieve( + "stopID", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + stop = response.parse() + assert_matches_type(StopRetrieveResponse, stop, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_retrieve(self, client: OnebusawaySDK) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `stop_id` but received ''"): + client.stop.with_raw_response.retrieve( + "", + ) + + +class TestAsyncStop: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_retrieve(self, async_client: AsyncOnebusawaySDK) -> None: + stop = await async_client.stop.retrieve( + "stopID", + ) + assert_matches_type(StopRetrieveResponse, stop, path=["response"]) + + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncOnebusawaySDK) -> None: + response = await async_client.stop.with_raw_response.retrieve( + "stopID", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + stop = await response.parse() + assert_matches_type(StopRetrieveResponse, stop, path=["response"]) + + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncOnebusawaySDK) -> None: + async with async_client.stop.with_streaming_response.retrieve( + "stopID", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + stop = await response.parse() + assert_matches_type(StopRetrieveResponse, stop, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_retrieve(self, async_client: AsyncOnebusawaySDK) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `stop_id` but received ''"): + await async_client.stop.with_raw_response.retrieve( + "", + )