Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ name: Node.js CI

on:
push:
branches: [ "main" ]
branches: ['main']
pull_request:
branches: [ "main" ]
branches: ['main']

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand All @@ -29,3 +28,4 @@ jobs:
- run: npm ci
- run: npm run build --if-present
- run: npm run test-unit
- run: npm run lint
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
8 changes: 4 additions & 4 deletions .jest/setEnvVars.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {readFileSync} from "node:fs";
import { readFileSync } from 'node:fs'

const tokenFile: string = process.env.TOKEN_FILE || ".token";
const tokenFile: string = process.env.TOKEN_FILE || '.token'

try {
process.env.METLINK_TOKEN = readFileSync(tokenFile, "utf-8");
process.env.METLINK_TOKEN = readFileSync(tokenFile, 'utf-8')
} catch {
process.env.METLINK_TOKEN = process.env.METLINK_TOKEN || ""
process.env.METLINK_TOKEN = process.env.METLINK_TOKEN || ''
}
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trailingComma: 'es5'
tabWidth: 4
semi: false
singleQuote: true
122 changes: 64 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
https://opendata.metlink.org.nz/

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=jaddek_metlink-api-http-client-typescript&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=jaddek_metlink-api-http-client-typescript)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

## Install

Expand All @@ -29,51 +30,59 @@ https://api.opendata.metlink.org.nz/v1
#### Client

```ts
import {MetlinkHttpClientInterface} from "./Contracts";
import {MetlinkHttpClientBuilder} from "./MetlinkHttpClientBuilder";
import { MetlinkHttpClientInterface } from './Contracts'
import { MetlinkHttpClientBuilder } from './MetlinkHttpClientBuilder'

const options = {
timeout: 1000
};
const metlinkHttpClient: MetlinkHttpClientInterface = MetlinkHttpClientBuilder.buildWithAxios(
token,
options,
function (axios: AxiosInstance) {
axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
return Promise.reject(error);
});
}
);
timeout: 1000,
}
const metlinkHttpClient: MetlinkHttpClientInterface =
MetlinkHttpClientBuilder.buildWithAxios(
token,
options,
function (axios: AxiosInstance) {
axios.interceptors.response.use(
function (response) {
return response
},
function (error) {
return Promise.reject(error)
}
)
}
)
```

OR

```ts
import {MetlinkHttpClientInterface} from "./Contracts";
import {MetlinkHttpClientBuilder} from "./MetlinkHttpClientBuilder";
import { MetlinkHttpClientInterface } from './Contracts'
import { MetlinkHttpClientBuilder } from './MetlinkHttpClientBuilder'

const options = {
timeout: 1000
};
const metlinkHttpClient: MetlinkHttpClientInterface = MetlinkHttpClientBuilder.buildWithAxiosAndDecorate(
token,
options,
function (axios: AxiosInstance) {
axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
return Promise.reject(error);
});
}
);
timeout: 1000,
}
const metlinkHttpClient: MetlinkHttpClientInterface =
MetlinkHttpClientBuilder.buildWithAxiosAndDecorate(
token,
options,
function (axios: AxiosInstance) {
axios.interceptors.response.use(
function (response) {
return response
},
function (error) {
return Promise.reject(error)
}
)
}
)
```

#### Wrapped response body

```ts
const metlinkHttpClient = new ResponseDataDecorator(httpClient);
const metlinkHttpClient = new ResponseDataDecorator(httpClient)
```

### Tests
Expand All @@ -92,8 +101,8 @@ TOKEN_FILE=.token jest tests

#### Unresolved issues:

- GTFS-RT: Service Alerts: Validation Scheme issue
- GTFS-RT: Trip Updates: Validation Scheme issue
- GTFS-RT: Service Alerts: Validation Scheme issue
- GTFS-RT: Trip Updates: Validation Scheme issue

## API

Expand All @@ -104,71 +113,71 @@ TOKEN_FILE=.token jest tests
Transit agencies with service represented in this dataset.

```ts
metlinkHttpClient.getGtfsAgencies();
metlinkHttpClient.getGtfsAgencies()
```

#### Calendars

Service dates specified using a weekly schedule with start and end dates.

```ts
metlinkHttpClient.getGtfsCalendar();
metlinkHttpClient.getGtfsCalendar()
```

#### Calendar Dates

Exceptions for the services defined in the calendar.

```ts
metlinkHttpClient.getGtfsCalendarDates();
metlinkHttpClient.getGtfsCalendarDates()
```

#### Feed info

Dataset metadata, including publisher, version, and expiration information.

```ts
metlinkHttpClient.getGtfsFeedInfo();
metlinkHttpClient.getGtfsFeedInfo()
```

#### Routes

Transit routes. A route is a group of trips that are displayed to riders as a single service.

```ts
metlinkHttpClient.getGtfsRoutes();
metlinkHttpClient.getGtfsRoutes()
```

#### Shapes

Rules for mapping vehicle travel paths, sometimes referred to as route alignments.

```ts
metlinkHttpClient.getGtfsShapes("shapeId");
metlinkHttpClient.getGtfsShapes('shapeId')
```

#### Stop Times

Times that a vehicle arrives at and departs from stops for each trip.

```ts
metlinkHttpClient.getGtfsStopTimes("tripId");
metlinkHttpClient.getGtfsStopTimes('tripId')
```

#### Stops

Stops where vehicles pick up or drop off riders. Also defines stations and station entrances.

```ts
metlinkHttpClient.getGtfsStops();
metlinkHttpClient.getGtfsStops()
```

#### Transfers

Rules for making connections at transfer points between routes.

```ts
metlinkHttpClient.getGtfsTransfers();
metlinkHttpClient.getGtfsTransfers()
```

#### Trips
Expand All @@ -177,12 +186,12 @@ Trips for each route. A trip is a sequence of two or more stops that occur durin

```ts
metlinkHttpClient.getGtfsTrips(
"start",
"extraFields",
"routeId",
"tripId",
"end"
);
'start',
'extraFields',
'routeId',
'tripId',
'end'
)
```

### GTFS-RT
Expand All @@ -193,23 +202,23 @@ Information about unforeseen events affecting routes, stops, or the network. Use
to receive in Protobuf format.

```ts
metlinkHttpClient.getGtfsServiceAlerts();
metlinkHttpClient.getGtfsServiceAlerts()
```

#### Trip Updates

Delays, cancellations, changed routes. Use accept header 'application/x-protobuf' to receive in Protobuf format.

```ts
metlinkHttpClient.getGtfsRtTripUpdates();
metlinkHttpClient.getGtfsRtTripUpdates()
```

#### Vehicle Positions

Information about vehicles including location. Use accept header 'application/x-protobuf' to receive in Protobuf format.

```ts
metlinkHttpClient.getGtfsRtVehiclePositions();
metlinkHttpClient.getGtfsRtVehiclePositions()
```

### Other
Expand All @@ -219,18 +228,15 @@ metlinkHttpClient.getGtfsRtVehiclePositions();
Predictions for when vehicles will arrive and depart through stops.

```ts
metlinkHttpClient.getStopPredictions("stopId");
metlinkHttpClient.getStopPredictions('stopId')
```

#### Trip Cancellations

Historical, current, and known future data for trip cancellations.

```ts
const query: Query = new Query();
query.dateCreated = Date.now().toString();
metlinkHttpClient.getTripCancellation(query);
const query: Query = new Query()
query.dateCreated = Date.now().toString()
metlinkHttpClient.getTripCancellation(query)
```



14 changes: 14 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-check

import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
}
)
Loading