diff --git a/.stats.yml b/.stats.yml index 4b50dee..c040587 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 26 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/open-transit%2Fopen-transit-fbc053e98085f73b2bf9d6a71bd4992c5eec1b582a030fb48b727cc0788ceae7.yml +configured_endpoints: 27 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/open-transit%2Fopen-transit-e4779565160778ba4193bbe8b27556a49f0f8c31ef15ac72c9ee1eb791f92d33.yml diff --git a/api.md b/api.md index 970353f..d53eb6c 100644 --- a/api.md +++ b/api.md @@ -248,3 +248,13 @@ Types: Methods: - client.block.retrieve(blockId) -> BlockRetrieveResponse + +# Shape + +Types: + +- ShapeRetrieveResponse + +Methods: + +- client.shape.retrieve(shapeId) -> ShapeRetrieveResponse diff --git a/src/index.ts b/src/index.ts index fecb8cd..e9e267c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -144,6 +144,7 @@ export class OnebusawaySDK extends Core.APIClient { searchForStop: API.SearchForStop = new API.SearchForStop(this); searchForRoute: API.SearchForRoute = new API.SearchForRoute(this); block: API.Block = new API.Block(this); + shape: API.Shape = new API.Shape(this); protected override defaultQuery(): Core.DefaultQuery | undefined { return { @@ -295,6 +296,9 @@ export namespace OnebusawaySDK { export import Block = API.Block; export import BlockRetrieveResponse = API.BlockRetrieveResponse; + export import Shape = API.Shape; + export import ShapeRetrieveResponse = API.ShapeRetrieveResponse; + export import References = API.References; export import ResponseWrapper = API.ResponseWrapper; } diff --git a/src/resources/index.ts b/src/resources/index.ts index 365c0f8..a66a88d 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -39,6 +39,7 @@ export { SearchForRoute, } from './search-for-route'; export { SearchForStopRetrieveResponse, SearchForStopRetrieveParams, SearchForStop } from './search-for-stop'; +export { ShapeRetrieveResponse, Shape } from './shape'; export { StopIDsForAgencyListResponse, StopIDsForAgency } from './stop-ids-for-agency'; export { StopRetrieveResponse, Stop } from './stop'; export { diff --git a/src/resources/shape.ts b/src/resources/shape.ts new file mode 100644 index 0000000..412c03e --- /dev/null +++ b/src/resources/shape.ts @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../resource'; +import * as Core from '../core'; +import * as ShapeAPI from './shape'; +import * as Shared from './shared'; + +export class Shape extends APIResource { + /** + * Retrieve a shape (the path traveled by a transit vehicle) by ID. + */ + retrieve(shapeId: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.get(`/api/where/shape/${shapeId}.json`, options); + } +} + +export interface ShapeRetrieveResponse extends Shared.ResponseWrapper { + data: ShapeRetrieveResponse.Data; +} + +export namespace ShapeRetrieveResponse { + export interface Data { + entry: Data.Entry; + + references: Shared.References; + } + + export namespace Data { + export interface Entry { + length: number; + + /** + * Encoded polyline format representing the shape of the path + */ + points: string; + + levels?: string; + } + } +} + +export namespace Shape { + export import ShapeRetrieveResponse = ShapeAPI.ShapeRetrieveResponse; +} diff --git a/tests/api-resources/shape.test.ts b/tests/api-resources/shape.test.ts new file mode 100644 index 0000000..93bcb87 --- /dev/null +++ b/tests/api-resources/shape.test.ts @@ -0,0 +1,29 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import OnebusawaySDK from 'onebusaway-sdk'; +import { Response } from 'node-fetch'; + +const client = new OnebusawaySDK({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource shape', () => { + test('retrieve', async () => { + const responsePromise = client.shape.retrieve('shapeID'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('retrieve: request options instead of params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect(client.shape.retrieve('shapeID', { path: '/_stainless_unknown_path' })).rejects.toThrow( + OnebusawaySDK.NotFoundError, + ); + }); +});