hubot-nextbus 2.0.2 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/package.json +1 -1
- package/src/nextbus.coffee +13 -7
- package/test/nextbus_test.coffee +31 -1
package/README.md
CHANGED
|
@@ -21,7 +21,8 @@ Then add **hubot-nextbus** to your `external-scripts.json`:
|
|
|
21
21
|
| Environment Variable | Optional | Description |
|
|
22
22
|
| ----------------------- | :------: | ----------------------------------------|
|
|
23
23
|
| `HUBOT_NEXTBUS_LAT_LON` | No | Default location for `hubot nextbus`, separated by a comma. (e.g. `36.1629191,-86.7813481`)|
|
|
24
|
-
| `
|
|
24
|
+
| `HUBOT_NEXTBUS_STOP_ID` | Yes | Specific identifier to use with `hubot nextbus`; if not set, falls back to latitude/longitude |
|
|
25
|
+
| `HUBOT_NEXTBUS_BASE_URL`| Yes | URL of a `gtfs-rails-api` instance; Defaults to Nashville, TN. |
|
|
25
26
|
|
|
26
27
|
## Usage
|
|
27
28
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hubot-nextbus",
|
|
3
3
|
"description": "Shows when the next transit vehicle will arrive at a particular stop.",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.1",
|
|
5
5
|
"author": "Stephen Yeargin <stephen@yearg.in>",
|
|
6
6
|
"homepage": "https://github.com/transitnownash/hubot-nextbus",
|
|
7
7
|
"license": "MIT",
|
package/src/nextbus.coffee
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
#
|
|
4
4
|
# Configuration:
|
|
5
5
|
# HUBOT_NEXTBUS_BASE_URL - URL of a `gtfs-rails-api` instance
|
|
6
|
-
# HUBOT_NEXTBUS_LAT_LON - Default location for
|
|
6
|
+
# HUBOT_NEXTBUS_LAT_LON - Default location for stop search
|
|
7
|
+
# HUBOT_NEXTBUS_STOP_ID - Default stop for `hubot nextbus`
|
|
7
8
|
#
|
|
8
9
|
# Commands:
|
|
9
10
|
# hubot nextbus
|
|
@@ -14,14 +15,19 @@
|
|
|
14
15
|
# Author:
|
|
15
16
|
# stephenyeargin
|
|
16
17
|
|
|
17
|
-
moment = require('moment')
|
|
18
|
-
AsciiTable = require('ascii-table')
|
|
19
|
-
baseURL = process.env.HUBOT_NEXTBUS_BASE_URL || 'https://gtfs.transitnownash.org'
|
|
20
|
-
latlon = process.env.HUBOT_NEXTBUS_LAT_LON
|
|
21
|
-
|
|
22
18
|
module.exports = (robot) ->
|
|
23
|
-
|
|
19
|
+
moment = require('moment')
|
|
20
|
+
AsciiTable = require('ascii-table')
|
|
21
|
+
baseURL = process.env.HUBOT_NEXTBUS_BASE_URL || 'https://gtfs.transitnownash.org'
|
|
22
|
+
latlon = process.env.HUBOT_NEXTBUS_LAT_LON
|
|
23
|
+
defaultStopId = process.env.HUBOT_NEXTBUS_STOP_ID
|
|
24
|
+
|
|
25
|
+
# query the default stop ID or location's closest bus stop
|
|
24
26
|
robot.respond /(?:bus|nextbus)(?: me)?$/i, (msg) ->
|
|
27
|
+
if defaultStopId
|
|
28
|
+
queryStopById defaultStopId, msg
|
|
29
|
+
return
|
|
30
|
+
|
|
25
31
|
getAPIResponse "stops/near/#{latlon}/1000.json?per_page=5", msg, (stops) ->
|
|
26
32
|
if stops.total > 0
|
|
27
33
|
queryStopById stops.data[0].stop_gid, msg
|
package/test/nextbus_test.coffee
CHANGED
|
@@ -26,7 +26,7 @@ describe 'hubot-nextbus', ->
|
|
|
26
26
|
nock.cleanAll()
|
|
27
27
|
Date.now = originalDateNow
|
|
28
28
|
|
|
29
|
-
context 'regular tests', ->
|
|
29
|
+
context 'regular tests with latitude/longitude set', ->
|
|
30
30
|
beforeEach ->
|
|
31
31
|
Date.now = () ->
|
|
32
32
|
return Date.parse('Fri, 1 Oct 2021 12:00:00 UTC')
|
|
@@ -88,6 +88,36 @@ describe 'hubot-nextbus', ->
|
|
|
88
88
|
return
|
|
89
89
|
, 1000)
|
|
90
90
|
|
|
91
|
+
context 'regular tests with default stop ID set', ->
|
|
92
|
+
beforeEach ->
|
|
93
|
+
Date.now = () ->
|
|
94
|
+
return Date.parse('Fri, 1 Oct 2021 12:00:00 UTC')
|
|
95
|
+
process.env.HUBOT_NEXTBUS_LAT_LON = '0,0'
|
|
96
|
+
process.env.HUBOT_NEXTBUS_STOP_ID = 'CHA7AWN'
|
|
97
|
+
@room = helper.createRoom()
|
|
98
|
+
|
|
99
|
+
afterEach ->
|
|
100
|
+
@room.destroy()
|
|
101
|
+
delete process.env.HUBOT_NEXTBUS_LAT_LON
|
|
102
|
+
delete process.env.HUBOT_NEXTBUS_STOP_ID
|
|
103
|
+
|
|
104
|
+
# hubot nextbus
|
|
105
|
+
it 'returns the next bus for closest stop', (done) ->
|
|
106
|
+
selfRoom = @room
|
|
107
|
+
selfRoom.user.say('alice', '@hubot nextbus')
|
|
108
|
+
setTimeout(() ->
|
|
109
|
+
try
|
|
110
|
+
expect(selfRoom.messages).to.eql [
|
|
111
|
+
['alice', '@hubot nextbus']
|
|
112
|
+
['hubot', 'Upcoming Trips for [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB']
|
|
113
|
+
['hubot', ' 7:01 AM #50 - CHARLOTTE WALMART in a minute \n 7:15 AM #17 - GREEN HILLS VIA 12TH AVE S in 16 minutes \n 7:16 AM #50 - CHARLOTTE WALMART in 16 minutes \n 7:31 AM #50 - CHARLOTTE WALMART in 31 minutes \n 7:35 AM #17 - GREEN HILLS VIA 12TH AVE S in 36 minutes ']
|
|
114
|
+
]
|
|
115
|
+
done()
|
|
116
|
+
catch err
|
|
117
|
+
done err
|
|
118
|
+
return
|
|
119
|
+
, 1000)
|
|
120
|
+
|
|
91
121
|
context 'time spans days', ->
|
|
92
122
|
beforeEach ->
|
|
93
123
|
Date.now = () ->
|