class SleeperRb::Resources::User
The User
resource represents a single user in Sleeper. This also serves as the access points for associated data.
Attributes
display_name[R]
is_owner[R]
user_id[R]
username[R]
Public Class Methods
new(opts)
click to toggle source
Initializes a user, with either username or user_id.
@param username [String] The current username
@param user_id
[String] The numerical user_id
Calls superclass method
SleeperRb::Utilities::Cache::new
# File lib/sleeper_rb/resources/user.rb, line 78 def initialize(opts) raise ArgumentError, "must provide either user_id or username" unless opts[:user_id] || opts[:username] super end
Public Instance Methods
avatar()
click to toggle source
@return [SleeperRb::Resources::Avatar
]
# File lib/sleeper_rb/resources/user.rb, line 40 cached_attr :user_id, :username, :display_name, :is_owner, metadata: ->(hash) { Metadata.new(hash) }, avatar: ->(id) { id ? Resources::Avatar.new(avatar_id: id) : nil }
drafts(season_year)
click to toggle source
Retrieves all drafts for the user for the given season
@param season_year [String] The year in which the leagues were played
@return [SleeperRb::Resources::DraftArray
]
# File lib/sleeper_rb/resources/user.rb, line 68 cached_association :drafts do |season_year| retrieve_drafts!(season_year) end
leagues(season_year)
click to toggle source
Retrieves leagues for the user for the given season.
@param season_year [String] The year in which the leagues were played
@return [SleeperRb::Resources::LeagueArray
]
# File lib/sleeper_rb/resources/user.rb, line 55 cached_association :leagues do |season_year| retrieve_leagues!(season_year) end
metadata()
click to toggle source
@return [SleeperRb::Resources::User::Metadata
]
# File lib/sleeper_rb/resources/user.rb, line 26
Private Instance Methods
retrieve_drafts!(season_year)
click to toggle source
# File lib/sleeper_rb/resources/user.rb, line 97 def retrieve_drafts!(season_year) uri = URI("#{BASE_URL}/user/#{user_id}/drafts/nfl/#{season_year}") response = execute_request(uri) DraftArray.new(response.map { |hash| Resources::Draft.new(hash) }) end
retrieve_leagues!(season_year)
click to toggle source
# File lib/sleeper_rb/resources/user.rb, line 91 def retrieve_leagues!(season_year) uri = URI("#{BASE_URL}/user/#{user_id}/leagues/nfl/#{season_year}") response = execute_request(uri) LeagueArray.new(response.map { |hash| Resources::League.new(hash) }) end
retrieve_values!()
click to toggle source
# File lib/sleeper_rb/resources/user.rb, line 86 def retrieve_values! uri = URI("#{BASE_URL}/user/#{@user_id || @username}") execute_request(uri) end