@@ -54,7 +54,7 @@ const handlers = {
54
54
var make = this . event . request . intent . slots . make . value ;
55
55
var model = this . event . request . intent . slots . model . value ;
56
56
var year = this . event . request . intent . slots . year . value ;
57
- speechOutput += " from " + fromCity + " to " + address + " , " + toCity + " on " + travelDate + "." ;
57
+ speechOutput += ` from ${ fromCity } to ${ address } , ${ toCity } on ${ travelDate } `
58
58
59
59
// Calling API
60
60
httpsGet_Geocode ( address , ( geocode ) => {
@@ -65,7 +65,7 @@ const handlers = {
65
65
var distancetext = matrix [ 1 ]
66
66
var durationvalue = matrix [ 2 ] // int
67
67
var durationtext = matrix [ 3 ]
68
- httpsGet_CarStats ( make , model , year , ( stats ) => {
68
+ httpsGetStats ( make , model , year , ( stats ) => {
69
69
var ctympg = stats [ 0 ] // int
70
70
var hwympg = stats [ 1 ] // int
71
71
httpsGet_CarTheft ( 'ma' , ( car ) => {
@@ -78,7 +78,7 @@ const handlers = {
78
78
var gasPrice = get_price ( lat , long )
79
79
var gasCost = Math . ceil ( ( gasPrice * distancevalue ) / hwympg )
80
80
if ( myCar . toLowerCase ( ) == theftCar . toLowerCase ( ) ) {
81
- speechOutput += " The total traveling distance is " + distancetext + " However, your car is on top of the car stolen list in this state. Becareful, I would recommend to find a garage to park." ;
81
+ speechOutput += `Based on the information that you've given, the total distance of will be ${ distancetext } . For gas expense, our estimation based on the traveling distance is ${ gasPrice } `
82
82
var activity = isSlotValid ( this . event . request , "activity" ) ;
83
83
if ( activity ) {
84
84
speechOutput += " to go " + activity ;
@@ -88,7 +88,7 @@ const handlers = {
88
88
this . response . speak ( speechOutput ) ;
89
89
this . emit ( ":responseReady" ) ;
90
90
}
91
- speechOutput += " The total traveling distance is " + distancetext + ", it will take around " + durationtext + " to go there. Your car " ;
91
+ speechOutput += ` The total traveling distance is ${ distancetext } , and based on the traveling distance, the estimate time that you'll arrive to your destination is ${ durationtext } ` ;
92
92
var activity = isSlotValid ( this . event . request , "activity" ) ;
93
93
if ( activity ) {
94
94
speechOutput += " to go " + activity ;
@@ -272,42 +272,36 @@ function httpsGet_Matrix(lat, long, callback) {
272
272
273
273
}
274
274
// Shine Car Stats
275
- function httpsGet_CarStats ( make , model , year , callback ) {
276
- // Update these options with the details of the web service you would like to call
277
- var options = {
278
- host : 'apis.solarialabs.com' ,
279
- port : 443 ,
280
- path : `/shine/v1/vehicle-stats/specs?make=${ make } &model=${ model } &year=${ year } &full-data=true&apikey=` + shine_key ,
281
- method : 'GET' ,
275
+ function httpsGetStats ( make , model , year , callback ) {
276
+ var stats_options = {
277
+ host : 'apis.solarialabs.com' ,
278
+ path : '/shine/v1/vehicle-stats/specs?make=' + make + '&model=' + model + '&year=' + year + '&full-data=true&apikey=' + shine_key ,
279
+ method : 'GET'
280
+ }
282
281
283
- // if x509 certs are required:
284
- // key: fs.readFileSync('certs/my-key.pem'),
285
- // cert: fs.readFileSync('certs/my-cert.pem')
286
- } ;
282
+ var req = https . request ( stats_options , function ( res ) {
283
+ res . setEncoding ( 'utf-8' ) ;
287
284
288
- var req = https . request ( options , res => {
289
- res . setEncoding ( 'utf8' ) ;
290
- var returnData = "" ;
285
+ var responseString = '' ;
291
286
292
- res . on ( 'data' , chunk => {
293
- returnData = returnData + chunk ;
294
- } ) ;
287
+ res . on ( 'data' , function ( data ) {
288
+ responseString += data ;
289
+ } ) ;
295
290
296
- res . on ( 'end' , ( ) => {
297
- // we have now received the raw return data in the returnData variable.
298
- // We can see it in the log output via:
299
- // console.log(JSON.stringify(returnData))
300
- // we may need to parse through it to extract the needed data
301
- var data = JSON . parse ( returnData ) ;
302
- var citygas = data [ 0 ] . City_Conventional_Fuel
303
- var hwygas = data [ 0 ] . Hwy_Conventional_Fuel
304
- callback ( [ citygas , citygas ] ) ;
305
- // this will execute whatever function the caller defined, with one argument
306
- } ) ;
291
+ res . on ( 'end' , function ( ) {
292
+ var response = JSON . parse ( responseString ) ;
293
+ var stats_make = response [ 0 ] . Make
294
+ var stats_model = response [ 0 ] . Model
295
+ var stats_car_year = response [ 0 ] . Model_Year
296
+ var stats_car_mpg = response [ 0 ] . City_Conventional_Fuel
297
+
298
+ console . log ( "Model Year of the " + stats_make + " " + stats_model + " is: " + stats_car_year + ". The combined highway and city MPG is " + stats_car_mpg + "." ) ;
299
+ callback ( [ stats_car_year , stats_car_mpg ] ) ;
300
+ } ) ;
307
301
} ) ;
308
- req . end ( ) ;
309
302
310
- }
303
+ req . end ( ) ;
304
+ }
311
305
// Shine Car Theft
312
306
function httpsGet_CarTheft ( state , callback ) {
313
307
// Update these options with the details of the web service you would like to call
0 commit comments