baseline_stats 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/baseline_endpoints.rb +891 -0
- data/lib/baseline_request.rb +60 -0
- data/lib/baseline_stats.rb +72 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f499ffabc01e978366b6c0f49563895758c46a4ec120c374cadad196f55f8191
|
4
|
+
data.tar.gz: ae04fe05c73b86fad3cc1e4a92f8ce0d86db3dad1d3a64a3c4ccd9e365b0f953
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 157841411039d20cbdfab6d7b686cd9653bca74a858f4d16b8e55dc1de8dfc9afbad6dce693c1f90c0f0f27553e728e97fc6a919bada07e924816d0e11906b91
|
7
|
+
data.tar.gz: e7d7585089edba17fec91be6bbd6ad2b8fa8659f56cb3add4a918016741d2fc76cce59355bf543f891428e6c4c9f4c1d89162cdcc537d71cb17e7e47b0288c43
|
@@ -0,0 +1,891 @@
|
|
1
|
+
require 'active_support/core_ext/hash'
|
2
|
+
require 'ice_nine'
|
3
|
+
require 'ice_nine/core_ext/object'
|
4
|
+
|
5
|
+
# Required params saved as two dimensional array. Each inner array is a set of params where 1 of them is required.
|
6
|
+
# field test_params is an object of parameters for each endpoint which is used when the `test_endpoints` method is called.
|
7
|
+
|
8
|
+
module BaselineEndpoints
|
9
|
+
BASE_URL = "https://statsapi.mlb.com/api/".freeze
|
10
|
+
ENDPOINTS = {
|
11
|
+
"attendance": {
|
12
|
+
"url": BASE_URL + "{ver}/attendance",
|
13
|
+
"path_params": {
|
14
|
+
"ver": {
|
15
|
+
"type": "str",
|
16
|
+
"default": "v1",
|
17
|
+
"required": true,
|
18
|
+
}
|
19
|
+
},
|
20
|
+
"query_params": %w[teamId leagueId season date leagueListId gameType fields],
|
21
|
+
"required_params": [%w[teamId leagueId leagueListId]],
|
22
|
+
"note": "Requires one of the following paramters to be present: teamId, leagueId, leagueListId.",
|
23
|
+
"test_params": {:leagueId => "103"},
|
24
|
+
},
|
25
|
+
"awards": {
|
26
|
+
"url": BASE_URL + "{ver}/awards{awardId}{recipients}",
|
27
|
+
"path_params": {
|
28
|
+
"ver": {
|
29
|
+
"type": "str",
|
30
|
+
"default": "v1",
|
31
|
+
"required": true,
|
32
|
+
},
|
33
|
+
"awardId": {
|
34
|
+
"type": "str",
|
35
|
+
"default": nil,
|
36
|
+
"leading_slash": true,
|
37
|
+
},
|
38
|
+
"recipients": {
|
39
|
+
"type": "bool",
|
40
|
+
"default": false,
|
41
|
+
"true": "/recipients",
|
42
|
+
"false": "",
|
43
|
+
},
|
44
|
+
},
|
45
|
+
"query_params": %w[sportId leagueId season hydrate fields],
|
46
|
+
"required_params": [],
|
47
|
+
"note": "Call awards endpoint with no parameters to return a list of awardIds.",
|
48
|
+
"test_params": {:season => 2023 }
|
49
|
+
},
|
50
|
+
"conferences": {
|
51
|
+
"url": BASE_URL + "{ver}/conferences",
|
52
|
+
"path_params": {
|
53
|
+
"ver": {
|
54
|
+
"type": "str",
|
55
|
+
"default": "v1",
|
56
|
+
"required": true,
|
57
|
+
}
|
58
|
+
},
|
59
|
+
"query_params": %w[conferenceId season fields],
|
60
|
+
"required_params": [],
|
61
|
+
"test_params": {},
|
62
|
+
},
|
63
|
+
"divisions": {
|
64
|
+
"url": BASE_URL + "{ver}/divisions",
|
65
|
+
"path_params": {
|
66
|
+
"ver": {
|
67
|
+
"type": "str",
|
68
|
+
"default": "v1",
|
69
|
+
"required": true,
|
70
|
+
}
|
71
|
+
},
|
72
|
+
"query_params": %w[divisionId leagueId sportId],
|
73
|
+
"required_params": [],
|
74
|
+
"note": "Call divisions endpoint with no parameters to return a list of divisions.",
|
75
|
+
"test_params": {},
|
76
|
+
},
|
77
|
+
"draft": {
|
78
|
+
"url": BASE_URL + "{ver}/draft{prospects}{year}{latest}",
|
79
|
+
"path_params": {
|
80
|
+
"ver": {
|
81
|
+
"type": "str",
|
82
|
+
"default": "v1",
|
83
|
+
"required": true,
|
84
|
+
},
|
85
|
+
"prospects": {
|
86
|
+
"type": "bool",
|
87
|
+
"default": false,
|
88
|
+
"true": "/prospects",
|
89
|
+
"false": "",
|
90
|
+
},
|
91
|
+
"year": {
|
92
|
+
"type": "str",
|
93
|
+
"default": Time.now.year.to_s,
|
94
|
+
"leading_slash": true,
|
95
|
+
"required": true,
|
96
|
+
},
|
97
|
+
"latest": {
|
98
|
+
"type": "bool",
|
99
|
+
"default": false,
|
100
|
+
"true": "/latest",
|
101
|
+
"false": "",
|
102
|
+
},
|
103
|
+
},
|
104
|
+
"query_params": %w[limit fields round name school state country position teamId playerId bisPlayerId],
|
105
|
+
"required_params": [],
|
106
|
+
"note": 'No query parameters are honored when "latest" endpoint is queried (year is still required). Prospects and Latest cannot be used together.',
|
107
|
+
"test_params": {gamePk: 718780},
|
108
|
+
},
|
109
|
+
"game": {
|
110
|
+
"url": BASE_URL + "{ver}/game/{gamePk}/feed/live",
|
111
|
+
"path_params": {
|
112
|
+
"ver": {
|
113
|
+
"type": "str",
|
114
|
+
"default": "v1.1",
|
115
|
+
"required": true,
|
116
|
+
},
|
117
|
+
"gamePk": {
|
118
|
+
"type": "str",
|
119
|
+
"default": "",
|
120
|
+
"required": true,
|
121
|
+
},
|
122
|
+
},
|
123
|
+
"query_params": %w[timecode hydrate fields],
|
124
|
+
"required_params": [],
|
125
|
+
"test_params": {gamePk: 718780},
|
126
|
+
},
|
127
|
+
"game_diff": {
|
128
|
+
"url": BASE_URL + "{ver}/game/{gamePk}/feed/live/diffPatch",
|
129
|
+
"path_params": {
|
130
|
+
"ver": {
|
131
|
+
"type": "str",
|
132
|
+
"default": "v1.1",
|
133
|
+
"required": true,
|
134
|
+
},
|
135
|
+
"gamePk": {
|
136
|
+
"type": "str",
|
137
|
+
"default": "",
|
138
|
+
"required": true,
|
139
|
+
},
|
140
|
+
},
|
141
|
+
"query_params": %w[startTimecode endTimecode],
|
142
|
+
"required_params": [["startTimecode"], ["endTimecode"]],
|
143
|
+
"note": "Use the `game_timestamps` endpoint to retrieve all timecodes for a specific game.",
|
144
|
+
"test_params": {gamePk: 718780, startTimecode: 20230330_151907, endTimecode: 20230330_201342},
|
145
|
+
},
|
146
|
+
"game_timestamps": {
|
147
|
+
"url": BASE_URL + "{ver}/game/{gamePk}/feed/live/timestamps",
|
148
|
+
"path_params": {
|
149
|
+
"ver": {
|
150
|
+
"type": "str",
|
151
|
+
"default": "v1.1",
|
152
|
+
"required": true,
|
153
|
+
},
|
154
|
+
"gamePk": {
|
155
|
+
"type": "str",
|
156
|
+
"default": "",
|
157
|
+
"required": true,
|
158
|
+
},
|
159
|
+
},
|
160
|
+
"query_params": [],
|
161
|
+
"required_params": [],
|
162
|
+
"test_params": {gamePk: 718780},
|
163
|
+
},
|
164
|
+
"game_changes": {
|
165
|
+
"url": BASE_URL + "{ver}/game/changes",
|
166
|
+
"path_params": {
|
167
|
+
"ver": {
|
168
|
+
"type": "str",
|
169
|
+
"default": "v1",
|
170
|
+
"required": true,
|
171
|
+
}
|
172
|
+
},
|
173
|
+
"query_params": %w[updatedSince sportId gameType season fields],
|
174
|
+
"required_params": [],
|
175
|
+
"test_params": {},
|
176
|
+
},
|
177
|
+
"game_context_metrics": {
|
178
|
+
"url": BASE_URL + "{ver}/game/{gamePk}/contextMetrics",
|
179
|
+
"path_params": {
|
180
|
+
"ver": {
|
181
|
+
"type": "str",
|
182
|
+
"default": "v1",
|
183
|
+
"required": true,
|
184
|
+
},
|
185
|
+
"gamePk": {
|
186
|
+
"type": "str",
|
187
|
+
"default": "",
|
188
|
+
"required": true,
|
189
|
+
},
|
190
|
+
},
|
191
|
+
"query_params": %w[timecode fields],
|
192
|
+
"required_params": [],
|
193
|
+
"test_params": {gamePk: 718780},
|
194
|
+
},
|
195
|
+
"game_win_probability": {
|
196
|
+
"url": BASE_URL + "{ver}/game/{gamePk}/winProbability",
|
197
|
+
"path_params": {
|
198
|
+
"ver": {
|
199
|
+
"type": "str",
|
200
|
+
"default": "v1",
|
201
|
+
"required": true,
|
202
|
+
},
|
203
|
+
"gamePk": {
|
204
|
+
"type": "str",
|
205
|
+
"default": "",
|
206
|
+
"required": true,
|
207
|
+
},
|
208
|
+
},
|
209
|
+
"query_params": %w[timecode fields],
|
210
|
+
"required_params": [],
|
211
|
+
"test_params": {gamePk: 718780},
|
212
|
+
},
|
213
|
+
"game_boxscore": {
|
214
|
+
"url": BASE_URL + "{ver}/game/{gamePk}/boxscore",
|
215
|
+
"path_params": {
|
216
|
+
"ver": {
|
217
|
+
"type": "str",
|
218
|
+
"default": "v1",
|
219
|
+
"required": true,
|
220
|
+
},
|
221
|
+
"gamePk": {
|
222
|
+
"type": "str",
|
223
|
+
"default": "",
|
224
|
+
"required": true,
|
225
|
+
},
|
226
|
+
},
|
227
|
+
"query_params": %w[timecode fields],
|
228
|
+
"required_params": [],
|
229
|
+
"test_params": {gamePk: 718780},
|
230
|
+
},
|
231
|
+
"game_content": {
|
232
|
+
"url": BASE_URL + "{ver}/game/{gamePk}/content",
|
233
|
+
"path_params": {
|
234
|
+
"ver": {
|
235
|
+
"type": "str",
|
236
|
+
"default": "v1",
|
237
|
+
"required": true,
|
238
|
+
},
|
239
|
+
"gamePk": {
|
240
|
+
"type": "str",
|
241
|
+
"default": "",
|
242
|
+
"required": true,
|
243
|
+
},
|
244
|
+
},
|
245
|
+
"query_params": %w[highlightLimit],
|
246
|
+
"required_params": [],
|
247
|
+
"test_params": {gamePk: 718780},
|
248
|
+
},
|
249
|
+
"game_linescore": {
|
250
|
+
"url": BASE_URL + "{ver}/game/{gamePk}/linescore",
|
251
|
+
"path_params": {
|
252
|
+
"ver": {
|
253
|
+
"type": "str",
|
254
|
+
"default": "v1",
|
255
|
+
"required": true,
|
256
|
+
},
|
257
|
+
"gamePk": {
|
258
|
+
"type": "str",
|
259
|
+
"default": "",
|
260
|
+
"required": true,
|
261
|
+
},
|
262
|
+
},
|
263
|
+
"query_params": %w[timecode fields],
|
264
|
+
"required_params": [],
|
265
|
+
"test_params": {gamePk: 718780},
|
266
|
+
},
|
267
|
+
"game_play_by_play": {
|
268
|
+
"url": BASE_URL + "{ver}/game/{gamePk}/playByPlay",
|
269
|
+
"path_params": {
|
270
|
+
"ver": {
|
271
|
+
"type": "str",
|
272
|
+
"default": "v1",
|
273
|
+
"required": true,
|
274
|
+
},
|
275
|
+
"gamePk": {
|
276
|
+
"type": "str",
|
277
|
+
"default": "",
|
278
|
+
"required": true,
|
279
|
+
},
|
280
|
+
},
|
281
|
+
"query_params": %w[timecode fields],
|
282
|
+
"required_params": [],
|
283
|
+
"test_params": {gamePk: 718780},
|
284
|
+
},
|
285
|
+
"game_pace": {
|
286
|
+
"url": BASE_URL + "{ver}/gamePace",
|
287
|
+
"path_params": {
|
288
|
+
"ver": {
|
289
|
+
"type": "str",
|
290
|
+
"default": "v1",
|
291
|
+
"required": true,
|
292
|
+
}
|
293
|
+
},
|
294
|
+
"query_params": %w[season teamIds leagueIds leagueListId sportId gameType startDate endDate venueIds orgType includeChildren fields],
|
295
|
+
"required_params": [["season"]],
|
296
|
+
"test_params": {season: 2023},
|
297
|
+
},
|
298
|
+
"high_low": {
|
299
|
+
"url": BASE_URL + "{ver}/highLow/{orgType}",
|
300
|
+
"path_params": {
|
301
|
+
"ver": {
|
302
|
+
"type": "str",
|
303
|
+
"default": "v1",
|
304
|
+
"required": true,
|
305
|
+
},
|
306
|
+
"orgType": {
|
307
|
+
"type": "str",
|
308
|
+
"default": "",
|
309
|
+
"required": true,
|
310
|
+
},
|
311
|
+
},
|
312
|
+
"query_params": %w[statGroup sortStat season gameType teamId leagueId sportIds limit fields],
|
313
|
+
"required_params": [["sortStat"], ["season"]],
|
314
|
+
"note": "Valid values for orgType parameter: player, team, division, league, sport, types.",
|
315
|
+
"test_params": {orgType: "team", sortStat: "hits", season: 2023, teamId: 158 },
|
316
|
+
},
|
317
|
+
"league": {
|
318
|
+
"url": BASE_URL + "{ver}/league",
|
319
|
+
"path_params": {
|
320
|
+
"ver": {
|
321
|
+
"type": "str",
|
322
|
+
"default": "v1",
|
323
|
+
"required": true,
|
324
|
+
}
|
325
|
+
},
|
326
|
+
"query_params": %w[sportId leagueIds seasons fields],
|
327
|
+
"required_params": [],
|
328
|
+
"test_params": {},
|
329
|
+
},
|
330
|
+
"people": {
|
331
|
+
"url": BASE_URL + "{ver}/people",
|
332
|
+
"path_params": {
|
333
|
+
"ver": {
|
334
|
+
"type": "str",
|
335
|
+
"default": "v1",
|
336
|
+
"required": true,
|
337
|
+
}
|
338
|
+
},
|
339
|
+
"query_params": %w[personIds hydrate fields],
|
340
|
+
"required_params": [["personIds"]],
|
341
|
+
"test_params": {personIds: 677594},
|
342
|
+
},
|
343
|
+
"people_changes": {
|
344
|
+
"url": BASE_URL + "{ver}/people/changes",
|
345
|
+
"path_params": {
|
346
|
+
"ver": {
|
347
|
+
"type": "str",
|
348
|
+
"default": "v1",
|
349
|
+
"required": true,
|
350
|
+
}
|
351
|
+
},
|
352
|
+
"query_params": %w[updatedSince fields],
|
353
|
+
"required_params": [["updatedSince"]],
|
354
|
+
"note": "updatedSince param is a DateTime object",
|
355
|
+
"test_params": {updatedSince: DateTime.new(2023, 9, 1)},
|
356
|
+
},
|
357
|
+
"people_free_agents": {
|
358
|
+
"url": BASE_URL + "{ver}/people/freeAgents",
|
359
|
+
"path_params": {
|
360
|
+
"ver": {
|
361
|
+
"type": "str",
|
362
|
+
"default": "v1",
|
363
|
+
"required": true,
|
364
|
+
},
|
365
|
+
"leagueId": {
|
366
|
+
"type": "str",
|
367
|
+
"default": "",
|
368
|
+
"required": true,
|
369
|
+
},
|
370
|
+
},
|
371
|
+
"query_params": %w[order hydrate fields season],
|
372
|
+
"required_params": [["season"]],
|
373
|
+
"test_params": {leagueId: 103, season: 2023},
|
374
|
+
},
|
375
|
+
"person": {
|
376
|
+
"url": BASE_URL + "{ver}/people/{personId}",
|
377
|
+
"path_params": {
|
378
|
+
"ver": {
|
379
|
+
"type": "str",
|
380
|
+
"default": "v1",
|
381
|
+
"required": true,
|
382
|
+
},
|
383
|
+
"personId": {
|
384
|
+
"type": "str",
|
385
|
+
"default": nil,
|
386
|
+
"required": true,
|
387
|
+
},
|
388
|
+
},
|
389
|
+
"query_params": %w[hydrate fields],
|
390
|
+
"required_params": [],
|
391
|
+
"test_params": {personId: 677594},
|
392
|
+
},
|
393
|
+
"person_stats": {
|
394
|
+
"url": BASE_URL + "{ver}/people/{personId}/stats",
|
395
|
+
"path_params": {
|
396
|
+
"ver": {
|
397
|
+
"type": "str",
|
398
|
+
"default": "v1",
|
399
|
+
"required": true,
|
400
|
+
},
|
401
|
+
"personId": {
|
402
|
+
"type": "str",
|
403
|
+
"default": nil,
|
404
|
+
"required": true,
|
405
|
+
},
|
406
|
+
},
|
407
|
+
"query_params": %w[fields stats],
|
408
|
+
"required_params": [["stats"]],
|
409
|
+
"note": "Valid values for stats include `season` and `career`",
|
410
|
+
"test_params": {personId: 677594, stats: 'season'},
|
411
|
+
},
|
412
|
+
"person_game_stats": {
|
413
|
+
"url": BASE_URL + "{ver}/people/{personId}/stats/game/{gamePk}",
|
414
|
+
"path_params": {
|
415
|
+
"ver": {
|
416
|
+
"type": "str",
|
417
|
+
"default": "v1",
|
418
|
+
"required": true,
|
419
|
+
},
|
420
|
+
"personId": {
|
421
|
+
"type": "str",
|
422
|
+
"default": nil,
|
423
|
+
"required": true,
|
424
|
+
},
|
425
|
+
"gamePk": {
|
426
|
+
"type": "str",
|
427
|
+
"default": "current",
|
428
|
+
"required": true,
|
429
|
+
},
|
430
|
+
},
|
431
|
+
"query_params": %[fields],
|
432
|
+
"required_params": [],
|
433
|
+
"note": "gamePk will default to `current` which will retrieve stats for the current game the player is playing in, if any.",
|
434
|
+
"test_params": {personId: 677594, gamePk: 716360},
|
435
|
+
},
|
436
|
+
"jobs": {
|
437
|
+
"url": BASE_URL + "{ver}/jobs",
|
438
|
+
"path_params": {
|
439
|
+
"ver": {
|
440
|
+
"type": "str",
|
441
|
+
"default": "v1",
|
442
|
+
"required": true,
|
443
|
+
}
|
444
|
+
},
|
445
|
+
"query_params": %w[jobType sportId date fields],
|
446
|
+
"required_params": [["jobType"]],
|
447
|
+
"note": "Valid values for jobType are `UMPR`, `MSTR`, `SCOR`",
|
448
|
+
"test_params": {jobType: "UMPR"},
|
449
|
+
},
|
450
|
+
"jobs_umpires": {
|
451
|
+
"url": BASE_URL + "{ver}/jobs/umpires",
|
452
|
+
"path_params": {
|
453
|
+
"ver": {
|
454
|
+
"type": "str",
|
455
|
+
"default": "v1",
|
456
|
+
"required": true,
|
457
|
+
}
|
458
|
+
},
|
459
|
+
"query_params": %w[sportId date fields],
|
460
|
+
"required_params": [],
|
461
|
+
"test_params": {},
|
462
|
+
},
|
463
|
+
"jobs_datacasters": {
|
464
|
+
"url": BASE_URL + "{ver}/jobs/datacasters",
|
465
|
+
"path_params": {
|
466
|
+
"ver": {
|
467
|
+
"type": "str",
|
468
|
+
"default": "v1",
|
469
|
+
"required": true,
|
470
|
+
}
|
471
|
+
},
|
472
|
+
"query_params": %w[sportId date fields],
|
473
|
+
"required_params": [],
|
474
|
+
"test_params": {},
|
475
|
+
},
|
476
|
+
"jobs_official_scorers": {
|
477
|
+
"url": BASE_URL + "{ver}/jobs/officialScorers",
|
478
|
+
"path_params": {
|
479
|
+
"ver": {
|
480
|
+
"type": "str",
|
481
|
+
"default": "v1",
|
482
|
+
"required": true,
|
483
|
+
}
|
484
|
+
},
|
485
|
+
"query_params": %w[timecode fields],
|
486
|
+
"required_params": [],
|
487
|
+
"test_params": {},
|
488
|
+
},
|
489
|
+
"schedule": {
|
490
|
+
"url": BASE_URL + "{ver}/schedule",
|
491
|
+
"path_params": {
|
492
|
+
"ver": {
|
493
|
+
"type": "str",
|
494
|
+
"default": "v1",
|
495
|
+
"required": true,
|
496
|
+
}
|
497
|
+
},
|
498
|
+
"query_params": %w[scheduleType eventTypes hydrate teamId leagueId sportId gamePk gamePks venueIds gameTypes date startDate endDate opponentId fields],
|
499
|
+
"required_params": [%w[sportId gamePk gamePks]],
|
500
|
+
"test_params": {sportId: 1, startDate: "2023-03-29", endDate: "2023-10-02"},
|
501
|
+
},
|
502
|
+
"schedule_tied": {
|
503
|
+
"url": BASE_URL + "{ver}/schedule/games/tied",
|
504
|
+
"path_params": {
|
505
|
+
"ver": {
|
506
|
+
"type": "str",
|
507
|
+
"default": "v1",
|
508
|
+
"required": true,
|
509
|
+
}
|
510
|
+
},
|
511
|
+
"query_params": %w[gameTypes season hydrate fields],
|
512
|
+
"required_params": [["season"]],
|
513
|
+
"test_params": {season: 2023},
|
514
|
+
},
|
515
|
+
"schedule_postseason": {
|
516
|
+
"url": BASE_URL + "{ver}/schedule/postseason",
|
517
|
+
"path_params": {
|
518
|
+
"ver": {
|
519
|
+
"type": "str",
|
520
|
+
"default": "v1",
|
521
|
+
"required": true,
|
522
|
+
}
|
523
|
+
},
|
524
|
+
"query_params": %w[gameTypes seriesNumber teamId sportId season hydrate fields],
|
525
|
+
"required_params": [],
|
526
|
+
"test_params": {},
|
527
|
+
},
|
528
|
+
"schedule_postseason_series": {
|
529
|
+
"url": BASE_URL + "{ver}/schedule/postseason/series",
|
530
|
+
"path_params": {
|
531
|
+
"ver": {
|
532
|
+
"type": "str",
|
533
|
+
"default": "v1",
|
534
|
+
"required": true,
|
535
|
+
}
|
536
|
+
},
|
537
|
+
"query_params": %w[gameTypes seriesNumber teamId sportId season fields],
|
538
|
+
"required_params": [],
|
539
|
+
"test_params": {},
|
540
|
+
},
|
541
|
+
"schedule_postseason_tune_in": {
|
542
|
+
"url": BASE_URL + "{ver}/schedule/postseason/tuneIn",
|
543
|
+
"path_params": {
|
544
|
+
"ver": {
|
545
|
+
"type": "str",
|
546
|
+
"default": "v1",
|
547
|
+
"required": true,
|
548
|
+
}
|
549
|
+
},
|
550
|
+
"query_params": %w[teamId sportId season hydrate fields],
|
551
|
+
"required_params": [],
|
552
|
+
"test_params": {},
|
553
|
+
},
|
554
|
+
"seasons": {
|
555
|
+
"url": BASE_URL + "{ver}/seasons{all}",
|
556
|
+
"path_params": {
|
557
|
+
"ver": {
|
558
|
+
"type": "str",
|
559
|
+
"default": "v1",
|
560
|
+
"required": true,
|
561
|
+
},
|
562
|
+
"all": {
|
563
|
+
"type": "bool",
|
564
|
+
"default": false,
|
565
|
+
"true": "/all",
|
566
|
+
"false": "",
|
567
|
+
"required": false,
|
568
|
+
},
|
569
|
+
},
|
570
|
+
"query_params": %w[season sportId divisionId leagueId fields],
|
571
|
+
"required_params": [%w[sportId divisionId leagueId]],
|
572
|
+
"note": "Use the `all` path parameter to retrieve data for all seasons. The `sportId`, `divisionId`, and `leagueId` params are respected even when the `all` param is used.",
|
573
|
+
"test_params": {sportId: 1},
|
574
|
+
},
|
575
|
+
"season": {
|
576
|
+
"url": BASE_URL + "{ver}/seasons/{season}",
|
577
|
+
"path_params": {
|
578
|
+
"ver": {
|
579
|
+
"type": "str",
|
580
|
+
"default": "v1",
|
581
|
+
"required": true,
|
582
|
+
},
|
583
|
+
"season": {
|
584
|
+
"type": "str",
|
585
|
+
"default": false,
|
586
|
+
"required": true,
|
587
|
+
},
|
588
|
+
},
|
589
|
+
"query_params": %w[sportId fields],
|
590
|
+
"required_params": [["sportId"]],
|
591
|
+
"test_params": {sportId: 1, season: 2023},
|
592
|
+
},
|
593
|
+
"sports": {
|
594
|
+
"url": BASE_URL + "{ver}/sports",
|
595
|
+
"path_params": {
|
596
|
+
"ver": {
|
597
|
+
"type": "str",
|
598
|
+
"default": "v1",
|
599
|
+
"required": true,
|
600
|
+
}
|
601
|
+
},
|
602
|
+
"query_params": %w[sportId fields],
|
603
|
+
"required_params": [],
|
604
|
+
"test_params": {},
|
605
|
+
},
|
606
|
+
"sports_players": {
|
607
|
+
"url": BASE_URL + "{ver}/sports/{sportId}/players",
|
608
|
+
"path_params": {
|
609
|
+
"ver": {
|
610
|
+
"type": "str",
|
611
|
+
"default": "v1",
|
612
|
+
"required": true,
|
613
|
+
},
|
614
|
+
"sportId": {
|
615
|
+
"type": "str",
|
616
|
+
"default": "1",
|
617
|
+
"required": true,
|
618
|
+
},
|
619
|
+
},
|
620
|
+
"query_params": %w[season gameType fields],
|
621
|
+
"required_params": [["season"]],
|
622
|
+
"test_params": {season: 2023},
|
623
|
+
},
|
624
|
+
"standings": {
|
625
|
+
"url": BASE_URL + "{ver}/standings",
|
626
|
+
"path_params": {
|
627
|
+
"ver": {
|
628
|
+
"type": "str",
|
629
|
+
"default": "v1",
|
630
|
+
"required": true,
|
631
|
+
}
|
632
|
+
},
|
633
|
+
"query_params": %w[leagueId season standingsTypes date hydrate fields],
|
634
|
+
"required_params": [["leagueId"]],
|
635
|
+
"test_params": {leagueId: 103},
|
636
|
+
},
|
637
|
+
"stats": {
|
638
|
+
"url": BASE_URL + "{ver}/stats",
|
639
|
+
"path_params": {
|
640
|
+
"ver": {
|
641
|
+
"type": "str",
|
642
|
+
"default": "v1",
|
643
|
+
"required": true,
|
644
|
+
}
|
645
|
+
},
|
646
|
+
"query_params": %w[stats playerPool position teamId leagueId limit offset group gameType season sportIds sortStat order hydrate fields personId metrics],
|
647
|
+
"required_params": [["stats", "group"]],
|
648
|
+
"note": "Limit defaults to 50 records. `stats` field can be `season` or `career`; `group` can be `hitting`, `pitching`, or `fielding`.",
|
649
|
+
"test_params": {stats: "season", group: "hitting"},
|
650
|
+
},
|
651
|
+
"stats_leaders": {
|
652
|
+
"url": BASE_URL + "{ver}/stats/leaders",
|
653
|
+
"path_params": {
|
654
|
+
"ver": {
|
655
|
+
"type": "str",
|
656
|
+
"default": "v1",
|
657
|
+
"required": true,
|
658
|
+
}
|
659
|
+
},
|
660
|
+
"query_params": %w[leaderCategories playerPool leaderGameTypes statGroup season leagueId sportId hydrate limit fields statType],
|
661
|
+
"required_params": [["leaderCategories"]],
|
662
|
+
"note": "If excluding season parameter to get all time leaders, include statType=statsSingleSeason or you will likely not get any results.",
|
663
|
+
"test_params": {leaderCategories: "runs", season: 2023, statGroup: "hitting"},
|
664
|
+
},
|
665
|
+
"teams": {
|
666
|
+
"url": BASE_URL + "{ver}/teams",
|
667
|
+
"path_params": {
|
668
|
+
"ver": {
|
669
|
+
"type": "str",
|
670
|
+
"default": "v1",
|
671
|
+
"required": true,
|
672
|
+
}
|
673
|
+
},
|
674
|
+
"query_params": %w[season activeStatus leagueIds sportId sportIds gameType hydrate fields],
|
675
|
+
"required_params": [],
|
676
|
+
"test_params": {leagueIds: [103, 104]},
|
677
|
+
},
|
678
|
+
"teams_history": {
|
679
|
+
"url": BASE_URL + "{ver}/teams/history",
|
680
|
+
"path_params": {
|
681
|
+
"ver": {
|
682
|
+
"type": "str",
|
683
|
+
"default": "v1",
|
684
|
+
"required": true,
|
685
|
+
}
|
686
|
+
},
|
687
|
+
"query_params": %w[teamIds startSeason endSeason fields],
|
688
|
+
"required_params": [%w[teamIds]],
|
689
|
+
"test_params": {teamIds: 158},
|
690
|
+
},
|
691
|
+
"teams_stats": {
|
692
|
+
"url": BASE_URL + "{ver}/teams/stats",
|
693
|
+
"path_params": {
|
694
|
+
"ver": {
|
695
|
+
"type": "str",
|
696
|
+
"default": "v1",
|
697
|
+
"required": true,
|
698
|
+
}
|
699
|
+
},
|
700
|
+
"query_params": %w[season sportIds group gameType stats order sortStat fields startDate endDate],
|
701
|
+
"required_params": [%w[season group stats]],
|
702
|
+
"note": "Use meta('statGroups') to look up valid values for group, and meta('statTypes') for valid values for stats.",
|
703
|
+
"test_params": {season: 2023, group: "hitting", sortStat: "runs"},
|
704
|
+
},
|
705
|
+
"teams_affiliates": {
|
706
|
+
"url": BASE_URL + "{ver}/teams/affiliates",
|
707
|
+
"path_params": {
|
708
|
+
"ver": {
|
709
|
+
"type": "str",
|
710
|
+
"default": "v1",
|
711
|
+
"required": true,
|
712
|
+
}
|
713
|
+
},
|
714
|
+
"query_params": %w[teamIds sportId season hydrate fields],
|
715
|
+
"required_params": [["teamIds"]],
|
716
|
+
"test_params": {teamIds: 158},
|
717
|
+
},
|
718
|
+
"team": {
|
719
|
+
"url": BASE_URL + "{ver}/teams/{teamId}",
|
720
|
+
"path_params": {
|
721
|
+
"ver": {
|
722
|
+
"type": "str",
|
723
|
+
"default": "v1",
|
724
|
+
"required": true,
|
725
|
+
},
|
726
|
+
"teamId": {
|
727
|
+
"type": "str",
|
728
|
+
"default": nil,
|
729
|
+
"required": true,
|
730
|
+
},
|
731
|
+
},
|
732
|
+
"query_params": %w[season sportId hydrate fields],
|
733
|
+
"required_params": [],
|
734
|
+
"test_params": {teamId: 158},
|
735
|
+
},
|
736
|
+
"team_alumni": {
|
737
|
+
"url": BASE_URL + "{ver}/teams/{teamId}/alumni",
|
738
|
+
"path_params": {
|
739
|
+
"ver": {
|
740
|
+
"type": "str",
|
741
|
+
"default": "v1",
|
742
|
+
"required": true,
|
743
|
+
},
|
744
|
+
"teamId": {
|
745
|
+
"type": "str",
|
746
|
+
"default": nil,
|
747
|
+
"required": true,
|
748
|
+
},
|
749
|
+
},
|
750
|
+
"query_params": %w[season group hydrate fields],
|
751
|
+
"required_params": [["season", "group"]],
|
752
|
+
"test_params": {teamId: 158, season: 2023},
|
753
|
+
},
|
754
|
+
"team_coaches": {
|
755
|
+
"url": BASE_URL + "{ver}/teams/{teamId}/coaches",
|
756
|
+
"path_params": {
|
757
|
+
"ver": {
|
758
|
+
"type": "str",
|
759
|
+
"default": "v1",
|
760
|
+
"required": true,
|
761
|
+
},
|
762
|
+
"teamId": {
|
763
|
+
"type": "str",
|
764
|
+
"default": nil,
|
765
|
+
"required": true,
|
766
|
+
},
|
767
|
+
},
|
768
|
+
"query_params": %w[season date fields],
|
769
|
+
"required_params": [],
|
770
|
+
"test_params": {teamId: 158},
|
771
|
+
},
|
772
|
+
"team_personnel": {
|
773
|
+
"url": BASE_URL + "{ver}/teams/{teamId}/personnel",
|
774
|
+
"path_params": {
|
775
|
+
"ver": {
|
776
|
+
"type": "str",
|
777
|
+
"default": "v1",
|
778
|
+
"required": true,
|
779
|
+
},
|
780
|
+
"teamId": {
|
781
|
+
"type": "str",
|
782
|
+
"default": nil,
|
783
|
+
"required": true,
|
784
|
+
},
|
785
|
+
},
|
786
|
+
"query_params": %w[date fields],
|
787
|
+
"required_params": [],
|
788
|
+
"test_params": {teamId: 158},
|
789
|
+
},
|
790
|
+
"team_leaders": {
|
791
|
+
"url": BASE_URL + "{ver}/teams/{teamId}/leaders",
|
792
|
+
"path_params": {
|
793
|
+
"ver": {
|
794
|
+
"type": "str",
|
795
|
+
"default": "v1",
|
796
|
+
"required": true,
|
797
|
+
},
|
798
|
+
"teamId": {
|
799
|
+
"type": "str",
|
800
|
+
"default": nil,
|
801
|
+
"required": true,
|
802
|
+
},
|
803
|
+
},
|
804
|
+
"query_params": %w[leaderCategories season leaderGameTypes hydrate limit fields],
|
805
|
+
"required_params": [%w[leaderCategories season]],
|
806
|
+
"test_params": {teamId: 158, season: 2023, leaderCategories: "hits"},
|
807
|
+
},
|
808
|
+
"team_roster": {
|
809
|
+
"url": BASE_URL + "{ver}/teams/{teamId}/roster",
|
810
|
+
"path_params": {
|
811
|
+
"ver": {
|
812
|
+
"type": "str",
|
813
|
+
"default": "v1",
|
814
|
+
"required": true,
|
815
|
+
},
|
816
|
+
"teamId": {
|
817
|
+
"type": "str",
|
818
|
+
"default": nil,
|
819
|
+
"required": true,
|
820
|
+
},
|
821
|
+
},
|
822
|
+
"query_params": %w[rosterType season date hydrate fields],
|
823
|
+
"required_params": [],
|
824
|
+
"test_params": {teamId: 158},
|
825
|
+
},
|
826
|
+
"team_stats": {
|
827
|
+
"url": BASE_URL + "{ver}/teams/{teamId}/stats",
|
828
|
+
"path_params": {
|
829
|
+
"ver": {
|
830
|
+
"type": "str",
|
831
|
+
"default": "v1",
|
832
|
+
"required": true,
|
833
|
+
},
|
834
|
+
"teamId": {
|
835
|
+
"type": "str",
|
836
|
+
"default": nil,
|
837
|
+
"required": true,
|
838
|
+
},
|
839
|
+
},
|
840
|
+
"query_params": %w[season group gameType stats sportIds sitCodes fields],
|
841
|
+
"required_params": [%w[group]],
|
842
|
+
"note": "Valid endpoint, but have not been able to retrieve anything but an empty object. Use meta('statGroups') to look up valid values for group, and meta('situationCodes') for valid values for sitCodes. Use sitCodes with stats=statSplits.",
|
843
|
+
"test_params": {teamId: 158, season: 2023, group: "hitting", stats: "statSplits"},
|
844
|
+
},
|
845
|
+
"transactions": {
|
846
|
+
"url": BASE_URL + "{ver}/transactions",
|
847
|
+
"path_params": {
|
848
|
+
"ver": {
|
849
|
+
"type": "str",
|
850
|
+
"default": "v1",
|
851
|
+
"required": true,
|
852
|
+
}
|
853
|
+
},
|
854
|
+
"query_params": %w[teamId playerId date startDate endDate sportId fields],
|
855
|
+
"required_params": [%w[teamId playerId date startDate endDate]],
|
856
|
+
"test_params": {teamId: 158},
|
857
|
+
},
|
858
|
+
"venue": {
|
859
|
+
"url": BASE_URL + "{ver}/venues",
|
860
|
+
"path_params": {
|
861
|
+
"ver": {
|
862
|
+
"type": "str",
|
863
|
+
"default": "v1",
|
864
|
+
"required": true,
|
865
|
+
}
|
866
|
+
},
|
867
|
+
"query_params": %w[venueIds season hydrate fields],
|
868
|
+
"required_params": [%w[venueIds]],
|
869
|
+
"test_params": {venueIds: 32},
|
870
|
+
},
|
871
|
+
"meta": {
|
872
|
+
"url": BASE_URL + "{ver}/{type}",
|
873
|
+
"path_params": {
|
874
|
+
"ver": {
|
875
|
+
"type": "str",
|
876
|
+
"default": "v1",
|
877
|
+
"required": true,
|
878
|
+
},
|
879
|
+
"type": {
|
880
|
+
"type": "str",
|
881
|
+
"default": nil,
|
882
|
+
"required": true,
|
883
|
+
},
|
884
|
+
},
|
885
|
+
"query_params": [],
|
886
|
+
"required_params": [],
|
887
|
+
"note": "Retrieves valid values for various parameters used in other endpoints. Available types: awards, baseballStats, eventTypes, gameStatus, gameTypes, hitTrajectories, jobTypes, languages, leagueLeaderTypes, logicalEvents, metrics, pitchCodes, pitchTypes, platforms, positions, reviewReasons, rosterTypes, scheduleEventTypes, situationCodes, sky, standingsTypes, statGroups, statTypes, windDirection.",
|
888
|
+
"test_params": {type: "baseballStats"},
|
889
|
+
}
|
890
|
+
}.with_indifferent_access.deep_freeze
|
891
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class BaselineRequest
|
2
|
+
include BaselineEndpoints
|
3
|
+
|
4
|
+
attr_accessor :endpoint, :uri, :options, :parameters
|
5
|
+
def initialize(endpoint, options = {})
|
6
|
+
raise "#{endpoint} is not a valid endpoint" unless ENDPOINTS[endpoint]
|
7
|
+
@endpoint = endpoint
|
8
|
+
@api_info = ENDPOINTS[@endpoint]
|
9
|
+
@options = options.with_indifferent_access
|
10
|
+
end
|
11
|
+
|
12
|
+
def test
|
13
|
+
@options = @api_info[:test_params]
|
14
|
+
call_api
|
15
|
+
end
|
16
|
+
|
17
|
+
def info
|
18
|
+
@api_info
|
19
|
+
end
|
20
|
+
|
21
|
+
def call_api
|
22
|
+
path, error_array = construct_path
|
23
|
+
query = @options.slice(*@api_info[:query_params])
|
24
|
+
@api_info[:required_params].each do |req_group|
|
25
|
+
error_array << "Missing one of the following required parameters: #{req_group.to_s}" unless req_group.any? {query.keys.include? _1 }
|
26
|
+
end
|
27
|
+
|
28
|
+
return error_array unless error_array.empty?
|
29
|
+
HTTParty.get(path, {:query => query})
|
30
|
+
end
|
31
|
+
|
32
|
+
def construct_path
|
33
|
+
error_array = []
|
34
|
+
url = @api_info[:url].dup
|
35
|
+
@api_info[:path_params].each do |path_key, value|
|
36
|
+
case value[:type]
|
37
|
+
when "bool"
|
38
|
+
path_value = value[@options[path_key].to_s] || value[value[:default].to_s]
|
39
|
+
else
|
40
|
+
path_value = @options[path_key] || value[:default]
|
41
|
+
end
|
42
|
+
error_array << "Missing required path parameter: #{path_key}" if value[:required] && path_value.blank?
|
43
|
+
path_value = path_value.to_s
|
44
|
+
path_value = "/" + path_value if path_value.present? && value[:leading_slash]
|
45
|
+
url.sub! "{#{path_key}}", path_value
|
46
|
+
end
|
47
|
+
|
48
|
+
[url, error_array]
|
49
|
+
end
|
50
|
+
|
51
|
+
def params
|
52
|
+
@api_info[:query_params] + @api_info[:path_params].keys
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_option(key, value, overwrite = true)
|
56
|
+
raise "#{key} not a valid parameter for #{@endpoint} endpoint" unless params.include? key
|
57
|
+
@options[key] = overwrite ? value : @options[key] || value
|
58
|
+
self
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'baseline_endpoints'
|
3
|
+
require 'active_support/core_ext/hash'
|
4
|
+
require 'date'
|
5
|
+
require 'baseline_request'
|
6
|
+
|
7
|
+
class Baseline
|
8
|
+
include BaselineEndpoints
|
9
|
+
|
10
|
+
|
11
|
+
MLB_LEAGUE_IDS = [103, 104].freeze
|
12
|
+
def self.team_list(options = {"leagueIds" => MLB_LEAGUE_IDS})
|
13
|
+
Baseline.teams(options).call_api
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.team_player_list(options = {})
|
17
|
+
Baseline.team_roster(options).call_api
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.all_player_list(options = {})
|
21
|
+
BaselineRequest.sports_players(options)
|
22
|
+
.set_option("sportId", 1, false)
|
23
|
+
.set_option("season", Time.now.year, false).call_api
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.schedule_year(year, options = {})
|
27
|
+
request = BaselineRequest.schedule(options)
|
28
|
+
.set_option("sportId", 1, false)
|
29
|
+
.set_option("startDate", "#{year}-03-29")
|
30
|
+
.set_option("endDate", "#{year}-10-02")
|
31
|
+
|
32
|
+
request.call_api["dates"].inject([]) do |result, day|
|
33
|
+
result += day["games"]
|
34
|
+
result
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.game_at_bats(game_id, options = {})
|
39
|
+
api_response = BaselineRequest.game_play_by_play(options).set_option("gamePk", game_id).call_api
|
40
|
+
api_response['allPlays'].filter{_1["result"]["type"] == "atBat"}
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.player_stats(player_id, options = {})
|
44
|
+
BaselineRequest.person_stats(options)
|
45
|
+
.set_option("personId", player_id)
|
46
|
+
.set_option("stats", "season", false).call_api
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.player_info(player_id, options = {})
|
50
|
+
BaselineRequest.person(options).set_option("personId", player_id).call_api
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.test_endpoints
|
54
|
+
ENDPOINTS.keys.inject({errors: []}) do |results, key|
|
55
|
+
response = BaselineRequest.new(key).test
|
56
|
+
code = response.code
|
57
|
+
results[:errors] << "#{key}: #{code}" unless code.to_s == "200"
|
58
|
+
# Add slight delay to make sure statcast api rate limit isn't hit.
|
59
|
+
sleep (0.1)
|
60
|
+
results[key] = "#{response.request.uri}: #{response.code}"
|
61
|
+
results
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.all_endpoints
|
66
|
+
ENDPOINTS.keys
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.method_missing(m, *args)
|
70
|
+
BaselineRequest.new(m, *args)
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: baseline_stats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Woodard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby wrapper for interacting with the Statcast baseball api.
|
14
|
+
email: mat.james.woodard@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/baseline_endpoints.rb
|
20
|
+
- lib/baseline_request.rb
|
21
|
+
- lib/baseline_stats.rb
|
22
|
+
homepage: https://github.com/InsomniMatt/baseline_stats
|
23
|
+
licenses: []
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.1.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Baseball stats through Statcast.
|
44
|
+
test_files: []
|