lib/sportradar/api/basketball/team.rb in sportradar-api-0.12.0 vs lib/sportradar/api/basketball/team.rb in sportradar-api-0.12.1
- old
+ new
@@ -82,53 +82,64 @@
alias :roster :players
def parse_players(data, game)
create_data(@players_hash, data, klass: player_class, api: api, team: self, game: game)
end
def update_player_stats(player, stats, game = nil)
- game ? game.update_player_stats(player, stats) : @player_stats.merge!(player.id => stats.merge!(player: player))
+ game ? game.update_player_stats(player, stats) : @player_stats.merge!(player.id => stats.merge(player: player))
end
+ def parse_records(data)
+ @records['overall'] = Record.new(data, type: 'overall')
+ data['records'].each { |record| @records[record['record_type']] = Record.new(record, type: record['record_type']) }
+ end
+ def parse_season_stats(data)
+ @team_stats = data.dig('own_record')
+ update(data)
+ player_data = data.dig('players')
+ create_data(@players_hash, player_data, klass: player_class, api: api, team: self)
+ data
+ end
+
+
+ # data retrieval
+
def get_roster
- data = api.get_data(path_roster)
+ data = api.get_data(path_roster).to_h
ingest_roster(data)
end
def ingest_roster(data)
update(data)
data
end
+ def queue_roster
+ url, headers, options, timeout = api.get_request_info(path_roster)
+ {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_roster)}
+ end
- def get_season_stats
- data = api.get_data(path_season_stats)
+ def get_season_stats(year = Date.today.year)
+ data = api.get_data(path_season_stats(year)).to_h
ingest_season_stats(data)
end
def ingest_season_stats(data)
parse_season_stats(data)
end
-
- def parse_records(data)
- @records['overall'] = Record.new(data, type: 'overall')
- data['records'].each { |record| @records[record['record_type']] = Record.new(record, type: record['record_type']) }
+ def queue_season_stats
+ url, headers, options, timeout = api.get_request_info(path_season_stats)
+ {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_season_stats)}
end
- def parse_season_stats(data)
- @team_stats = data.dig('own_record')
- update(data)
- player_data = data.dig('players')
- create_data(@players_hash, player_data, klass: player_class, api: api, team: self)
- data
- end
-
+ # url path helpers
def path_base
"teams/#{ id }"
end
def path_base_stats(season_year = api.default_year, default_season = api.default_season)
"seasontd/#{season_year}/#{default_season}/teams/#{id}"
end
def path_roster
"#{ path_base }/profile"
end
- def path_season_stats
- "#{ path_base_stats }/statistics"
+ def path_season_stats(year)
+ "#{ path_base_stats(year) }/statistics"
end
end
end
end