Class: NBA::Stats::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/nba/stats/team_stats.rb

Constant Summary collapse

BASE_URI =
'http://stats.nba.com/stats'

Class Method Summary collapse

Class Method Details

.get_team_by_id(id) ⇒ Object



58
59
60
61
# File 'lib/nba/stats/team_stats.rb', line 58

def self.get_team_by_id(id)
  teams = get_teams
  teams[id]
end

.get_team_stats(measureType = "Advanced", perMode = "Totals", plusMinus = "N", paceAdjust = "N", rank = "N", leagueID = "00", season = "2015-16", seasonType = "Regular Season", pORound = 0, outcome = nil, location = nil, month = 0, seasonSegment = nil, dateFrom = nil, dateTo = nil, opponentTeamID = 0, vsConference = nil, vsDivision = nil, teamID = 0, conference = nil, division = nil, gameSegment = nil, period = 0, shotClockRange = nil, lastNGames = 0, gameScope = nil, playerExperience = nil, playerPosition = nil, starterBench = nil) ⇒ Object

THIS SHOULD BE REFACTORED TO ACCEPT SPLAT PARAMS



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nba/stats/team_stats.rb', line 5

def self.get_team_stats(measureType="Advanced",perMode="Totals",plusMinus="N",paceAdjust="N",rank="N",leagueID="00",season="2015-16",seasonType="Regular Season",pORound=0,outcome=nil,location=nil,month=0,seasonSegment=nil,dateFrom=nil,dateTo=nil,opponentTeamID=0,vsConference=nil,vsDivision=nil,teamID=0,conference=nil,division=nil,gameSegment=nil,period=0,shotClockRange=nil,lastNGames=0,gameScope=nil,playerExperience=nil,playerPosition=nil,starterBench=nil)
  res = HTTP.get(BASE_URI+'/leaguedashteamstats', :params => {
    :MeasureType => measureType,
    :PerMode => perMode,
    :PlusMinus => plusMinus,
    :PaceAdjust => paceAdjust,
    :Rank => rank,
    :LeagueID => leagueID,
    :Season => season,
    :SeasonType => seasonType,
    :PORound => pORound,
    :Outcome => outcome,
    :Location => location,
    :Month => month,
    :SeasonSegment => seasonSegment,
    :DateFrom => dateFrom,
    :DateTo => dateTo,
    :OpponentTeamID => opponentTeamID,
    :VsConference => vsConference,
    :VsDivision => vsDivision,
    :TeamID => teamID,
    :Conference => conference,
    :Division => division,
    :GameSegment => gameSegment,
    :Period => period,
    :ShotClockRange => shotClockRange,
    :LastNGames => lastNGames,
    :GameScope => gameScope,
    :PlayerExperience => playerExperience,
    :PlayerPosition => playerPosition,
    :StarterBench => starterBench
  })
  if res.code == 200
    return JSON.parse(res.body)
  end
  return res.code
end

.get_teamsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/nba/stats/team_stats.rb', line 43

def self.get_teams
  r = self.get_team_stats
  # CHECK IF THE RESPONSE FAILED, IF SO RETURN THE FAILURE
  if r.is_a? Numeric
    r
  else
    teams_hash = {}
    teams = r["resultSets"].first["rowSet"]
    teams.each_with_index do |val, index|
      teams_hash[teams[index][0]] = teams[index][1]
    end
    teams_hash
  end
end