Class: ESPNNBAFantasy::League

Inherits:
Object
  • Object
show all
Includes:
PlayerFinder
Defined in:
lib/espn_nba_fantasy/league.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PlayerFinder

#find_players

Constructor Details

#initialize(league_id, year, s2, sw) ⇒ League

initializes the league



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/espn_nba_fantasy/league.rb', line 17

def initialize(league_id, year, s2, sw)
  @uri = "https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/#{year}/segments/0/leagues/#{league_id}?view=mRoster&view=mSettings&view=mTeam&view=modular&view=mNav"
  @cookies = {'espn_s2': "#{s2}", 'SWID': "#{sw}"}
  @data = JSON.parse(RestClient.get(@uri, {cookies: @cookies}))
  @teams = make_team_objects
  @users = make_user_objects
  @stat_data = make_stat_data
  @league_id = @data['id']
  @name = @data['settings']['name']
  @current_start_year = @data['seasonId']
  @current_end_year = @current_start_year + 1
end

Instance Attribute Details

#current_end_yearObject

Returns the value of attribute current_end_year.



13
14
15
# File 'lib/espn_nba_fantasy/league.rb', line 13

def current_end_year
  @current_end_year
end

#current_start_yearObject

Returns the value of attribute current_start_year.



13
14
15
# File 'lib/espn_nba_fantasy/league.rb', line 13

def current_start_year
  @current_start_year
end

#league_idObject

Returns the value of attribute league_id.



13
14
15
# File 'lib/espn_nba_fantasy/league.rb', line 13

def league_id
  @league_id
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/espn_nba_fantasy/league.rb', line 13

def name
  @name
end

#stat_dataObject

Returns the value of attribute stat_data.



13
14
15
# File 'lib/espn_nba_fantasy/league.rb', line 13

def stat_data
  @stat_data
end

#teamsObject

Returns the value of attribute teams.



13
14
15
# File 'lib/espn_nba_fantasy/league.rb', line 13

def teams
  @teams
end

#usersObject

Returns the value of attribute users.



13
14
15
# File 'lib/espn_nba_fantasy/league.rb', line 13

def users
  @users
end

Instance Method Details

#findplayer(team_name, str) ⇒ Object

pull up a Player object based on their name and their team



42
43
44
45
46
47
# File 'lib/espn_nba_fantasy/league.rb', line 42

def findplayer(team_name, str)
  team = @teams.select{|t| t.name == team_name}.first
  return "No team named #{team_name}" unless team

  find_players(team.players, str) || "#{str} cannot be found in #{team_name}'s roster"
end

#team_listObject

gives you an array of each team’s name and id in the league



36
37
38
# File 'lib/espn_nba_fantasy/league.rb', line 36

def team_list
  @teams.map{|r| [r.name, r.team_id]}
end

#to_sObject



30
31
32
# File 'lib/espn_nba_fantasy/league.rb', line 30

def to_s
  "League #{@league_id}"
end