diff --git a/README.md b/README.md index 921b110..07dc16d 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ const client = new OnebusawaySDK({ }); async function main() { - const currentTimeRetrieveResponse = await onebusawaySDK.currentTime.retrieve(); + const currentTimeRetrieveResponse = await client.currentTime.retrieve(); } main(); @@ -47,7 +47,7 @@ const client = new OnebusawaySDK({ async function main() { const currentTimeRetrieveResponse: OnebusawaySDK.CurrentTimeRetrieveResponse = - await onebusawaySDK.currentTime.retrieve(); + await client.currentTime.retrieve(); } main(); @@ -64,7 +64,7 @@ a subclass of `APIError` will be thrown: ```ts async function main() { - const currentTimeRetrieveResponse = await onebusawaySDK.currentTime.retrieve().catch(async (err) => { + const currentTimeRetrieveResponse = await client.currentTime.retrieve().catch(async (err) => { if (err instanceof OnebusawaySDK.APIError) { console.log(err.status); // 400 console.log(err.name); // BadRequestError @@ -107,7 +107,7 @@ const client = new OnebusawaySDK({ }); // Or, configure per-request: -await onebusawaySDK.currentTime.retrieve({ +await client.currentTime.retrieve({ maxRetries: 5, }); ``` @@ -124,7 +124,7 @@ const client = new OnebusawaySDK({ }); // Override per-request: -await onebusawaySDK.currentTime.retrieve({ +await client.currentTime.retrieve({ timeout: 5 * 1000, }); ``` @@ -145,11 +145,11 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi ```ts const client = new OnebusawaySDK(); -const response = await onebusawaySDK.currentTime.retrieve().asResponse(); +const response = await client.currentTime.retrieve().asResponse(); console.log(response.headers.get('X-My-Header')); console.log(response.statusText); // access the underlying Response object -const { data: currentTimeRetrieveResponse, response: raw } = await onebusawaySDK.currentTime +const { data: currentTimeRetrieveResponse, response: raw } = await client.currentTime .retrieve() .withResponse(); console.log(raw.headers.get('X-My-Header')); @@ -257,7 +257,7 @@ const client = new OnebusawaySDK({ }); // Override per-request: -await onebusawaySDK.currentTime.retrieve({ +await client.currentTime.retrieve({ httpAgent: new http.Agent({ keepAlive: false }), }); ``` diff --git a/tests/api-resources/agencies-with-coverage.test.ts b/tests/api-resources/agencies-with-coverage.test.ts index aaccfb6..38c9430 100644 --- a/tests/api-resources/agencies-with-coverage.test.ts +++ b/tests/api-resources/agencies-with-coverage.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource agenciesWithCoverage', () => { test('retrieve', async () => { - const responsePromise = onebusawaySDK.agenciesWithCoverage.retrieve(); + const responsePromise = client.agenciesWithCoverage.retrieve(); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -22,8 +22,8 @@ describe('resource agenciesWithCoverage', () => { 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( - onebusawaySDK.agenciesWithCoverage.retrieve({ path: '/_stainless_unknown_path' }), - ).rejects.toThrow(OnebusawaySDK.NotFoundError); + await expect(client.agenciesWithCoverage.retrieve({ path: '/_stainless_unknown_path' })).rejects.toThrow( + OnebusawaySDK.NotFoundError, + ); }); }); diff --git a/tests/api-resources/agency.test.ts b/tests/api-resources/agency.test.ts index cf6dfac..d001bc8 100644 --- a/tests/api-resources/agency.test.ts +++ b/tests/api-resources/agency.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource agency', () => { test('retrieve', async () => { - const responsePromise = onebusawaySDK.agency.retrieve('agencyID'); + const responsePromise = client.agency.retrieve('agencyID'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -22,8 +22,8 @@ describe('resource agency', () => { 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( - onebusawaySDK.agency.retrieve('agencyID', { path: '/_stainless_unknown_path' }), - ).rejects.toThrow(OnebusawaySDK.NotFoundError); + await expect(client.agency.retrieve('agencyID', { path: '/_stainless_unknown_path' })).rejects.toThrow( + OnebusawaySDK.NotFoundError, + ); }); }); diff --git a/tests/api-resources/arrival-and-departure.test.ts b/tests/api-resources/arrival-and-departure.test.ts index b317841..0664238 100644 --- a/tests/api-resources/arrival-and-departure.test.ts +++ b/tests/api-resources/arrival-and-departure.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource arrivalAndDeparture', () => { test('retrieve: only required params', async () => { - const responsePromise = onebusawaySDK.arrivalAndDeparture.retrieve('1_75403', { + const responsePromise = client.arrivalAndDeparture.retrieve('1_75403', { serviceDate: 0, tripId: 'tripId', }); @@ -24,7 +24,7 @@ describe('resource arrivalAndDeparture', () => { }); test('retrieve: required and optional params', async () => { - const response = await onebusawaySDK.arrivalAndDeparture.retrieve('1_75403', { + const response = await client.arrivalAndDeparture.retrieve('1_75403', { serviceDate: 0, tripId: 'tripId', stopSequence: 0, @@ -34,7 +34,7 @@ describe('resource arrivalAndDeparture', () => { }); test('list', async () => { - const responsePromise = onebusawaySDK.arrivalAndDeparture.list('1_75403'); + const responsePromise = client.arrivalAndDeparture.list('1_75403'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -47,14 +47,14 @@ describe('resource arrivalAndDeparture', () => { test('list: 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( - onebusawaySDK.arrivalAndDeparture.list('1_75403', { path: '/_stainless_unknown_path' }), + client.arrivalAndDeparture.list('1_75403', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OnebusawaySDK.NotFoundError); }); test('list: request options and 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( - onebusawaySDK.arrivalAndDeparture.list( + client.arrivalAndDeparture.list( '1_75403', { minutesAfter: 0, minutesBefore: 0, time: '2019-12-27T18:11:19.117Z' }, { path: '/_stainless_unknown_path' }, diff --git a/tests/api-resources/config.test.ts b/tests/api-resources/config.test.ts index 22af654..b56fd4b 100644 --- a/tests/api-resources/config.test.ts +++ b/tests/api-resources/config.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource config', () => { test('retrieve', async () => { - const responsePromise = onebusawaySDK.config.retrieve(); + const responsePromise = client.config.retrieve(); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -22,7 +22,7 @@ describe('resource config', () => { 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(onebusawaySDK.config.retrieve({ path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.config.retrieve({ path: '/_stainless_unknown_path' })).rejects.toThrow( OnebusawaySDK.NotFoundError, ); }); diff --git a/tests/api-resources/current-time.test.ts b/tests/api-resources/current-time.test.ts index 6c862f6..7e1e2f5 100644 --- a/tests/api-resources/current-time.test.ts +++ b/tests/api-resources/current-time.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource currentTime', () => { test('retrieve', async () => { - const responsePromise = onebusawaySDK.currentTime.retrieve(); + const responsePromise = client.currentTime.retrieve(); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -22,7 +22,7 @@ describe('resource currentTime', () => { 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(onebusawaySDK.currentTime.retrieve({ path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.currentTime.retrieve({ path: '/_stainless_unknown_path' })).rejects.toThrow( OnebusawaySDK.NotFoundError, ); }); diff --git a/tests/api-resources/route.test.ts b/tests/api-resources/route.test.ts index b203514..6a7c2df 100644 --- a/tests/api-resources/route.test.ts +++ b/tests/api-resources/route.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource route', () => { test('retrieve', async () => { - const responsePromise = onebusawaySDK.route.retrieve('routeID'); + const responsePromise = client.route.retrieve('routeID'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -22,8 +22,8 @@ describe('resource route', () => { 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( - onebusawaySDK.route.retrieve('routeID', { path: '/_stainless_unknown_path' }), - ).rejects.toThrow(OnebusawaySDK.NotFoundError); + await expect(client.route.retrieve('routeID', { path: '/_stainless_unknown_path' })).rejects.toThrow( + OnebusawaySDK.NotFoundError, + ); }); }); diff --git a/tests/api-resources/stop.test.ts b/tests/api-resources/stop.test.ts index 74c11a7..7b2c96b 100644 --- a/tests/api-resources/stop.test.ts +++ b/tests/api-resources/stop.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource stop', () => { test('retrieve', async () => { - const responsePromise = onebusawaySDK.stop.retrieve('stopID'); + const responsePromise = client.stop.retrieve('stopID'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -22,7 +22,7 @@ describe('resource stop', () => { 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(onebusawaySDK.stop.retrieve('stopID', { path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.stop.retrieve('stopID', { path: '/_stainless_unknown_path' })).rejects.toThrow( OnebusawaySDK.NotFoundError, ); }); diff --git a/tests/api-resources/stops-for-location.test.ts b/tests/api-resources/stops-for-location.test.ts index 7ba98e5..f2c8ed3 100644 --- a/tests/api-resources/stops-for-location.test.ts +++ b/tests/api-resources/stops-for-location.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource stopsForLocation', () => { test('retrieve: only required params', async () => { - const responsePromise = onebusawaySDK.stopsForLocation.retrieve({ key: 'key' }); + const responsePromise = client.stopsForLocation.retrieve({ key: 'key' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -21,6 +21,6 @@ describe('resource stopsForLocation', () => { }); test('retrieve: required and optional params', async () => { - const response = await onebusawaySDK.stopsForLocation.retrieve({ key: 'key', lat: 0, lon: 0 }); + const response = await client.stopsForLocation.retrieve({ key: 'key', lat: 0, lon: 0 }); }); }); diff --git a/tests/api-resources/stops-for-route.test.ts b/tests/api-resources/stops-for-route.test.ts index c4bce6b..b9fe515 100644 --- a/tests/api-resources/stops-for-route.test.ts +++ b/tests/api-resources/stops-for-route.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource stopsForRoute', () => { test('list', async () => { - const responsePromise = onebusawaySDK.stopsForRoute.list('routeID'); + const responsePromise = client.stopsForRoute.list('routeID'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -22,15 +22,15 @@ describe('resource stopsForRoute', () => { test('list: 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( - onebusawaySDK.stopsForRoute.list('routeID', { path: '/_stainless_unknown_path' }), - ).rejects.toThrow(OnebusawaySDK.NotFoundError); + await expect(client.stopsForRoute.list('routeID', { path: '/_stainless_unknown_path' })).rejects.toThrow( + OnebusawaySDK.NotFoundError, + ); }); test('list: request options and 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( - onebusawaySDK.stopsForRoute.list( + client.stopsForRoute.list( 'routeID', { includePolylines: true, time: 'time' }, { path: '/_stainless_unknown_path' }, diff --git a/tests/api-resources/trip-details.test.ts b/tests/api-resources/trip-details.test.ts index dfaa52e..bc9695b 100644 --- a/tests/api-resources/trip-details.test.ts +++ b/tests/api-resources/trip-details.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource tripDetails', () => { test('retrieve', async () => { - const responsePromise = onebusawaySDK.tripDetails.retrieve('tripID'); + const responsePromise = client.tripDetails.retrieve('tripID'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -22,15 +22,15 @@ describe('resource tripDetails', () => { 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( - onebusawaySDK.tripDetails.retrieve('tripID', { path: '/_stainless_unknown_path' }), - ).rejects.toThrow(OnebusawaySDK.NotFoundError); + await expect(client.tripDetails.retrieve('tripID', { path: '/_stainless_unknown_path' })).rejects.toThrow( + OnebusawaySDK.NotFoundError, + ); }); test('retrieve: request options and 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( - onebusawaySDK.tripDetails.retrieve( + client.tripDetails.retrieve( 'tripID', { includeSchedule: true, includeStatus: true, includeTrip: true, serviceDate: 0, time: 0 }, { path: '/_stainless_unknown_path' }, diff --git a/tests/api-resources/trip-for-vehicle.test.ts b/tests/api-resources/trip-for-vehicle.test.ts index c6818ae..f203f75 100644 --- a/tests/api-resources/trip-for-vehicle.test.ts +++ b/tests/api-resources/trip-for-vehicle.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource tripForVehicle', () => { test('retrieve', async () => { - const responsePromise = onebusawaySDK.tripForVehicle.retrieve('vehicleID'); + const responsePromise = client.tripForVehicle.retrieve('vehicleID'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -23,14 +23,14 @@ describe('resource tripForVehicle', () => { 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( - onebusawaySDK.tripForVehicle.retrieve('vehicleID', { path: '/_stainless_unknown_path' }), + client.tripForVehicle.retrieve('vehicleID', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OnebusawaySDK.NotFoundError); }); test('retrieve: request options and 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( - onebusawaySDK.tripForVehicle.retrieve( + client.tripForVehicle.retrieve( 'vehicleID', { includeSchedule: true, includeStatus: true, includeTrip: true, time: 0 }, { path: '/_stainless_unknown_path' }, diff --git a/tests/api-resources/trip.test.ts b/tests/api-resources/trip.test.ts index 49a8e41..3d8e19c 100644 --- a/tests/api-resources/trip.test.ts +++ b/tests/api-resources/trip.test.ts @@ -3,14 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource trip', () => { test('retrieve', async () => { - const responsePromise = onebusawaySDK.trip.retrieve('tripID'); + const responsePromise = client.trip.retrieve('tripID'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -22,7 +22,7 @@ describe('resource trip', () => { 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(onebusawaySDK.trip.retrieve('tripID', { path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.trip.retrieve('tripID', { path: '/_stainless_unknown_path' })).rejects.toThrow( OnebusawaySDK.NotFoundError, ); }); diff --git a/tests/api-resources/trips-for-location.test.ts b/tests/api-resources/trips-for-location.test.ts index 9ba9f79..494e0db 100644 --- a/tests/api-resources/trips-for-location.test.ts +++ b/tests/api-resources/trips-for-location.test.ts @@ -3,19 +3,14 @@ import OnebusawaySDK from 'onebusaway-sdk'; import { Response } from 'node-fetch'; -const onebusawaySDK = new OnebusawaySDK({ +const client = new OnebusawaySDK({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource tripsForLocation', () => { test('retrieve: only required params', async () => { - const responsePromise = onebusawaySDK.tripsForLocation.retrieve({ - lat: 0, - latSpan: 0, - lon: 0, - lonSpan: 0, - }); + const responsePromise = client.tripsForLocation.retrieve({ lat: 0, latSpan: 0, lon: 0, lonSpan: 0 }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -26,7 +21,7 @@ describe('resource tripsForLocation', () => { }); test('retrieve: required and optional params', async () => { - const response = await onebusawaySDK.tripsForLocation.retrieve({ + const response = await client.tripsForLocation.retrieve({ lat: 0, latSpan: 0, lon: 0,