|
1 |
| -## A fully typed Tbilisi Transport Company API Wrapper |
| 1 | +# ttc-api |
2 | 2 |
|
3 |
| -### [Documentation](docs/modules/ttc.md) |
| 3 | +A fully typed TypeScript wrapper for the Tbilisi Transport Company (TTC) API, providing real-time access to public transport data in Tbilisi, Georgia. |
4 | 4 |
|
5 |
| -### Installation |
| 5 | +[](https://www.npmjs.com/package/ttc-api) |
| 6 | +[](https://opensource.org/licenses/MIT) |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +- 🚌 Real-time bus locations and arrival times |
| 11 | +- 🗺️ Route planning and navigation |
| 12 | +- 🎯 Bus stop information |
| 13 | +- ⌚ Live arrival predictions |
| 14 | +- 📝 Full TypeScript support |
| 15 | +- 🌍 Multilingual support (Georgian and English) |
| 16 | + |
| 17 | +## Installation |
6 | 18 |
|
7 | 19 | ```bash
|
8 | 20 | # npm
|
9 |
| -$ npm install ttc-api |
| 21 | +npm install ttc-api |
10 | 22 |
|
11 | 23 | # yarn
|
12 |
| -$ yarn add ttc-api |
| 24 | +yarn add ttc-api |
13 | 25 |
|
14 | 26 | # pnpm
|
15 |
| -$ pnpm add ttc-api |
| 27 | +pnpm add ttc-api |
16 | 28 | ```
|
17 | 29 |
|
18 |
| -### Usage |
| 30 | +## Usage |
| 31 | + |
| 32 | +### Basic Examples |
19 | 33 |
|
20 | 34 | ```typescript
|
21 | 35 | import { ttc } from "ttc-api";
|
22 | 36 |
|
23 |
| -const arrivalTimes = await ttc.stopArrivalTimes("1946").then((arrivalTimes) => { |
| 37 | +// Set preferred language (optional, defaults to 'en') |
| 38 | +ttc.setLocale("en"); // or "ka" for Georgian |
| 39 | + |
| 40 | +// Get all bus stops |
| 41 | +const stops = await ttc.stops(); |
| 42 | + |
| 43 | +// Get arrival times for a specific stop |
| 44 | +const arrivals = await ttc.arrivalTimes({ |
| 45 | + stopId: "1946", |
| 46 | + ignoreScheduledArrivalTimes: false, |
| 47 | +}); |
| 48 | + |
| 49 | +// Get real-time bus locations |
| 50 | +const busLocations = await ttc.locations({ |
| 51 | + busId: "123", |
| 52 | + forward: true, |
| 53 | +}); |
| 54 | + |
| 55 | +// Plan a route |
| 56 | +const journey = await ttc.plan({ |
| 57 | + from: [41.7151, 44.8271], // [latitude, longitude] |
| 58 | + to: [41.7099, 44.7929], |
| 59 | + locale: "en", |
| 60 | +}); |
| 61 | +``` |
| 62 | + |
| 63 | +### Advanced Usage |
| 64 | + |
| 65 | +#### Get Routes for a Specific Stop |
| 66 | + |
| 67 | +```typescript |
| 68 | +const stopRoutes = await ttc.stopRoutes({ |
| 69 | + stopId: "1946", |
| 70 | + locale: "en", |
| 71 | +}); |
| 72 | + |
| 73 | +stopRoutes.forEach((route) => { |
| 74 | + console.log(`Bus ${route.shortName}: ${route.longName}`); |
| 75 | +}); |
| 76 | +``` |
| 77 | + |
| 78 | +#### Monitor Real-time Arrivals |
| 79 | + |
| 80 | +```typescript |
| 81 | +const monitorArrivals = async (stopId: string) => { |
| 82 | + const arrivals = await ttc.arrivalTimes({ stopId }); |
| 83 | + |
| 84 | + arrivals.forEach((arrival) => { |
| 85 | + console.log( |
| 86 | + `Bus ${arrival.shortName} arriving in ${arrival.realtimeArrivalMinutes} minutes` |
| 87 | + ); |
| 88 | + console.log(`Status: ${arrival.realtime ? "Real-time" : "Scheduled"}`); |
| 89 | + }); |
| 90 | +}; |
| 91 | +``` |
| 92 | + |
| 93 | +## API Reference |
| 94 | + |
| 95 | +### Core Functions |
| 96 | + |
| 97 | +#### `setLocale(locale: "ka" | "en")` |
| 98 | + |
| 99 | +Set the preferred language for responses. |
| 100 | + |
| 101 | +#### `stops(params?: { locale?: "ka" | "en" })` |
| 102 | + |
| 103 | +Get all bus stops in the network. |
| 104 | + |
| 105 | +#### `stop(stopId: string)` |
| 106 | + |
| 107 | +Get detailed information about a specific stop. |
| 108 | + |
| 109 | +#### `routes(params?: { locale?: "ka" | "en" })` |
| 110 | + |
| 111 | +Get all bus routes. |
24 | 112 |
|
25 |
| -for (let at of arrivalTimes) { |
26 |
| - console.log(`${at.RouteNumber} arrives in ${at.ArrivalTime} minutes`); |
| 113 | +#### `plan(options: PlanOptions)` |
| 114 | + |
| 115 | +Plan a journey between two points. |
| 116 | + |
| 117 | +```typescript |
| 118 | +interface PlanOptions { |
| 119 | + from: [number, number]; // [latitude, longitude] |
| 120 | + to: [number, number]; // [latitude, longitude] |
| 121 | + locale?: "ka" | "en"; |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +#### `locations(options: LocationOptions)` |
| 126 | + |
| 127 | +Get real-time locations of buses on a route. |
| 128 | + |
| 129 | +```typescript |
| 130 | +interface LocationOptions { |
| 131 | + busId: string; |
| 132 | + forward?: boolean; |
| 133 | +} |
| 134 | +``` |
| 135 | + |
| 136 | +#### `arrivalTimes(options: ArrivalOptions)` |
| 137 | + |
| 138 | +Get arrival predictions for a stop. |
| 139 | + |
| 140 | +```typescript |
| 141 | +interface ArrivalOptions { |
| 142 | + stopId: string; |
| 143 | + locale?: "ka" | "en"; |
| 144 | + ignoreScheduledArrivalTimes?: boolean; |
27 | 145 | }
|
28 | 146 | ```
|
| 147 | + |
| 148 | +### Types |
| 149 | + |
| 150 | +The library includes comprehensive TypeScript definitions for all API responses. Key types include: |
| 151 | + |
| 152 | +```typescript |
| 153 | +type Locale = "ka" | "en"; |
| 154 | + |
| 155 | +interface BusStop { |
| 156 | + id: string; |
| 157 | + code: string | null; |
| 158 | + name: string; |
| 159 | + lat: number; |
| 160 | + lon: number; |
| 161 | + vehicleMode: "BUS" | "GONDOLA" | "SUBWAY"; |
| 162 | +} |
| 163 | + |
| 164 | +interface BusArrival { |
| 165 | + shortName: string; |
| 166 | + color: string; |
| 167 | + headsign: string; |
| 168 | + realtime: boolean; |
| 169 | + realtimeArrivalMinutes: number; |
| 170 | + scheduledArrivalMinutes: number; |
| 171 | +} |
| 172 | + |
| 173 | +// ... and more |
| 174 | +``` |
| 175 | + |
| 176 | +## Acknowledgments |
| 177 | + |
| 178 | +- Built with [requestly](https://www.npmjs.com/package/requestly) for HTTP requests |
| 179 | + |
| 180 | +## Support |
| 181 | + |
| 182 | +If you encounter any issues or have questions, please [open an issue](https://github.com/sunneydev/ttc-api/issues) on GitHub. |
0 commit comments