Class: Sportradar::Api::Baseball::Mlb
- Defined in:
- lib/sportradar/api/baseball/mlb.rb,
lib/sportradar/api/baseball/mlb/api.rb,
lib/sportradar/api/baseball/mlb/league.rb,
lib/sportradar/api/baseball/mlb/division.rb
Defined Under Namespace
Classes: Api, Division, League
Instance Attribute Summary collapse
-
#alias ⇒ Object
Returns the value of attribute alias.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#response ⇒ Object
Returns the value of attribute response.
-
#type ⇒ Object
Returns the value of attribute type.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
- #all_attributes ⇒ Object
-
#api ⇒ Object
api stuff.
- #daily_schedule ⇒ Object
- #default_date ⇒ Object
- #default_season ⇒ Object
- #default_year ⇒ Object
- #divisions ⇒ Object
- #games ⇒ Object
-
#get_daily_summary(date = Date.today) ⇒ Object
daily summary.
-
#get_depth_charts ⇒ Object
depth_charts.
-
#get_hierarchy ⇒ Object
hierarchy.
-
#get_schedule ⇒ Object
schedule.
-
#get_standings ⇒ Object
standings.
- #hierarchy ⇒ Object
- #ingest_daily_summary(data) ⇒ Object
- #ingest_depth_charts(data) ⇒ Object
- #ingest_hierarchy(data) ⇒ Object
- #ingest_schedule(data) ⇒ Object
- #ingest_standings(data) ⇒ Object
-
#initialize(data = {}, **opts) ⇒ Mlb
constructor
A new instance of Mlb.
- #leagues ⇒ Object
- #mlb_season ⇒ Object
-
#path_base ⇒ Object
url paths.
- #path_daily_boxscore(date) ⇒ Object
- #path_daily_summary(date) ⇒ Object
- #path_depth_charts ⇒ Object
- #path_hierarchy ⇒ Object
- #path_rankings ⇒ Object
- #path_schedule ⇒ Object
- #path_series ⇒ Object
- #path_standings ⇒ Object
- #queue_daily_summary(date = Date.today) ⇒ Object
- #queue_depth_charts ⇒ Object
- #queue_hierarchy ⇒ Object
- #queue_schedule ⇒ Object
- #queue_standings ⇒ Object
- #schedule ⇒ Object
- #season_year ⇒ Object
- #standings ⇒ Object
- #team(team_id) ⇒ Object
- #teams ⇒ Object
- #update(data, source: nil, **opts) ⇒ Object
Methods inherited from Data
#attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data
Constructor Details
#initialize(data = {}, **opts) ⇒ Mlb
Returns a new instance of Mlb.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 10 def initialize(data = {}, **opts) # @response = data @api = opts[:api] @id = data['id'] @season = opts[:year] @type = opts[:type] @leagues_hash = {} @games_hash = {} @teams_hash = {} update(data, **opts) end |
Instance Attribute Details
#alias ⇒ Object
Returns the value of attribute alias.
5 6 7 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 5 def alias @alias end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 5 def name @name end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 5 def response @response end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 5 def type @type end |
#year ⇒ Object
Returns the value of attribute year.
5 6 7 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 5 def year @year end |
Instance Method Details
#all_attributes ⇒ Object
6 7 8 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 6 def all_attributes [:name, :alias, :leagues, :divisions, :teams] end |
#api ⇒ Object
api stuff
92 93 94 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 92 def api @api ||= Sportradar::Api::Baseball::Mlb::Api.new end |
#daily_schedule ⇒ Object
58 59 60 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 58 def daily_schedule # TODO end |
#default_date ⇒ Object
99 100 101 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 99 def default_date Date.today end |
#default_season ⇒ Object
102 103 104 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 102 def default_season 'reg' end |
#default_year ⇒ Object
96 97 98 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 96 def default_year Date.today.year end |
#divisions ⇒ Object
69 70 71 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 69 def divisions leagues.flat_map(&:divisions) end |
#games ⇒ Object
62 63 64 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 62 def games @games_hash.values end |
#get_daily_summary(date = Date.today) ⇒ Object
daily summary
226 227 228 229 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 226 def get_daily_summary(date = Date.today) data = api.get_data(path_daily_summary(date)).to_h ingest_daily_summary(data) end |
#get_depth_charts ⇒ Object
depth_charts
178 179 180 181 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 178 def get_depth_charts data = api.get_data(path_depth_charts).to_h ingest_depth_charts(data) end |
#get_hierarchy ⇒ Object
hierarchy
162 163 164 165 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 162 def get_hierarchy data = api.get_data(path_hierarchy).to_h ingest_hierarchy(data) end |
#get_schedule ⇒ Object
schedule
146 147 148 149 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 146 def get_schedule data = api.get_data(path_schedule).to_h ingest_schedule(data) end |
#get_standings ⇒ Object
standings
194 195 196 197 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 194 def get_standings data = api.get_data(path_standings).to_h ingest_standings(data) end |
#hierarchy ⇒ Object
53 54 55 56 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 53 def hierarchy get_hierarchy if divisions.empty? self end |
#ingest_daily_summary(data) ⇒ Object
231 232 233 234 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 231 def ingest_daily_summary(data) update(data.dig('league'), source: :games) data end |
#ingest_depth_charts(data) ⇒ Object
183 184 185 186 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 183 def ingest_depth_charts(data) update(data, source: :teams) data end |
#ingest_hierarchy(data) ⇒ Object
167 168 169 170 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 167 def ingest_hierarchy(data) update(data, source: :teams) data end |
#ingest_schedule(data) ⇒ Object
151 152 153 154 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 151 def ingest_schedule(data) update(data, source: :games) data end |
#ingest_standings(data) ⇒ Object
199 200 201 202 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 199 def ingest_standings(data) update(data.dig('league','season'), source: :teams) data end |
#leagues ⇒ Object
66 67 68 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 66 def leagues @leagues_hash.values end |
#mlb_season ⇒ Object
108 109 110 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 108 def mlb_season @type || default_season end |
#path_base ⇒ Object
url paths
114 115 116 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 114 def path_base "league" end |
#path_daily_boxscore(date) ⇒ Object
138 139 140 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 138 def path_daily_boxscore(date) "#{ path_base }/games/#{date.year}/#{date.month}/#{date.day}/boxscore" end |
#path_daily_summary(date) ⇒ Object
135 136 137 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 135 def path_daily_summary(date) "games/#{date.year}/#{date.month}/#{date.day}/summary" end |
#path_depth_charts ⇒ Object
129 130 131 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 129 def path_depth_charts "#{ path_base }/depth_charts" end |
#path_hierarchy ⇒ Object
126 127 128 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 126 def path_hierarchy "#{ path_base }/hierarchy" end |
#path_rankings ⇒ Object
123 124 125 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 123 def path_rankings "seasontd/#{season_year}/#{mlb_season}/rankings" end |
#path_schedule ⇒ Object
117 118 119 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 117 def path_schedule "games/#{season_year}/#{mlb_season}/schedule" end |
#path_series ⇒ Object
120 121 122 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 120 def path_series "series/#{season_year}/#{mlb_season}/schedule" end |
#path_standings ⇒ Object
132 133 134 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 132 def path_standings "seasontd/#{season_year}/#{mlb_season}/standings" end |
#queue_daily_summary(date = Date.today) ⇒ Object
236 237 238 239 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 236 def queue_daily_summary(date = Date.today) url, headers, , timeout = api.get_request_info(path_daily_summary(date)) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_daily_summary)} end |
#queue_depth_charts ⇒ Object
188 189 190 191 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 188 def queue_depth_charts url, headers, , timeout = api.get_request_info(path_depth_charts) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_depth_charts)} end |
#queue_hierarchy ⇒ Object
172 173 174 175 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 172 def queue_hierarchy url, headers, , timeout = api.get_request_info(path_hierarchy) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_hierarchy)} end |
#queue_schedule ⇒ Object
156 157 158 159 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 156 def queue_schedule url, headers, , timeout = api.get_request_info(path_schedule) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_schedule)} end |
#queue_standings ⇒ Object
204 205 206 207 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 204 def queue_standings url, headers, , timeout = api.get_request_info(path_standings) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_standings)} end |
#schedule ⇒ Object
43 44 45 46 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 43 def schedule get_schedule if games.empty? self end |
#season_year ⇒ Object
105 106 107 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 105 def season_year @year || default_year end |
#standings ⇒ Object
48 49 50 51 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 48 def standings get_standings if teams.first&.record.nil? self end |
#team(team_id) ⇒ Object
85 86 87 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 85 def team(team_id) teams.detect { |team| team.id == team_id } end |
#teams ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 72 def teams teams = divisions.flat_map(&:teams) if teams.empty? if @teams_hash.empty? get_hierarchy divisions.flat_map(&:teams) else @teams_hash.values end else teams end end |
#update(data, source: nil, **opts) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sportradar/api/baseball/mlb.rb', line 24 def update(data, source: nil, **opts) # update stuff @id = data.dig('league', 'id') if data.dig('league', 'id') @name = data.dig('league', 'name') if data.dig('league', 'name') @alias = data.dig('league', 'alias') if data.dig('league', 'alias') @year = data.dig('season', 'year') if data.dig('season', 'year') @type = data.dig('season', 'type') if data.dig('season', 'type') @leagues_hash = create_data({}, data['leagues'], klass: League, hierarchy: self, api: api) if data['leagues'] @teams_hash = create_data({}, data['teams'], klass: Team, hierarchy: self, api: api) if data['teams'] if data['games'] && !data['games'].empty? if data['games'].first.keys == ['game'] data['games'].map! { |hash| hash['game'] } end @games_hash = create_data({}, data['games'], klass: Game, hierarchy: self, api: api) end end |