From 0882418b78daed18f17667c0b11faf262e46289f Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Sat, 20 Jan 2024 23:40:51 -0600 Subject: [PATCH 1/2] Remove mockResponse --- __mocks__/mockResponse.js | 15 --------------- __mocks__/node-fetch.js | 4 +--- 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 __mocks__/mockResponse.js diff --git a/__mocks__/mockResponse.js b/__mocks__/mockResponse.js deleted file mode 100644 index f8f2db4..0000000 --- a/__mocks__/mockResponse.js +++ /dev/null @@ -1,15 +0,0 @@ -function mockResponse() { - const body = { - /** TODO mock return body */ - }; - - return { - json: async () => body, - status: 200, - headers: { - 'Content-type': 'application/json', - }, - }; -} - -module.exports = mockResponse; diff --git a/__mocks__/node-fetch.js b/__mocks__/node-fetch.js index b0b701c..d98049e 100644 --- a/__mocks__/node-fetch.js +++ b/__mocks__/node-fetch.js @@ -1,3 +1 @@ -mockResponse = require('mockResponse'); - -jest.mock('node-fetch', () => jest.fn(() => Promise.resolve(mockResponse()))); +jest.mock('node-fetch', () => jest.fn()); From 8339d46396cf9043602dad250bee973843e38326 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Sat, 20 Jan 2024 23:41:23 -0600 Subject: [PATCH 2/2] Update README --- MMM-CTA.js | 2 +- README.md | 81 +++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 66 insertions(+), 17 deletions(-) diff --git a/MMM-CTA.js b/MMM-CTA.js index 6c1a501..958d2df 100644 --- a/MMM-CTA.js +++ b/MMM-CTA.js @@ -12,8 +12,8 @@ Module.register('MMM-CTA', { updateInterval: 60000, trainApiKey: null, busApiKey: null, - maxResultsTrain: 5, maxResultsBus: 5, + maxResultsTrain: 5, stops: [], }, diff --git a/README.md b/README.md index e2de920..1ced14b 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ This is a module for the [MagicMirror²](https://github.com/MichMich/MagicMirror/). - - ## Installation In ~/MagicMirror/modules @@ -17,30 +15,76 @@ cd MMM-CTA npm install --production ``` +## Obtaining CTA API keys + +You need to obtain API keys to access CTA data. The API keys are two separate keys for two services. + +- [Bus API](http://www.transitchicago.com/developers/bustracker.aspx) +- [Train API](http://www.transitchicago.com/developers/traintrackerapply.aspx) + +The bus tracker API key can be obtained immediately, the train tracker key can take a few days to register. + ## Using the module To use this module, add the following configuration block to the modules array in the `config/config.js` file: ```js var config = { - modules: [ - { - module: 'MMM-CTA', - config: { - // See below for configurable options - } - } - ] + modules: [ + { + module: 'MMM-CTA', + config: { + // See below for configurable options + } + } + ] } ``` ## Configuration options - -| Option | Required? | Description | -| ---------------- | ------------ | ---------------------------------------------------------------------- | -| `busToken` | **Required** | How to get? | -| `trainToken` | **Required** | How to get? | -| `updateInterval` | *Optional* | Refresh time in milliseconds
Default 60000 milliseconds (1 minute) | +| Option | Required? | Description | +| ----------------- | ------------ | ---------------------------------------------------------------------- | +| `busApiKey` | **Required** | How to get? | +| `trainApiKey` | **Required** | How to get? | +| `stops` | **Required** | Array of stops to display. See [`stops` option](#stops-option) | +| `updateInterval` | *Optional* | Refresh time in milliseconds
Default 60000 milliseconds (1 minute) | +| `maxResultsBus` | *Optional* | Maximum number of bus results to display
Default 5 | +| `maxResultsTrain` | *Optional* | Maximum number of train results to display
Default 5 | + +### `stops` option + +The `stops` option is an array of objects. Each object represents a stop to display. + +```js +{ + stops: [ + { + type: 'bus', + id: 561, + name: 'Chicago and Milwaukee' + }, + { + type: 'train', + id: 41410, + name: 'Blue Line' + } + ] +} +``` + +| Property | Description | +| -------- | -------------------------------------------------------------------- | +| `type` | Type of stop. Either `bus` or `train` | +| `id` | Stop ID. See [Finding Stop IDs](#finding-stop-ids) | +| `name` | Name of stop. This is displayed in the header of the stop's results. | + +### Finding Stop IDs + +1. Go to [CTA Trackers](https://www.transitchicago.com/tracker/) and select Train or Bus Tracker. +2. Search for your stop inside of the given app +3. Once you find your stop, obtain the Id. It will be the number at the end of the page's URL + 1. For train tracker, it may look like `?sid={id}`. The `id` is the stop ID. + 2. For bus tracker, it may look like `Southbound/{id}`. The `id` is the stop ID. ## Development @@ -67,3 +111,8 @@ npm run lint # Fix linting errors npm run fix ``` + + +## Thanks + +This module is inspired by [MMM-CTA from NateDee](https://github.com/NateDee/MMM-CTA).