diff --git a/.gitpod.yml b/.gitpod.yml index fea5126..6dfd6f9 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -5,6 +5,9 @@ # Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart tasks: + - name: Start Redis Stack + init: docker compose --file ./docker-compose-dev.yaml up -d + - init: npm install && npm run build command: npm run dev diff --git a/docker-compose-dev.yaml b/docker-compose-dev.yaml new file mode 100644 index 0000000..3bdc093 --- /dev/null +++ b/docker-compose-dev.yaml @@ -0,0 +1,8 @@ +version: '3.9' + +services: + redis: + container_name: redis + image: redis:latest + ports: + - 6379:6379 \ No newline at end of file diff --git a/src/Library/PlatformNotifyLab.ts b/src/Library/PlatformNotifyLab.ts new file mode 100644 index 0000000..8764e8e --- /dev/null +++ b/src/Library/PlatformNotifyLab.ts @@ -0,0 +1,9 @@ +// src/Library/PlatformNotifyLab.ts +/** + * This is just temp until I work out the actual design of the main system + */ +import { logger, LogMode } from "./Logger"; + +export async function monitorRoute(routeName: string): Promise { + logger.log(LogMode.DEBUG, `Starting route monitoring system`); +} \ No newline at end of file diff --git a/src/Modules/GoTransit/Stop.ts b/src/Modules/GoTransit/Stop.ts index c4dff28..86dcb84 100644 --- a/src/Modules/GoTransit/Stop.ts +++ b/src/Modules/GoTransit/Stop.ts @@ -2,10 +2,26 @@ import { Type } from 'class-transformer'; import { IsString } from 'class-validator'; +export enum GoTransitStopType { + BUS = 'Bus Stop', + TRAIN = 'Train Station', + TRAINBUS = 'Train & Bus Station', + BUSTERMINAL = 'Bus Terminal', + PARKNRIDE = 'Park & Ride' +} + export class GoTransitStop { @Type(() => String) @IsString() - public Name: string; + public LocationCode: string; + + @Type(() => String) + @IsString() + public LocationName: string; + + @Type(() => String) + @IsString() + public PublicStopId: string; - public Code: string | null; + public LocationType: GoTransitStopType; } diff --git a/src/Modules/GoTransit/UnionDeparture.ts b/src/Modules/GoTransit/UnionDeparture.ts index a0fac20..c59384f 100644 --- a/src/Modules/GoTransit/UnionDeparture.ts +++ b/src/Modules/GoTransit/UnionDeparture.ts @@ -1,7 +1,14 @@ // src/Modules/GoTransit/Trips.ts import { IsDate, IsNumber, IsString } from 'class-validator'; import { Type } from 'class-transformer'; -import { GoTransitStop } from './Stop'; + +export class GoTransitUnionDepartureStop { + @Type(() => String) + @IsString() + public Name: string; + + public Code: string | null; +} export class GoTransitUnionDepartureTrip { @Type(() => String) @@ -28,6 +35,6 @@ export class GoTransitUnionDepartureTrip { @IsDate() public Time: Date; - @Type(() => GoTransitStop) - public Stops: GoTransitStop[]; + @Type(() => GoTransitUnionDepartureStop) + public Stops: GoTransitUnionDepartureStop[]; } diff --git a/src/Modules/GoTransit/index.ts b/src/Modules/GoTransit/index.ts index 18c931c..62e5381 100644 --- a/src/Modules/GoTransit/index.ts +++ b/src/Modules/GoTransit/index.ts @@ -3,6 +3,7 @@ import { plainToInstance } from 'class-transformer'; import got, { OptionsOfJSONResponseBody } from 'got'; import { CONFIG } from '../../Library/Config'; import { logger, LogMode } from '../../Library/Logger'; +import { GoTransitStop, GoTransitStopType } from './Stop'; import { GoTransitTrainTrip } from './TrainTrip'; import { GoTransitUnionDepartureTrip } from './UnionDeparture'; @@ -19,6 +20,7 @@ interface APIMetadata { ErrorMessage: string; } + interface APIResponse { Metadata: APIMetadata; } @@ -61,6 +63,12 @@ export class GoTransit { return request.body; } + /** + * Gets all the trains soon arriving at Union and the platform allocation + * if provided/same as the departure board/go tracker. + * + * @returns array of GoTransitUnionDepartureTrip + */ public async unionDepartures(): Promise { const response = await this.makeRequest< APIResponse & { AllDepartures: { Trip: GoTransitUnionDepartureTrip[] } } @@ -72,6 +80,12 @@ export class GoTransit { ); } + + /** + * Function to get all active trains within the Go Transit network. + * + * @returns All active trains in Go Network + */ public async getAllTrains(): Promise { const response = await this.makeRequest< APIResponse & { Trips: { Trip: GoTransitUnionDepartureTrip[] } } @@ -79,4 +93,18 @@ export class GoTransit { return plainToInstance(GoTransitTrainTrip, response.Trips.Trip); } + + /** + * Get all Go Transit Stops within the network + * + * @returns Array of all Go Transit Bus Stops, + * Bus Terminals, Bus & Train Stations, and Park & Ride Stops + */ + public async getAllStops(): Promise { + const response = await this.makeRequest< + APIResponse & { Stations: { Station: GoTransitStop[] } } + >('Stop/All'); + + return plainToInstance(GoTransitStop, response.Stations.Station); + } } diff --git a/src/Modules/User/index.ts b/src/Modules/User/index.ts index 9a6c812..e27a5ea 100644 --- a/src/Modules/User/index.ts +++ b/src/Modules/User/index.ts @@ -1,23 +1,25 @@ // src/Modules/User/index.ts -import { iCloudAPI, sendAlert } from "../../Library/iCloud"; -import { logger, LogMode } from "../../Library/Logger"; +import { iCloudAPI, sendAlert } from '../../Library/iCloud'; +import { logger, LogMode } from '../../Library/Logger'; export class User { public name: string; public deviceID: string; - public async findUserNotifyDevice(deviceName: string): Promise { const findMyAPI = iCloudAPI.getService('findme'); - await findMyAPI.refresh() + await findMyAPI.refresh(); for (const [deviceID, device] of findMyAPI.devices) { logger.log(LogMode.DEBUG, `Looping over user Devices`, deviceID, device); if (device.deviceInfo.name === deviceName) { - logger.log(LogMode.DEBUG, `Found device ${deviceName} with the ID of ${deviceID}`); + logger.log( + LogMode.DEBUG, + `Found device ${deviceName} with the ID of ${deviceID}`, + ); this.deviceID = deviceID; } @@ -27,10 +29,7 @@ export class User { /** * Sends notification to user via her Apple Watch Ultra */ - public async notifyUser(options: { - subject?: string, - text?: string - }) { - await sendAlert(this.deviceID, options) + public async notifyUser(options: { subject?: string; text?: string }) { + await sendAlert(this.deviceID, options); } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index cdc45a0..a181bf4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,30 +1,25 @@ // src/index.ts import 'reflect-metadata'; import { CONFIG } from './Library/Config'; -import { initiCloud } from './Library/iCloud'; import { logger, LogMode } from './Library/Logger'; import { GoTransit } from './Modules/GoTransit'; -import { User } from './Modules/User'; import { sayHello } from './Utils/sayHello'; - - logger.log(LogMode.INFO, `Starting TransitRouting`); +// logger.log(LogMode.INFO, `Init iCloud Library`); +// await initiCloud(); -logger.log(LogMode.INFO, `Init iCloud Library`); -await initiCloud(); - -logger.log(LogMode.INFO, `Creating Kristine Entity`); +// logger.log(LogMode.INFO, `Creating Kristine Entity`); -const kristine = new User(); +// const kristine = new User(); -await kristine.findUserNotifyDevice(`Kristine’s Apple Watch`); +// await kristine.findUserNotifyDevice(`Kristine’s Apple Watch`); -await kristine.notifyUser({ - subject: 'Platform Assignment', - text: 'Platform 6 & 7' -}) +// await kristine.notifyUser({ +// subject: 'Platform Assignment', +// text: 'Platform 6 & 7' +// }) const goAPI = new GoTransit({ apiURL: CONFIG.apiURL,