lib/sportradar/api/basketball/nba.rb in sportradar-api-0.9.59 vs lib/sportradar/api/basketball/nba.rb in sportradar-api-0.10.0

- old
+ new

@@ -2,89 +2,86 @@ module Api module Basketball class Nba < Request attr_accessor :league, :access_level, :simulation, :error - def initialize(access_level = 'p') + def initialize(access_level = default_access_level) @league = 'nba' raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? access_level @access_level = access_level end def schedule(season_year = default_year, nba_season = default_season) raise Sportradar::Api::Error::InvalidSeason unless allowed_seasons.include? nba_season response = get request_url("games/#{season_year}/#{nba_season}/schedule") - if response.success? && response['league'] - Sportradar::Api::Basketball::Nba::Season.new(response['league'], api: self) + if response.success? + Sportradar::Api::Basketball::Nba::Season.new(response.to_h, api: self) else @error = response end end def daily_schedule(date = default_date, nba_season = default_season) response = get request_url("games/#{ date.year }/#{ date.month }/#{ date.day }/schedule") - if response.success? && response['league'] - Sportradar::Api::Basketball::Nba::Schedule.new(response['league'], api: self) + if response.success? + Sportradar::Api::Basketball::Nba::Schedule.new(response.to_h, api: self) else @error = response end end def league_hierarchy response = get request_url("league/hierarchy") - if response.success? && response["league"] - Sportradar::Api::Basketball::Nba::Hierarchy.new(response["league"], api: self) + if response.success? + Sportradar::Api::Basketball::Nba::Hierarchy.new(response.to_h, api: self) else response end end + alias :hierarchy :league_hierarchy - def team_stats(season_year = default_year, nba_season = default_season, team_id) - response = get request_url("seasontd/#{season_year}/#{nba_season}/teams/#{team_id}/statistics") - if response.success? && response["season"] - # Sportradar::Api::Basketball::Nba::Team.new response["season"] - response - else - response - end - end - def standings(season_year = default_year, nba_season = default_season) response = get request_url("seasontd/#{season_year}/#{nba_season}/standings") - if response.success? && response["league"] - Sportradar::Api::Basketball::Nba::Hierarchy.new(response['league']["season"], api: self) + if response.success? + Sportradar::Api::Basketball::Nba::Hierarchy.new(response.to_h, api: self) else response end end def get_data(url) get request_url(url) end - def get_pbp(*args) - 'pbp' - end - - def default_year 2016 end def default_date Date.today end def default_season 'reg' end + def default_access_level + if (ENV['SPORTRADAR_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production' + 'p' + else + 't' + end + end + def content_format + 'json' + end + private def check_simulation(game_id) @simulation = true if simulation_games.include?(game_id) end def request_url(path) - puts "/nba-#{access_level}#{version}/#{path}" + # puts "/nba-#{access_level}#{version}/#{path}" if simulation # "/nfl-sim1/#{path}" else "/nba-#{access_level}#{version}/#{path}" end \ No newline at end of file