gameday_api 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,245 @@
1
+ require 'gameday_remote_fetcher'
2
+ require 'gameday_local_fetcher'
3
+
4
+
5
+ # This class is responsible for retrieving the Gameday files.
6
+ # It uses either a remote or a local fetcher to get the files from a
7
+ # remote server or the local file system.
8
+ #
9
+ # The files that can be fetched using this class:
10
+ #
11
+ ##### THESE FILES ARE ASSOCIATED WITH A SPECIFIC DATE
12
+ # epg.xml
13
+ # master_scoreboard.xml
14
+ # media/highlights.xml
15
+ #
16
+ ##### HTML PAGES THAT CAN BE RETRIEVED
17
+ # games page => this page lists all games for the selected date
18
+ # batters page => this page lists all batter files for the selected game
19
+ # pitchers page => this page lists all pitcher files for the selected game
20
+ #
21
+ ##### FILES THAT ARE ASSOCIATED WITH A SPECIFIC GAME IDENTIFIED BY A GID ##############
22
+ # bench.xml
23
+ # benchO.xml
24
+ # boxscore.xml
25
+ # emailSource.xml
26
+ # eventLog.xml
27
+ # game.xml
28
+ # game_events.xml
29
+ # gamecenter.xml
30
+ # gameday_Syn.xml
31
+ # linescore.xml
32
+ # miniscoreboard.xml
33
+ # players.xml
34
+ # plays.xml
35
+ #
36
+ # batters/(pid).xml
37
+ # pitchers/(pid).xml
38
+ #
39
+ # inning/inning_X.xml
40
+ # inning/inning_Scores.xml
41
+ # inning/inning_hit.xml
42
+ #
43
+ # onbase/linescore.xml
44
+ # onbase/plays.xml
45
+ #
46
+ # media/highlights.xml
47
+ # media/mobile.xml
48
+ #
49
+ # notifications/notifications_X.xml where X is an inning number
50
+ # notifications/notifications_full.xml
51
+ #
52
+ class GamedayFetcher
53
+
54
+ # LOCAL OR REMOTE CONFIG IS NOW SET IN THE gameday_config.yml file
55
+ # DO NOT MODIFY THIS
56
+ # Uncomment the fetcher that you want to use
57
+ # GamedayRemoteFetcher - gets data from remote url
58
+ # GamedayLocalFetcher - gets data from locally stored files
59
+ #def self.fetcher
60
+ # GamedayRemoteFetcher
61
+ #GamedayLocalFetcher
62
+ #end
63
+
64
+
65
+ def self.fetch_epg(year, month, day)
66
+ GamedayUtil.fetcher.fetch_epg(year, month, day)
67
+ end
68
+
69
+
70
+ # Fetch the master scoreboard file
71
+ # Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/master_scoreboard.xml
72
+ def self.fetch_scoreboard(year, month, day)
73
+ GamedayUtil.fetcher.fetch_scoreboard(year, month, day)
74
+ end
75
+
76
+
77
+ def self.fetch_day_highlights(year, month, day)
78
+ GamedayUtil.fetcher.fetch_day_highlights(year, month, day)
79
+ end
80
+
81
+
82
+ # Fetch the bench.xml file
83
+ # Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/bench.xml
84
+ def self.fetch_bench(gid)
85
+ GamedayUtil.fetcher.fetch_bench(gid)
86
+ end
87
+
88
+
89
+ # Fetch the benchO.xml file
90
+ # Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/benchO.xml
91
+ def self.fetch_bencho(gid)
92
+ GamedayUtil.fetcher.fetch_bencho(gid)
93
+ end
94
+
95
+
96
+ # Fetches the boxscore.xml file and returns its contents
97
+ # Sample URL: http://gd2.mlb.com/components/game/mlb/year_2009/month_05/day_08/gid_2009_05_08_detmlb_clemlb_1/boxscore.xml
98
+ def self.fetch_boxscore(gid)
99
+ GamedayUtil.fetcher.fetch_boxscore(gid)
100
+ end
101
+
102
+
103
+ # Fetch the emailSource.xml file
104
+ # Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/emailSource.xml
105
+ def self.fetch_emailsource(gid)
106
+ GamedayUtil.fetcher.fetch_emailsource(gid)
107
+ end
108
+
109
+
110
+ # Fetches the eventLog.xml file and returns its contents
111
+ # Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_flomlb_wasmlb_1/eventLog.xml
112
+ def self.fetch_eventlog(gid)
113
+ GamedayUtil.fetcher.fetch_eventlog(gid)
114
+ end
115
+
116
+
117
+ # Fetches the game.xml file and returns its contents
118
+ def self.fetch_game_xml(gid)
119
+ GamedayUtil.fetcher.fetch_game_xml(gid)
120
+ end
121
+
122
+
123
+ def self.fetch_game_events(gid)
124
+ GamedayUtil.fetcher.fetch_game_events(gid)
125
+ end
126
+
127
+
128
+ # Fetches the gamecenter.xml file and returns its contents
129
+ def self.fetch_gamecenter_xml(gid)
130
+ GamedayUtil.fetcher.fetch_gamecenter_xml(gid)
131
+ end
132
+
133
+
134
+ # Fetch the gameday_Syn.xml file
135
+ # Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/gameday_Syn.xml
136
+ def self.fetch_gamedaysyn(gid)
137
+ GamedayUtil.fetcher.fetch_gamedaysyn(gid)
138
+ end
139
+
140
+
141
+ # Fetch the linescore.xml file
142
+ # Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/linescore.xml
143
+ def self.fetch_linescore(gid)
144
+ GamedayUtil.fetcher.fetch_linescore(gid)
145
+ end
146
+
147
+
148
+ # Fetch the miniscoreboard.xml file
149
+ # Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/miniscoreboard.xml
150
+ def self.fetch_miniscoreboard(gid)
151
+ GamedayUtil.fetcher.fetch_miniscoreboard(gid)
152
+ end
153
+
154
+
155
+ # Fetches the players.xml file and returns its contents
156
+ def self.fetch_players(gid)
157
+ GamedayUtil.fetcher.fetch_players(gid)
158
+ end
159
+
160
+
161
+ # Fetch the plays.xml file
162
+ # Sample URL: http://gd2.mlb.com/components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/plays.xml
163
+ def self.fetch_plays(gid)
164
+ GamedayUtil.fetcher.fetch_plays(gid)
165
+ end
166
+
167
+
168
+ # Fetches the batters/(pid).xml file
169
+ def self.fetch_batter(gid, pid)
170
+ GamedayUtil.fetcher.fetch_batter(gid, pid)
171
+ end
172
+
173
+
174
+ # Fetches the pitchers/(pid).xml file
175
+ def self.fetch_pitcher(gid, pid)
176
+ GamedayUtil.fetcher.fetch_pitcher(gid, pid)
177
+ end
178
+
179
+ # inning/inning_X.xml
180
+ def self.fetch_inningx(gid, inning_num)
181
+ GamedayUtil.fetcher.fetch_inningx(gid, inning_num)
182
+ end
183
+
184
+
185
+ # inning/inning_Score.xml
186
+ def self.fetch_inning_scores(gid)
187
+ GamedayUtil.fetcher.fetch_inning_scores(gid)
188
+ end
189
+
190
+
191
+ # inning/inning_hit.xml
192
+ def self.fetch_inning_hit(gid)
193
+ GamedayUtil.fetcher.fetch_inning_hit(gid)
194
+ end
195
+
196
+
197
+ # Fetches the HTML page that lists all games for the specified date
198
+ def self.fetch_games_page(year, month, day)
199
+ GamedayUtil.fetcher.fetch_games_page(year, month, day)
200
+ end
201
+
202
+
203
+ # Fetches the HTML page that lists all games for the specified date
204
+ def self.fetch_batters_page(gid)
205
+ GamedayUtil.fetcher.fetch_batters_page(gid)
206
+ end
207
+
208
+
209
+ # Fetches the HTML page that lists all games for the specified date
210
+ def self.fetch_pitchers_page(gid)
211
+ GamedayUtil.fetcher.fetch_pitchers_page(gid)
212
+ end
213
+
214
+
215
+ def self.fetch_media_highlights(gid)
216
+ GamedayUtil.fetcher.fetch_media_highlights(gid)
217
+ end
218
+
219
+
220
+ def self.fetch_media_mobile(gid)
221
+ GamedayUtil.fetcher.fetch_media_mobile(gid)
222
+ end
223
+
224
+
225
+ def self.fetch_onbase_linescore(gid)
226
+ GamedayUtil.fetcher.fetch_onbase_linescore(gid)
227
+ end
228
+
229
+
230
+ def self.fetch_onbase_plays(gid)
231
+ GamedayUtil.fetcher.fetch_onbase_plays(gid)
232
+ end
233
+
234
+
235
+ def self.fetch_notifications_inning(gid, inning)
236
+ GamedayUtil.fetcher.fetch_notifications_inning(gid, inning)
237
+ end
238
+
239
+
240
+ def self.fetch_notifications_full(gid)
241
+ GamedayUtil.fetcher.fetch_notifications_full(gid)
242
+ end
243
+
244
+
245
+ end
@@ -0,0 +1,236 @@
1
+ require 'gameday_path_builder'
2
+
3
+
4
+ # This class is responsible for retrieving gameday data files from the local file system.
5
+ # It contains methods that read or open a connection to the XML files that have been saved
6
+ # to the local filesystem.
7
+ class GamedayLocalFetcher
8
+
9
+
10
+ # Fetch the epg.xml file
11
+ # Sample PATH: components/game/mlb/year_2008/month_04/day_07/epg.xml
12
+ def self.fetch_epg(year, month, day)
13
+ path = GamedayPathBuilder.build_epg_path(year, month, day)
14
+ GamedayUtil.read_file(path)
15
+ end
16
+
17
+
18
+ # Fetch the master scoreboard file
19
+ # Sample PATH: components/game/mlb/year_2008/month_04/day_07/master_scoreboard.xml
20
+ def self.fetch_scoreboard(year, month, day)
21
+ path = GamedayPathBuilder.build_scoreboard_path(year, month, day)
22
+ GamedayUtil.read_file(path)
23
+ end
24
+
25
+
26
+ def self.fetch_day_highlights(year, month, day)
27
+ path = GamedayPathBuilder.build_day_highlights_path(year, month, day)
28
+ GamedayUtil.read_file(path)
29
+ end
30
+
31
+
32
+ # Fetch the bench.xml file
33
+ # Sample PATH: components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/bench.xml
34
+ def self.fetch_bench(gid)
35
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/bench.xml'
36
+ GamedayUtil.read_file(path)
37
+ end
38
+
39
+
40
+ # Fetch the benchO.xml file
41
+ # Sample PATH: components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/benchO.xml
42
+ def self.fetch_bencho(gid)
43
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/benchO.xml'
44
+ GamedayUtil.read_file(path)
45
+ end
46
+
47
+
48
+ # Fetches the boxscore.xml file and returns its contents
49
+ # Sample PATH: components/game/mlb/year_2009/month_05/day_08/gid_2009_05_08_detmlb_clemlb_1/boxscore.xml
50
+ def self.fetch_boxscore(gid)
51
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
52
+ path = GamedayPathBuilder.build_boxscore_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
53
+ GamedayUtil.read_file(path)
54
+ end
55
+
56
+
57
+ # Fetch the emailSource.xml file
58
+ # Sample PATH: components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/emailSource.xml
59
+ def self.fetch_emailsource(gid)
60
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/emailSource.xml'
61
+ GamedayUtil.read_file(path)
62
+ end
63
+
64
+
65
+ # Fetches the eventLog.xml file and returns its contents
66
+ # Sample PATH: components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_flomlb_wasmlb_1/eventLog.xml
67
+ def self.fetch_eventlog(gid)
68
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
69
+ path = GamedayPathBuilder.build_eventlog_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
70
+ GamedayUtil.read_file(path)
71
+ end
72
+
73
+
74
+ # Fetches the game.xml file and returns its contents
75
+ def self.fetch_game_xml(gid)
76
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
77
+ path = GamedayPathBuilder.build_game_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
78
+ GamedayUtil.read_file(path)
79
+ end
80
+
81
+
82
+ def self.fetch_game_events(gid)
83
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
84
+ path = GamedayPathBuilder.build_game_events_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
85
+ GamedayUtil.read_file(path)
86
+ end
87
+
88
+
89
+ # Fetches the gamecenter.xml file and returns its contents
90
+ def self.fetch_gamecenter_xml(gid)
91
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
92
+ path = GamedayPathBuilder.build_gamecenter_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
93
+ GamedayUtil.read_file(path)
94
+ end
95
+
96
+
97
+ # Fetch the gameday_Syn.xml file
98
+ # Sample PATH: components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/gameday_Syn.xml
99
+ def self.fetch_gamedaysyn(gid)
100
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/gameday_Syn.xml'
101
+ GamedayUtil.read_file(path)
102
+ end
103
+
104
+
105
+ # Fetch the linescore.xml file
106
+ # Sample PATH: components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/linescore.xml
107
+ def self.fetch_linescore(gid)
108
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
109
+ path = GamedayPathBuilder.build_linescore_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
110
+ GamedayUtil.read_file(path)
111
+ end
112
+
113
+
114
+ # Fetch the miniscoreboard.xml file
115
+ # Sample PATH: components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/miniscoreboard.xml
116
+ def self.fetch_miniscoreboard(gid)
117
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/miniscoreboard.xml'
118
+ GamedayUtil.read_file(path)
119
+ end
120
+
121
+
122
+ # Fetches the players.xml file and returns its contents
123
+ def self.fetch_players(gid)
124
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
125
+ path = GamedayPathBuilder.build_players_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
126
+ GamedayUtil.read_file(path)
127
+ end
128
+
129
+
130
+ # Fetch the plays.xml file
131
+ # Sample PATH: components/game/mlb/year_2008/month_04/day_07/gid_2008_04_07_atlmlb_colmlb_1/plays.xml
132
+ def self.fetch_plays(gid)
133
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/plays.xml'
134
+ GamedayUtil.read_file(path)
135
+ end
136
+
137
+
138
+ # Fetches the batters/(pid).xml file
139
+ def self.fetch_batter(gid, pid)
140
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
141
+ path = GamedayPathBuilder.build_batter_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid, pid)
142
+ GamedayUtil.read_file(path)
143
+ end
144
+
145
+
146
+ # Fetches the pitchers/(pid).xml file
147
+ def self.fetch_pitcher(gid, pid)
148
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
149
+ path = GamedayPathBuilder.build_pitcher_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid, pid)
150
+ GamedayUtil.read_file(path)
151
+ end
152
+
153
+ # inning/inning_X.xml
154
+ def self.fetch_inningx(gid, inning_num)
155
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
156
+ path = GamedayPathBuilder.build_inningx_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid, inning_num)
157
+ GamedayUtil.read_file(path)
158
+ end
159
+
160
+
161
+ # inning/inning_Score.xml
162
+ def self.fetch_inning_scores(gid)
163
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
164
+ path = GamedayPathBuilder.build_inning_scores_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
165
+ GamedayUtil.read_file(path)
166
+ end
167
+
168
+
169
+ # inning/inning_hit.xml
170
+ def self.fetch_inning_hit(gid)
171
+ gameday_info = GamedayUtil.parse_gameday_id('gid_' + gid)
172
+ path = GamedayPathBuilder.build_inning_hit_path(gameday_info['year'] , gameday_info['month'], gameday_info['day'] , gid)
173
+ GamedayUtil.read_file(path)
174
+ end
175
+
176
+
177
+ # Fetches the HTML page that lists all games for the specified date
178
+ def self.fetch_games_page(year, month, day)
179
+ puts 'LOCAL = fetching games page - ' + year.to_s + ' ' + month.to_s + ' ' + day.to_s
180
+ path = GamedayPathBuilder.build_day_path(year, month, day) + 'games.html'
181
+ puts 'PATH = ' + path
182
+ GamedayUtil.read_file(path)
183
+ end
184
+
185
+
186
+ # Fetches the HTML page that lists all games for the specified date
187
+ def self.fetch_batters_page(gid)
188
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/batters.html'
189
+ GamedayUtil.read_file(path)
190
+ end
191
+
192
+
193
+ # Fetches the HTML page that lists all games for the specified date
194
+ def self.fetch_pitchers_page(gid)
195
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/pitchers.html'
196
+ GamedayUtil.read_file(path)
197
+ end
198
+
199
+
200
+ def self.fetch_media_highlights(gid)
201
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/media/highlights.xml'
202
+ GamedayUtil.read_file(path)
203
+ end
204
+
205
+
206
+ def self.fetch_media_mobile(gid)
207
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/media/mobile.xml'
208
+ GamedayUtil.read_file(path)
209
+ end
210
+
211
+
212
+ def self.fetch_onbase_linescore(gid)
213
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/onbase/linescore.xml'
214
+ GamedayUtil.read_file(path)
215
+ end
216
+
217
+
218
+ def self.fetch_onbase_plays(gid)
219
+ path = GamedayPathBuilder.build_game_base_path(gid) + '/onbase/plays.xml'
220
+ GamedayUtil.read_file(path)
221
+ end
222
+
223
+
224
+ def self.fetch_notifications_inning(gid, inning)
225
+ path = GamedayPathBuilder.build_game_base_path(gid) + "/notifications/notifications_#{inning}.xml"
226
+ GamedayUtil.read_file(path)
227
+ end
228
+
229
+
230
+ def self.fetch_notifications_full(gid)
231
+ path = GamedayPathBuilder.build_game_base_path(gid) + "/notifications/notifications_full.xml"
232
+ GamedayUtil.read_file(path)
233
+ end
234
+
235
+
236
+ end