@@ -6,45 +6,49 @@ var util = require('util');
6
6
var libVersion = require ( '../package.json' ) . version ;
7
7
8
8
// Private Functions
9
- function __getBaseUrl ( league , feed , format , params ) {
10
- return this . baseUrl + '/' + league + '/' + feed + '.' + format ;
11
- }
12
-
13
9
function __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
+ }
21
13
22
- return isValid ;
14
+ return this . validFeeds . includes ( feed ) ;
23
15
}
24
16
25
17
function __verifyFormat ( format ) {
26
- var isValid = true ;
27
-
28
18
// Only JSON format supported
29
- if ( format ! = 'json' ) {
30
- isValid = false ;
19
+ if ( ! format || format != = 'json' ) {
20
+ return false ;
31
21
}
32
22
33
- return isValid ;
23
+ return true ;
34
24
}
35
25
36
26
function __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
+ }
38
34
39
- if ( Object . keys ( params ) . includes ( "gameid " ) ) {
40
- filename += "-" + params [ "gameid" ] ;
35
+ if ( keys . includes ( "fordate " ) ) {
36
+ filename += `- ${ params [ "fordate" ] } ` ;
41
37
}
42
38
43
- if ( Object . keys ( params ) . includes ( "fordate " ) ) {
44
- filename += "-" + params [ "fordate" ] ;
39
+ if ( keys . includes ( "game " ) ) {
40
+ filename += `- ${ params [ "game" ] } ` ;
45
41
}
46
42
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 } ` ;
48
52
49
53
return filename ;
50
54
}
@@ -75,7 +79,7 @@ function __saveFeed(response, league, season, feed, format, params) {
75
79
}
76
80
77
81
if ( this . verbose ) {
78
- console . log ( " File saved as '" + this . storeLocation + filename + "'." ) ;
82
+ console . log ( ` File saved as '${ this . storeLocation } ${ filename } '.` ) ;
79
83
}
80
84
}
81
85
}
@@ -114,21 +118,21 @@ var API_v1_0 = function (v, storeT, storeL) {
114
118
'daily_game_schedule' ,
115
119
'daily_player_stats' ,
116
120
'game_boxscore' ,
117
- 'scoreboard' ,
118
121
'game_playbyplay' ,
119
- 'player_gamelogs' ,
120
- 'team_gamelogs' ,
122
+ 'scoreboard' ,
121
123
'roster_players' ,
122
124
'game_startinglineup' ,
125
+ 'player_gamelogs' ,
126
+ 'team_gamelogs' ,
123
127
'active_players' ,
124
128
'overall_team_standings' ,
125
129
'conference_team_standings' ,
126
130
'division_team_standings' ,
127
131
'playoff_team_standings' ,
128
132
'player_injuries' ,
133
+ 'latest_updates' ,
129
134
'daily_dfs' ,
130
135
'current_season' ,
131
- 'latest_updates'
132
136
] ;
133
137
} ;
134
138
@@ -150,9 +154,9 @@ API_v1_0.prototype.setAuthCredentials = function (apikey, password) {
150
154
151
155
API_v1_0 . prototype . __determineUrl = function ( league , season , feed , format , params ) {
152
156
if ( feed == "current_season" ) {
153
- return this . baseUrl + '/' + league + '/' + feed + '.' + format ;
157
+ return ` ${ this . baseUrl } / ${ league } / ${ feed } . ${ format } ` ;
154
158
} else {
155
- return this . baseUrl + '/' + league + '/' + season + '/' + feed + '.' + format ;
159
+ return ` ${ this . baseUrl } / ${ league } / ${ season } / ${ feed } . ${ format } ` ;
156
160
}
157
161
} ;
158
162
@@ -167,17 +171,17 @@ API_v1_0.prototype.getData = function (league, season, feed, format, params = {}
167
171
}
168
172
169
173
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 } ]` ) ;
171
175
}
172
176
173
177
if ( ! __verifyFormat . call ( this , format ) ) {
174
- throw new Error ( " Unsupported format '" + format + "'." ) ;
178
+ throw new Error ( ` Unsupported format '${ format } '.` ) ;
175
179
}
176
180
177
181
var url = this . __determineUrl ( league , season , feed , format , params ) ;
178
182
179
183
if ( this . verbose ) {
180
- console . log ( " Making API request to '" + url + "'." ) ;
184
+ console . log ( ` Making API request to '${ url } '.` ) ;
181
185
console . log ( " with headers:" ) ;
182
186
console . log ( this . options . headers ) ;
183
187
console . log ( " and params:" ) ;
@@ -208,7 +212,7 @@ API_v1_0.prototype.getData = function (league, season, feed, format, params = {}
208
212
} . bind ( this ) )
209
213
. catch ( function ( err ) {
210
214
if ( this . verbose ) {
211
- console . log ( " err = '" + util . inspect ( err , { depth : null } ) + "'" ) ;
215
+ console . log ( ` err = '${ util . inspect ( err , { depth : null } ) } '` ) ;
212
216
}
213
217
214
218
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 = {}
238
242
239
243
deferred . resolve ( data ) ;
240
244
} else {
241
- throw new Error ( " API call failed with error: " + err . statusCode ) ;
245
+ throw new Error ( ` API call failed with error: ${ err . statusCode } ` ) ;
242
246
}
243
247
} . bind ( this ) ) ;
244
248
0 commit comments