@@ -6,45 +6,49 @@ var util = require('util');
66var libVersion = require ( '../package.json' ) . version ;
77
88// Private Functions
9- function __getBaseUrl ( league , feed , format , params ) {
10- return this . baseUrl + '/' + league + '/' + feed + '.' + format ;
11- }
12-
139function __verifyFeedName ( feed ) {
14- var isValid = false ;
15-
16- this . validFeeds . forEach ( function ( value ) {
17- if ( value == feed ) {
18- isValid = true ;
19- }
20- } ) ;
10+ if ( ! feed ) {
11+ return false ;
12+ }
2113
22- return isValid ;
14+ return this . validFeeds . includes ( feed ) ;
2315}
2416
2517function __verifyFormat ( format ) {
26- var isValid = true ;
27-
2818 // Only JSON format supported
29- if ( format ! = 'json' ) {
30- isValid = false ;
19+ if ( ! format || format != = 'json' ) {
20+ return false ;
3121 }
3222
33- return isValid ;
23+ return true ;
3424}
3525
3626function __makeOutputFilename ( league , season , feed , format , params ) {
37- var filename = feed + '-' + league + '-' + season ;
27+ var filename = `${ feed } -${ league } -${ season } ` ;
28+
29+ const keys = Object . keys ( params ) ;
30+
31+ if ( keys . includes ( "gameid" ) ) {
32+ filename += `-${ params [ "gameid" ] } ` ;
33+ }
3834
39- if ( Object . keys ( params ) . includes ( "gameid " ) ) {
40- filename += "-" + params [ "gameid" ] ;
35+ if ( keys . includes ( "fordate " ) ) {
36+ filename += `- ${ params [ "fordate" ] } ` ;
4137 }
4238
43- if ( Object . keys ( params ) . includes ( "fordate " ) ) {
44- filename += "-" + params [ "fordate" ] ;
39+ if ( keys . includes ( "game " ) ) {
40+ filename += `- ${ params [ "game" ] } ` ;
4541 }
4642
47- filename += "." + format ;
43+ if ( keys . includes ( "date" ) ) {
44+ filename += `-${ params [ "date" ] } ` ;
45+ }
46+
47+ if ( keys . includes ( "week" ) ) {
48+ filename += `-${ params [ "week" ] } ` ;
49+ }
50+
51+ filename += `.${ format } ` ;
4852
4953 return filename ;
5054}
@@ -75,7 +79,7 @@ function __saveFeed(response, league, season, feed, format, params) {
7579 }
7680
7781 if ( this . verbose ) {
78- console . log ( " File saved as '" + this . storeLocation + filename + "'." ) ;
82+ console . log ( ` File saved as '${ this . storeLocation } ${ filename } '.` ) ;
7983 }
8084 }
8185}
@@ -114,21 +118,21 @@ var API_v1_0 = function (v, storeT, storeL) {
114118 'daily_game_schedule' ,
115119 'daily_player_stats' ,
116120 'game_boxscore' ,
117- 'scoreboard' ,
118121 'game_playbyplay' ,
119- 'player_gamelogs' ,
120- 'team_gamelogs' ,
122+ 'scoreboard' ,
121123 'roster_players' ,
122124 'game_startinglineup' ,
125+ 'player_gamelogs' ,
126+ 'team_gamelogs' ,
123127 'active_players' ,
124128 'overall_team_standings' ,
125129 'conference_team_standings' ,
126130 'division_team_standings' ,
127131 'playoff_team_standings' ,
128132 'player_injuries' ,
133+ 'latest_updates' ,
129134 'daily_dfs' ,
130135 'current_season' ,
131- 'latest_updates'
132136 ] ;
133137} ;
134138
@@ -150,9 +154,9 @@ API_v1_0.prototype.setAuthCredentials = function (apikey, password) {
150154
151155API_v1_0 . prototype . __determineUrl = function ( league , season , feed , format , params ) {
152156 if ( feed == "current_season" ) {
153- return this . baseUrl + '/' + league + '/' + feed + '.' + format ;
157+ return ` ${ this . baseUrl } / ${ league } / ${ feed } . ${ format } ` ;
154158 } else {
155- return this . baseUrl + '/' + league + '/' + season + '/' + feed + '.' + format ;
159+ return ` ${ this . baseUrl } / ${ league } / ${ season } / ${ feed } . ${ format } ` ;
156160 }
157161} ;
158162
@@ -167,17 +171,17 @@ API_v1_0.prototype.getData = function (league, season, feed, format, params = {}
167171 }
168172
169173 if ( ! __verifyFeedName . call ( this , feed ) ) {
170- throw new Error ( " Unknown feed '" + feed + " '. Known values are: [" + this . validFeeds + "]" ) ;
174+ throw new Error ( ` Unknown feed '${ feed } '. Known values are: [${ this . validFeeds } ]` ) ;
171175 }
172176
173177 if ( ! __verifyFormat . call ( this , format ) ) {
174- throw new Error ( " Unsupported format '" + format + "'." ) ;
178+ throw new Error ( ` Unsupported format '${ format } '.` ) ;
175179 }
176180
177181 var url = this . __determineUrl ( league , season , feed , format , params ) ;
178182
179183 if ( this . verbose ) {
180- console . log ( " Making API request to '" + url + "'." ) ;
184+ console . log ( ` Making API request to '${ url } '.` ) ;
181185 console . log ( " with headers:" ) ;
182186 console . log ( this . options . headers ) ;
183187 console . log ( " and params:" ) ;
@@ -208,7 +212,7 @@ API_v1_0.prototype.getData = function (league, season, feed, format, params = {}
208212 } . bind ( this ) )
209213 . catch ( function ( err ) {
210214 if ( this . verbose ) {
211- console . log ( " err = '" + util . inspect ( err , { depth : null } ) + "'" ) ;
215+ console . log ( ` err = '${ util . inspect ( err , { depth : null } ) } '` ) ;
212216 }
213217
214218 if ( err . statusCode == 304 ) { // Content hasn't changed, read from local file
@@ -238,7 +242,7 @@ API_v1_0.prototype.getData = function (league, season, feed, format, params = {}
238242
239243 deferred . resolve ( data ) ;
240244 } else {
241- throw new Error ( " API call failed with error: " + err . statusCode ) ;
245+ throw new Error ( ` API call failed with error: ${ err . statusCode } ` ) ;
242246 }
243247 } . bind ( this ) ) ;
244248
0 commit comments