-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and extract useful parts for the new handler
- Loading branch information
Showing
11 changed files
with
75 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const fetchMTAStatus = require('../services/fetch-mta-status.js'); | ||
const closestLineMatcher = require('../utilities/closest-line-matcher.js'); | ||
|
||
module.exports = function() { | ||
let heardNameGroup = this.event.request.intent.slots.subwayLineOrGroup.value; | ||
|
||
if(!nameGroup) { this.emit(':tell', "Sorry, I didn't hear a subway line or group I recognized") }; | ||
|
||
fetchMTAStatus(statuses => { | ||
let closestLine = closestLineMatcher(statuses, 'nameGroup', heardNameGroup); | ||
|
||
this.emit('tell', `Your favorite line is ${closestLine.nameGroup}`); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const sanitize = require('sanitize-html'); | ||
const MATCHERS = { | ||
br: /<br\/?>\s*/g | ||
} | ||
|
||
module.exports = function(detailsText) { | ||
let text = detailsText.replace(MATCHERS.br, '\n'); // BRs to newline | ||
|
||
return sanitize(text, { | ||
allowedTags: [] | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const MTA_STATUS_URL = process.env.MTA_STATUS_URL; | ||
const currentMTAStatus = require('../parsers/current-mta-status.js'); | ||
|
||
module.exports = function(callback) { | ||
return fetch(MTA_STATUS_URL) | ||
.then(response => response.text()) | ||
.then(body => currentMTAStatus(body, callback)); | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const _ = require('lodash'); | ||
const levenshtein = require('fast-levenshtein'); | ||
|
||
module.exports = function(statuses, key, potentialValue) { | ||
let closetStatus; | ||
|
||
if(potentialValue.length > 1) { | ||
closestStatus = _.minBy(statuses, function(status) { | ||
return levenshtein.get(status[key], potentialValue.toUpperCase()); | ||
}); | ||
} else { | ||
closestStatus = _.find(statuses, function(status) { | ||
return status[key].search(potentialValue.toUpperCase()) !== -1; | ||
}); | ||
} | ||
return closestStatus; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters