class SleeperRb::Resources::League
This class represents a Fantasy Football League
and is the access point for associated resources. All attributes are lazily loaded and cache their value based on the API response.
Attributes
Public Class Methods
SleeperRb::Utilities::Cache::new
# File lib/sleeper_rb/resources/league.rb, line 143 def initialize(opts = {}) raise ArgumentError unless opts[:league_id] super end
Public Instance Methods
Retrieves the Avatar
instance for the league.
@return [SleeperRb::Resources::Avatar
]
# File lib/sleeper_rb/resources/league.rb, line 49
Returns all drafts for the league
@return [SleeperRb::Resources::DraftArray
]
# File lib/sleeper_rb/resources/league.rb, line 128 cached_association :drafts do retrieve_drafts! end
Returns matchups for the League
for the given week.
@return [SleeperRb::Resources::League::MatchupArray
]
# File lib/sleeper_rb/resources/league.rb, line 110 cached_association :matchups do |week| retrieve_matchups!(week) end
Retrieves the available roster positions for the league.
@return [Array<SleeperRb::Utilities::RosterPosition
>]
# File lib/sleeper_rb/resources/league.rb, line 61
Retrieves rosters for the League
.
@return [SleeperRb::Resources::League::RosterArray
]
# File lib/sleeper_rb/resources/league.rb, line 90 cached_association :rosters do retrieve_rosters! end
Retrieves the scoring settings for the league.
@return [SleeperRb::Resources::League::ScoringSettings
]
# File lib/sleeper_rb/resources/league.rb, line 55
Returns the non-scoring settings for the league.
@return [SleeperRb::Resources::League::Settings
]
# File lib/sleeper_rb/resources/league.rb, line 71 cached_attr :total_rosters, :status, :sport, :season_type, :season, :previous_league_id, :name, :league_id, :draft_id, avatar: ->(id) { Resources::Avatar.new(avatar_id: id) }, scoring_settings: ->(settings) { ScoringSettings.new(settings) }, roster_positions: lambda { |array| array.map do |pos| SleeperRb::Utilities::RosterPosition.new(pos) end
Returns all traded draft picks for the League
.
@return [SleeperRb::Resources::TradedPickArray
]
# File lib/sleeper_rb/resources/league.rb, line 119 cached_association :traded_picks do retrieve_traded_picks! end
Returns all transactions for the League
for a given week.
@return [SleeperRb::Resources::League::TransactionArray
]
# File lib/sleeper_rb/resources/league.rb, line 139 cached_association :transactions do |week| retrieve_transactions!(week) end
Retrieves users for the League
.
@return [SleeperRb::Resources::UserArray
]
# File lib/sleeper_rb/resources/league.rb, line 99 cached_association :users do retrieve_users! end
Private Instance Methods
# File lib/sleeper_rb/resources/league.rb, line 184 def retrieve_drafts! url = "#{BASE_URL}/league/#{league_id}/drafts" response = execute_request(url) DraftArray.new(response.map { |hash| Draft.new(hash.merge(league: self)) }) end
# File lib/sleeper_rb/resources/league.rb, line 172 def retrieve_matchups!(week) url = "#{BASE_URL}/league/#{league_id}/matchups/#{week}" response = execute_request(url) MatchupArray.new(response.map { |hash| Matchup.new(hash.merge(league: self)) }) end
# File lib/sleeper_rb/resources/league.rb, line 160 def retrieve_rosters! url = "#{BASE_URL}/league/#{league_id}/rosters" response = execute_request(url) RosterArray.new(response.map { |hash| Roster.new(hash.merge(league: self)) }) end
# File lib/sleeper_rb/resources/league.rb, line 178 def retrieve_traded_picks! url = "#{BASE_URL}/league/#{league_id}/traded_picks" response = execute_request(url) TradedPickArray.new(response.map { |hash| TradedPick.new(hash.merge(league: self)) }) end
# File lib/sleeper_rb/resources/league.rb, line 190 def retrieve_transactions!(week) url = "#{BASE_URL}/league/#{league_id}/transactions/#{week}" response = execute_request(url) TransactionArray.new(response.map { |hash| Transaction.new(hash.merge(league: self)) }) end
# File lib/sleeper_rb/resources/league.rb, line 166 def retrieve_users! url = "#{BASE_URL}/league/#{league_id}/users" response = execute_request(url) UserArray.new(response.map { |hash| User.new(hash) }) end
# File lib/sleeper_rb/resources/league.rb, line 155 def retrieve_values! url = "#{BASE_URL}/league/#{league_id}" execute_request(url) end