y_fantasy 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.pryrc +8 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/.standard.yml +2 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +220 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +12 -0
- data/exe/y_fantasy +9 -0
- data/lib/y_fantasy/api/authentication.rb +177 -0
- data/lib/y_fantasy/api/client.rb +84 -0
- data/lib/y_fantasy/api/subresource_param_builder.rb +138 -0
- data/lib/y_fantasy/api/url_builder.rb +91 -0
- data/lib/y_fantasy/cli.rb +46 -0
- data/lib/y_fantasy/concerns/subresourceable.rb +87 -0
- data/lib/y_fantasy/ref/nfl.rb +57 -0
- data/lib/y_fantasy/resources/base_resource.rb +117 -0
- data/lib/y_fantasy/resources/base_subresource.rb +31 -0
- data/lib/y_fantasy/resources/game/game_week.rb +26 -0
- data/lib/y_fantasy/resources/game/position_type.rb +20 -0
- data/lib/y_fantasy/resources/game.rb +136 -0
- data/lib/y_fantasy/resources/group/settings.rb +53 -0
- data/lib/y_fantasy/resources/group/standings.rb +11 -0
- data/lib/y_fantasy/resources/group.rb +76 -0
- data/lib/y_fantasy/resources/league/scoreboard.rb +12 -0
- data/lib/y_fantasy/resources/league/settings.rb +51 -0
- data/lib/y_fantasy/resources/league/standings.rb +25 -0
- data/lib/y_fantasy/resources/league.rb +187 -0
- data/lib/y_fantasy/resources/pickem_team/pick.rb +31 -0
- data/lib/y_fantasy/resources/pickem_team/week_pick.rb +28 -0
- data/lib/y_fantasy/resources/pickem_team.rb +98 -0
- data/lib/y_fantasy/resources/player/draft_analysis.rb +26 -0
- data/lib/y_fantasy/resources/player/ownership_percentage.rb +26 -0
- data/lib/y_fantasy/resources/player/stat_collection.rb +32 -0
- data/lib/y_fantasy/resources/player.rb +157 -0
- data/lib/y_fantasy/resources/shared_subresources/draft_result.rb +39 -0
- data/lib/y_fantasy/resources/shared_subresources/matchup.rb +61 -0
- data/lib/y_fantasy/resources/shared_subresources/roster_position.rb +38 -0
- data/lib/y_fantasy/resources/shared_subresources/stat.rb +16 -0
- data/lib/y_fantasy/resources/shared_subresources/stat_category.rb +22 -0
- data/lib/y_fantasy/resources/shared_subresources/stat_modifier.rb +10 -0
- data/lib/y_fantasy/resources/shared_subresources/stat_winner.rb +8 -0
- data/lib/y_fantasy/resources/team/manager.rb +23 -0
- data/lib/y_fantasy/resources/team/roster.rb +18 -0
- data/lib/y_fantasy/resources/team/standings.rb +33 -0
- data/lib/y_fantasy/resources/team/stat_collection.rb +38 -0
- data/lib/y_fantasy/resources/team.rb +175 -0
- data/lib/y_fantasy/subresource_validator.rb +67 -0
- data/lib/y_fantasy/transformations/base_transform.rb +62 -0
- data/lib/y_fantasy/transformations/collection_transformer.rb +22 -0
- data/lib/y_fantasy/transformations/default_transformer.rb +22 -0
- data/lib/y_fantasy/transformations/game/position_types_transformer.rb +21 -0
- data/lib/y_fantasy/transformations/game_transformer.rb +54 -0
- data/lib/y_fantasy/transformations/group_transformer.rb +39 -0
- data/lib/y_fantasy/transformations/instantiator.rb +25 -0
- data/lib/y_fantasy/transformations/key_unwrapper.rb +12 -0
- data/lib/y_fantasy/transformations/league/scoreboard_transformer.rb +21 -0
- data/lib/y_fantasy/transformations/league/settings_transformer.rb +25 -0
- data/lib/y_fantasy/transformations/league/standings_transformer.rb +22 -0
- data/lib/y_fantasy/transformations/league_transformer.rb +57 -0
- data/lib/y_fantasy/transformations/matchups_transformer.rb +22 -0
- data/lib/y_fantasy/transformations/pickem_team/week_picks_transformer.rb +29 -0
- data/lib/y_fantasy/transformations/pickem_team_transformer.rb +41 -0
- data/lib/y_fantasy/transformations/player/ownership_percentage_transformer.rb +21 -0
- data/lib/y_fantasy/transformations/player/stats_transformer.rb +32 -0
- data/lib/y_fantasy/transformations/player_transformer.rb +34 -0
- data/lib/y_fantasy/transformations/stat_categories_transformer.rb +19 -0
- data/lib/y_fantasy/transformations/stat_modifiers_transformer.rb +19 -0
- data/lib/y_fantasy/transformations/t.rb +44 -0
- data/lib/y_fantasy/transformations/team/manager_transformer.rb +19 -0
- data/lib/y_fantasy/transformations/team/roster_transformer.rb +27 -0
- data/lib/y_fantasy/transformations/team/standings_transformer.rb +42 -0
- data/lib/y_fantasy/transformations/team/stats_transformer.rb +30 -0
- data/lib/y_fantasy/transformations/team_transformer.rb +54 -0
- data/lib/y_fantasy/transformations/user_transformer.rb +17 -0
- data/lib/y_fantasy/transformations.rb +54 -0
- data/lib/y_fantasy/version.rb +5 -0
- data/lib/y_fantasy.rb +36 -0
- data/sig/y_fantasy.rbs +4 -0
- data/y_fantasy.gemspec +49 -0
- metadata +364 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YFantasy
|
4
|
+
# Represents a Yahoo Fantasy Game (e.g. NFL, NBA, MLB).
|
5
|
+
# A game is the top-level sports resource and contains leagues, which contain teams.
|
6
|
+
#
|
7
|
+
# @example Get NFL game information with game weeks
|
8
|
+
# games = YFantasy::Game.find_all_by_code('nfl', with: [:game_weeks])
|
9
|
+
#
|
10
|
+
# @see https://developer.yahoo.com/fantasysports/guide/#game-resource
|
11
|
+
class Game < BaseResource
|
12
|
+
# TODO: make constant of all valid yahoo game codes (nfl, nba, nfls, etc)
|
13
|
+
|
14
|
+
# --- REQUIRED ATTRIBUTES ------------------------------------------------------------------------------------------
|
15
|
+
|
16
|
+
# @!attribute [r] game_key
|
17
|
+
# @return [String] The unique key for this game
|
18
|
+
option :game_key
|
19
|
+
|
20
|
+
# @!attribute [r] game_id
|
21
|
+
# @return [String] The ID for this game (for Game resource, this is the same as game_key)
|
22
|
+
option :game_id
|
23
|
+
|
24
|
+
# @!attribute [r] name
|
25
|
+
# @return [String] The name of the game (eg. "Football", "Baseball")
|
26
|
+
option :name
|
27
|
+
|
28
|
+
# @!attribute [r] code
|
29
|
+
# @return [String] The general code for this game (eg. "nfl", "nba")
|
30
|
+
option :code
|
31
|
+
|
32
|
+
# @!attribute [r] type
|
33
|
+
# @return [String] The type of game (eg. "full")
|
34
|
+
option :type
|
35
|
+
|
36
|
+
# @!attribute [r] url
|
37
|
+
# @return [String] The URL to the game's home page
|
38
|
+
option :url
|
39
|
+
|
40
|
+
# @!attribute [r] season
|
41
|
+
# @return [Integer] The year of the season
|
42
|
+
option :season, type: Types::Coercible::Integer
|
43
|
+
|
44
|
+
# @!attribute [r] is_registration_over
|
45
|
+
# @return [Boolean] Whether registration for this game is over
|
46
|
+
option :is_registration_over, type: Types::Params::Bool
|
47
|
+
|
48
|
+
# @!attribute [r] is_game_over
|
49
|
+
# @return [Boolean] Whether this game's season is over
|
50
|
+
option :is_game_over, type: Types::Params::Bool
|
51
|
+
|
52
|
+
# @!attribute [r] is_offseason
|
53
|
+
# @return [Boolean] Whether this game is in the offseason
|
54
|
+
option :is_offseason, type: Types::Params::Bool
|
55
|
+
|
56
|
+
# --- OPTIONAL ATTRIBUTES ------------------------------------------------------------------------------------------
|
57
|
+
|
58
|
+
# @!attribute [r] current_week
|
59
|
+
# @return [Integer, nil] The current week number of the game
|
60
|
+
option :current_week, optional: true
|
61
|
+
|
62
|
+
# @!attribute [r] is_contest_reg_active
|
63
|
+
# @return [Boolean, nil] Whether contest registration is active
|
64
|
+
option :is_contest_reg_active, optional: true, type: Types::Params::Bool
|
65
|
+
|
66
|
+
# @!attribute [r] is_contest_over
|
67
|
+
# @return [Boolean, nil] Whether the contest is over
|
68
|
+
option :is_contest_over, optional: true, type: Types::Params::Bool
|
69
|
+
|
70
|
+
# @!attribute [r] has_schedule
|
71
|
+
# @return [Boolean, nil] Whether this game has a schedule
|
72
|
+
option :has_schedule, optional: true, type: Types::Params::Bool
|
73
|
+
|
74
|
+
# --- SUBRESOURCES -------------------------------------------------------------------------------------------------
|
75
|
+
|
76
|
+
# @!attribute [r] game_weeks
|
77
|
+
# @return [Array<GameWeek>, nil] Array of game weeks for this game
|
78
|
+
option :game_weeks, optional: true, type: array_of(GameWeek)
|
79
|
+
|
80
|
+
# @!attribute [r] position_types
|
81
|
+
# @return [Array<PositionType>, nil] Array of position types for this game
|
82
|
+
option :position_types, optional: true, type: array_of(PositionType)
|
83
|
+
|
84
|
+
# @!attribute [r] roster_positions
|
85
|
+
# @return [Array<RosterPosition>, nil] Array of roster positions for this game
|
86
|
+
option :roster_positions, optional: true, type: array_of(RosterPosition)
|
87
|
+
|
88
|
+
# @!attribute [r] stat_categories
|
89
|
+
# @return [Array<StatCategory>, nil] Array of stat categories for this game
|
90
|
+
option :stat_categories, optional: true, type: array_of(StatCategory)
|
91
|
+
|
92
|
+
# @!attribute [r] groups
|
93
|
+
# @return [Array<Group>, nil] Array of groups for this game (e.g. NFL Survival)
|
94
|
+
option :groups, optional: true, type: array_of(Group)
|
95
|
+
|
96
|
+
# @!attribute [r] leagues
|
97
|
+
# @return [Array<League>, nil] Array of leagues belonging to this game
|
98
|
+
option :leagues, optional: true, type: array_of(League)
|
99
|
+
|
100
|
+
# Define subresource associations
|
101
|
+
has_subresource :game_weeks, klass: GameWeek
|
102
|
+
has_subresource :position_types, klass: PositionType
|
103
|
+
has_subresource :roster_positions, klass: RosterPosition
|
104
|
+
has_subresource :stat_categories, klass: StatCategory
|
105
|
+
|
106
|
+
has_subresource :groups, klass: Group # NFL Survival
|
107
|
+
has_subresource :leagues, klass: League
|
108
|
+
|
109
|
+
# --- CLASS METHODS ------------------------------------------------------------------------------------------------
|
110
|
+
|
111
|
+
# Finds all games by their code(s)
|
112
|
+
#
|
113
|
+
# @param codes [String, Symbol, Array<String>, Array<Symbol>] The code(s) of the game(s) to find (e.g. 'nfl', 'nba')
|
114
|
+
# @param with [Symbol, Array<Symbol>] Optional subresources to include
|
115
|
+
# @param options [Hash] Additional options to pass to the API client
|
116
|
+
# @return [Array<Game>] Array of games matching the given code(s)
|
117
|
+
# @example Find all NFL games with game weeks
|
118
|
+
# YFantasy::Game.find_all_by_code('nfl', with: :game_weeks)
|
119
|
+
# @example Find all NFL and NBA games
|
120
|
+
# YFantasy::Game.find_all_by_code(['nfl', 'nba'])
|
121
|
+
def self.find_all_by_code(codes, with: [], **options)
|
122
|
+
subresources = Transformations::T.wrap_in_array(with)
|
123
|
+
SubresourceValidator.validate!(self, subresources)
|
124
|
+
data = YFantasy::Api::Client.get(:games, game_codes: codes, subresources: subresources, **options)
|
125
|
+
Transformations::CollectionTransformer.new(:games).call(data)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Retrieves leagues associated with this game
|
129
|
+
#
|
130
|
+
# @param league_keys [Array<String>] Optional specific league keys to retrieve
|
131
|
+
# @return [Array<League>] Array of leagues
|
132
|
+
# def leagues(league_keys = [])
|
133
|
+
# @leagues ||= League.find_all(Array(league_keys))
|
134
|
+
# end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YFantasy
|
4
|
+
class Group
|
5
|
+
# Settings for a Yahoo NFL Survival Group
|
6
|
+
class Settings < BaseSubresource
|
7
|
+
DEADLINE_1_DESC = "5 minutes before the first game of each week"
|
8
|
+
DEADLINE_2_DESC = "Sunday at 1:00 PM EST"
|
9
|
+
|
10
|
+
# --- REQUIRED ATTRIBUTES ----------------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
# @!attribute [r] start_week
|
13
|
+
# @return [Integer] the group start week
|
14
|
+
option :start_week, type: Types::Coercible::Integer
|
15
|
+
|
16
|
+
# @!attribute [r] end_week
|
17
|
+
# @return [Integer] the group end week
|
18
|
+
option :end_week, type: Types::Coercible::Integer
|
19
|
+
|
20
|
+
# @!attribute [r] max_strikes
|
21
|
+
# @return [Integer] the total number of strikes (incorrect picks) allowed
|
22
|
+
option :max_strikes, type: Types::Coercible::Integer
|
23
|
+
|
24
|
+
# @!attribute [r] use_playoff_weeks
|
25
|
+
# @return [Boolean] whether or not the group uses playoff weeks
|
26
|
+
option :use_playoff_weeks, type: Types::Params::Bool
|
27
|
+
|
28
|
+
# @!attribute [r] deadline
|
29
|
+
# @return [Integer]
|
30
|
+
option :deadline, type: Types::Coercible::Integer
|
31
|
+
|
32
|
+
# @!attribute [r] two_pick_start_week
|
33
|
+
# @return [Integer]
|
34
|
+
option :two_pick_start_week, type: Types::Coercible::Integer
|
35
|
+
|
36
|
+
# @!attribute [r] commissioner_note
|
37
|
+
# @return [String]
|
38
|
+
option :commissioner_note
|
39
|
+
|
40
|
+
# --- INSTANCE METHODS -------------------------------------------------------------------------------------------
|
41
|
+
|
42
|
+
# :nocov:
|
43
|
+
def deadline_desc
|
44
|
+
if deadline == 1
|
45
|
+
DEADLINE_1_DESC
|
46
|
+
elsif deadline == 2
|
47
|
+
DEADLINE_2_DESC
|
48
|
+
end
|
49
|
+
end
|
50
|
+
# :nocov:
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YFantasy
|
4
|
+
class Group
|
5
|
+
# Standings for a Yahoo Fantasy NFL Survival Group
|
6
|
+
class Standings < BaseSubresource
|
7
|
+
# --- REQUIRED ATTRIBUTES ----------------------------------------------------------------------------------------
|
8
|
+
option :teams, array_of(PickemTeam)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YFantasy
|
4
|
+
# Represents a Yahoo Fantasy NFL Survival Group
|
5
|
+
class Group < BaseResource
|
6
|
+
# --- REQUIRED ATTRIBUTES ------------------------------------------------------------------------------------------
|
7
|
+
|
8
|
+
# @!attribute [r] group_key
|
9
|
+
# @return [String] the unique key for this group
|
10
|
+
option :group_key
|
11
|
+
|
12
|
+
# @!attribute [r] group_id
|
13
|
+
# @return [String] the ID for this group
|
14
|
+
option :group_id
|
15
|
+
|
16
|
+
# @!attribute [r] name
|
17
|
+
# @return [String] the name of the group
|
18
|
+
option :name
|
19
|
+
|
20
|
+
# @!attribute [r] url
|
21
|
+
# @return [String] the URL to the group's Yahoo Fantasy page
|
22
|
+
option :url
|
23
|
+
|
24
|
+
# @!attribute [r] type
|
25
|
+
# @return [String] the type of group (e.g. "private")
|
26
|
+
option :type
|
27
|
+
|
28
|
+
# @!attribute [r] num_teams
|
29
|
+
# @return [Integer] the number of teams in the group
|
30
|
+
option :num_teams, type: Types::Coercible::Integer
|
31
|
+
|
32
|
+
# @!attribute [r] current_login_is_member
|
33
|
+
# @return [Boolean] whether the current user is a member of this group
|
34
|
+
option :current_login_is_member, type: Types::Params::Bool
|
35
|
+
|
36
|
+
# @!attribute [r] current_week
|
37
|
+
# @return [Integer] the current week number of the group
|
38
|
+
option :current_week, type: Types::Coercible::Integer
|
39
|
+
|
40
|
+
# @!attribute [r] has_group_started
|
41
|
+
# @return [Boolean] whether the group has started
|
42
|
+
option :has_group_started, type: Types::Params::Bool
|
43
|
+
|
44
|
+
# @!attribute [r] current_week_lock_time
|
45
|
+
# @return [Integer] the timestamp when the current week locks
|
46
|
+
option :current_week_lock_time, type: Types::Coercible::Integer
|
47
|
+
|
48
|
+
# --- OPTIONAL ATTRIBUTES ------------------------------------------------------------------------------------------
|
49
|
+
|
50
|
+
# @!attribute [r] commissioner_nickname
|
51
|
+
# @return [String, nil] the nickname of the commissioner
|
52
|
+
option :commissioner_nickname, optional: true
|
53
|
+
|
54
|
+
# @!attribute [r] is_commissioner
|
55
|
+
# @return [Boolean, nil] whether the current user is the commissioner
|
56
|
+
option :is_commissioner, optional: true, type: Types::Params::Bool
|
57
|
+
|
58
|
+
# --- SUBRESOURCES --------------------------------------------------------------------------------
|
59
|
+
|
60
|
+
# @!attribute [r] settings
|
61
|
+
# @return [Settings, nil] the settings for this group
|
62
|
+
option :settings, optional: true, type: instance_of(Settings)
|
63
|
+
|
64
|
+
# @!attribute [r] standings
|
65
|
+
# @return [Standings, nil] the standings for this group
|
66
|
+
option :standings, optional: true, type: instance_of(Standings)
|
67
|
+
|
68
|
+
# @!attribute [r] teams
|
69
|
+
# @return [Array<PickemTeam>, nil] the teams in this group
|
70
|
+
option :teams, optional: true, type: array_of(PickemTeam)
|
71
|
+
|
72
|
+
has_subresource :settings, klass: Settings
|
73
|
+
has_subresource :standings, klass: Standings
|
74
|
+
has_subresource :teams, klass: PickemTeam
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YFantasy
|
4
|
+
class League
|
5
|
+
# League scoreboard for a specific week
|
6
|
+
class Scoreboard < BaseSubresource
|
7
|
+
# --- REQUIRED ATTRIBUTES ----------------------------------------------------------------------------------------
|
8
|
+
option :week, type: Types::Coercible::Integer
|
9
|
+
option :matchups, type: array_of(Matchup)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YFantasy
|
4
|
+
class League
|
5
|
+
# Represents a league's settings
|
6
|
+
class Settings < BaseSubresource
|
7
|
+
# --- REQUIRED ATTRIBUTES ----------------------------------------------------------------------------------------
|
8
|
+
option :cant_cut_list
|
9
|
+
option :draft_together, type: Types::Params::Bool
|
10
|
+
option :draft_type
|
11
|
+
option :is_auction_draft, type: Types::Params::Bool
|
12
|
+
option :max_teams, type: Types::Coercible::Integer
|
13
|
+
option :player_pool
|
14
|
+
option :post_draft_players
|
15
|
+
option :scoring_type
|
16
|
+
option :trade_end_date, type: Types::Params::Date
|
17
|
+
option :trade_ratify_type
|
18
|
+
option :trade_reject_time, type: Types::Coercible::Integer
|
19
|
+
option :uses_faab, type: Types::Params::Bool
|
20
|
+
option :uses_playoff, type: Types::Params::Bool
|
21
|
+
option :waiver_rule
|
22
|
+
option :waiver_time, type: Types::Coercible::Integer
|
23
|
+
option :waiver_type
|
24
|
+
|
25
|
+
# --- OPTIONAL ATTRIBUTES ----------------------------------------------------------------------------------------
|
26
|
+
option :divisions, optional: true, type: ->(h) { h[:division] }
|
27
|
+
option :draft_pick_time, optional: true, type: Types::Coercible::Integer
|
28
|
+
option :draft_time, optional: true, type: Types::Coercible::Integer
|
29
|
+
option :has_multiweek_championship, optional: true, type: Types::Params::Bool
|
30
|
+
option :has_playoff_consolation_games, optional: true, type: Types::Params::Bool
|
31
|
+
option :max_games_played, optional: true, type: Types::Coercible::Integer
|
32
|
+
option :max_innings_pitched, optional: true, type: Types::Coercible::Integer
|
33
|
+
option :max_weekly_adds, optional: true, type: Types::Coercible::Integer
|
34
|
+
option :num_playoff_consolation_teams, optional: true, type: Types::Coercible::Integer
|
35
|
+
option :num_playoff_teams, optional: true, type: Types::Coercible::Integer
|
36
|
+
option :pickem_enabled, optional: true, type: Types::Params::Bool
|
37
|
+
option :playoff_start_week, optional: true, type: Types::Coercible::Integer
|
38
|
+
option :roster_import_deadline, optional: true, type: Types::Params::Date
|
39
|
+
option :roster_positions, optional: true, type: array_of(RosterPosition)
|
40
|
+
option :season_type, optional: true
|
41
|
+
option :stat_categories, optional: true, type: array_of(StatCategory)
|
42
|
+
option :stat_modifiers, optional: true, type: array_of(StatModifier)
|
43
|
+
option :uses_fractional_points, optional: true, type: Types::Params::Bool
|
44
|
+
option :uses_lock_eliminated_teams, optional: true, type: Types::Params::Bool
|
45
|
+
option :uses_negative_points, optional: true, type: Types::Params::Bool
|
46
|
+
option :uses_playoff_reseeding, optional: true, type: Types::Params::Bool
|
47
|
+
option :uses_roster_import, optional: true, type: Types::Params::Bool
|
48
|
+
option :waiver_days, optional: true, type: ->(h) { h.values.flatten }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YFantasy
|
4
|
+
class League
|
5
|
+
# Standings for a league
|
6
|
+
class Standings < BaseSubresource
|
7
|
+
# --- REQUIRED ATTRIBUTES ----------------------------------------------------------------------------------------
|
8
|
+
option :teams, array_of(Team)
|
9
|
+
|
10
|
+
# --- INSTANCE METHODS -------------------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
# Returns an array of team hashes, sorted by rank.
|
13
|
+
# @return [Array<Hash>]
|
14
|
+
def final
|
15
|
+
teams.map(&:simple_standings).sort_by { |h| h[:rank] }
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns an array of team hashes, sorted by wins and points for.
|
19
|
+
# @return [Array<Hash>]
|
20
|
+
def regular_season
|
21
|
+
teams.map(&:simple_standings).sort_by { |h| [-h[:wins], -h[:points_for]] }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YFantasy
|
4
|
+
# Represents a Yahoo Fantasy League.
|
5
|
+
|
6
|
+
class League < BaseResource
|
7
|
+
# --- REQUIRED ATTRIBUTES ------------------------------------------------------------------------------------------
|
8
|
+
|
9
|
+
# @!attribute [r] league_key
|
10
|
+
# @return [String] The unique key for this league
|
11
|
+
option :league_key
|
12
|
+
|
13
|
+
# @!attribute [r] league_id
|
14
|
+
# @return [String] The ID for this league
|
15
|
+
option :league_id
|
16
|
+
|
17
|
+
# @!attribute [r] allow_add_to_dl_extra_pos
|
18
|
+
# @return [Boolean] Whether the league allows adding extra positions to DL
|
19
|
+
option :allow_add_to_dl_extra_pos, Types::Params::Bool
|
20
|
+
|
21
|
+
# @!attribute [r] draft_status
|
22
|
+
# @return [String] The status of the draft
|
23
|
+
option :draft_status
|
24
|
+
|
25
|
+
# @!attribute [r] edit_key
|
26
|
+
# @return [String] The edit key for this league
|
27
|
+
option :edit_key
|
28
|
+
|
29
|
+
# @!attribute [r] end_date
|
30
|
+
# @return [Date] The end date of the league
|
31
|
+
option :end_date, type: Types::Params::Date
|
32
|
+
|
33
|
+
# @!attribute [r] felo_tier
|
34
|
+
# @return [String] The Fantasy ELO tier of the league
|
35
|
+
option :felo_tier
|
36
|
+
|
37
|
+
# @!attribute [r] game_code
|
38
|
+
# @return [String] The game code (e.g. "nfl", "nba")
|
39
|
+
option :game_code
|
40
|
+
|
41
|
+
# @!attribute [r] is_cash_league
|
42
|
+
# @return [Boolean] Whether this is a cash league
|
43
|
+
option :is_cash_league, Types::Params::Bool
|
44
|
+
|
45
|
+
# @!attribute [r] is_pro_league
|
46
|
+
# @return [Boolean] Whether this is a pro league
|
47
|
+
option :is_pro_league, Types::Params::Bool
|
48
|
+
|
49
|
+
# @!attribute [r] league_type
|
50
|
+
# @return [String] The type of league
|
51
|
+
option :league_type
|
52
|
+
|
53
|
+
# @!attribute [r] league_update_timestamp
|
54
|
+
# @return [Integer] The timestamp of the last league update
|
55
|
+
option :league_update_timestamp, Types::Coercible::Integer
|
56
|
+
|
57
|
+
# @!attribute [r] logo_url
|
58
|
+
# @return [String] The URL for the league logo
|
59
|
+
option :logo_url
|
60
|
+
|
61
|
+
# @!attribute [r] name
|
62
|
+
# @return [String] The name of the league
|
63
|
+
option :name
|
64
|
+
|
65
|
+
# @!attribute [r] num_teams
|
66
|
+
# @return [Integer] The number of teams in the league
|
67
|
+
option :num_teams, type: Types::Coercible::Integer
|
68
|
+
|
69
|
+
# @!attribute [r] renew
|
70
|
+
# @return [String] Previous league ID in the format "<game_id>_<league_id>"
|
71
|
+
# @example "123_111111"
|
72
|
+
option :renew
|
73
|
+
|
74
|
+
# @!attribute [r] renewed
|
75
|
+
# @return [String] Next league ID in the format "<game_id>_<league_id>"
|
76
|
+
# @example "789_222222"
|
77
|
+
option :renewed
|
78
|
+
|
79
|
+
# @!attribute [r] scoring_type
|
80
|
+
# @return [String] The scoring type of the league
|
81
|
+
option :scoring_type
|
82
|
+
|
83
|
+
# @!attribute [r] season
|
84
|
+
# @return [String] The season year of the league
|
85
|
+
option :season
|
86
|
+
|
87
|
+
# @!attribute [r] start_date
|
88
|
+
# @return [Date] The start date of the league
|
89
|
+
option :start_date, type: Types::Params::Date
|
90
|
+
|
91
|
+
# @!attribute [r] url
|
92
|
+
# @return [String] The URL to the league's Yahoo Fantasy page
|
93
|
+
option :url
|
94
|
+
|
95
|
+
# @!attribute [r] weekly_deadline
|
96
|
+
# @return [String] The weekly deadline type
|
97
|
+
option :weekly_deadline
|
98
|
+
|
99
|
+
# --- OPTIONAL ATTRIBUTES ------------------------------------------------------------------------------------------
|
100
|
+
|
101
|
+
# @!attribute [r] short_invitation_url
|
102
|
+
# @return [String, nil] The short URL for invitations to the league
|
103
|
+
option :short_invitation_url, optional: true
|
104
|
+
|
105
|
+
# @!attribute [r] current_week
|
106
|
+
# @return [Integer, nil] The current week number of the league
|
107
|
+
option :current_week, optional: true, type: Types::Coercible::Integer
|
108
|
+
|
109
|
+
# @!attribute [r] start_week
|
110
|
+
# @return [Integer, nil] The starting week of the league
|
111
|
+
option :start_week, optional: true, type: Types::Coercible::Integer
|
112
|
+
|
113
|
+
# @!attribute [r] end_week
|
114
|
+
# @return [Integer, nil] The final week of the league
|
115
|
+
option :end_week, optional: true, type: Types::Coercible::Integer
|
116
|
+
|
117
|
+
# @!attribute [r] is_finished
|
118
|
+
# @return [Boolean, nil] Whether the league has finished
|
119
|
+
option :is_finished, optional: true, type: Types::Params::Bool
|
120
|
+
|
121
|
+
# --- SUBRESOURCES -------------------------------------------------------------------------------------------------
|
122
|
+
|
123
|
+
# @!attribute [r] draft_results
|
124
|
+
# @return [Array<DraftResult>, nil] The draft results for the league
|
125
|
+
option :draft_results, optional: true, type: array_of(DraftResult)
|
126
|
+
|
127
|
+
# @!attribute [r] players
|
128
|
+
# @return [Array<Player>, nil] The players in the league. By default, only 25 players are returned.
|
129
|
+
option :players, optional: true, type: array_of(Player)
|
130
|
+
|
131
|
+
# @!attribute [r] scoreboard
|
132
|
+
# @return [Scoreboard, nil] The league scoreboard
|
133
|
+
option :scoreboard, optional: true, type: instance_of(Scoreboard)
|
134
|
+
|
135
|
+
# @!attribute [r] settings
|
136
|
+
# @return [Settings, nil] The league settings
|
137
|
+
option :settings, optional: true, type: instance_of(Settings)
|
138
|
+
|
139
|
+
# @!attribute [r] standings
|
140
|
+
# @return [Standings, nil] The league standings
|
141
|
+
option :standings, optional: true, type: instance_of(Standings)
|
142
|
+
|
143
|
+
# @!attribute [r] teams
|
144
|
+
# @return [Array<Team>, nil] The teams in this league
|
145
|
+
option :teams, optional: true, type: array_of(Team)
|
146
|
+
|
147
|
+
has_subresource :draft_results, klass: DraftResult
|
148
|
+
has_subresource :players, klass: Player
|
149
|
+
has_subresource :scoreboard, klass: Scoreboard
|
150
|
+
has_subresource :settings, klass: Settings
|
151
|
+
has_subresource :standings, klass: Standings
|
152
|
+
has_subresource :teams, klass: Team
|
153
|
+
|
154
|
+
# --- INSTANCE METHODS ---------------------------------------------------------------------------------------------
|
155
|
+
|
156
|
+
# Whether the league has started
|
157
|
+
# @return [Boolean] Whether the league has started based on the start date
|
158
|
+
def started?
|
159
|
+
Date.today >= start_date
|
160
|
+
end
|
161
|
+
|
162
|
+
# Whether the league has ended
|
163
|
+
# @return [Boolean] Whether the league has ended based on finished status or end date
|
164
|
+
def ended?
|
165
|
+
is_finished || Date.today > end_date
|
166
|
+
end
|
167
|
+
|
168
|
+
# Returns the key of the previous league
|
169
|
+
# @return [String, nil] The key of the previous league, if any
|
170
|
+
def previous_league_key
|
171
|
+
renew&.split("_")&.join(".l.")
|
172
|
+
end
|
173
|
+
|
174
|
+
# Returns the key of the next/renewed league
|
175
|
+
# @return [String, nil] The key of the next/renewed league, if any
|
176
|
+
def next_league_key
|
177
|
+
renewed&.split("_")&.join(".l.")
|
178
|
+
end
|
179
|
+
|
180
|
+
# Gets the scoreboard for a specific week
|
181
|
+
# @param week [Integer] The week number to get the scoreboard for
|
182
|
+
# @return [Scoreboard] The scoreboard for the specified week
|
183
|
+
def scoreboard_for_week(week)
|
184
|
+
@scoreboard = self.class.find(league_key, with: :scoreboard, week: week).scoreboard
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YFantasy
|
4
|
+
class PickemTeam
|
5
|
+
# Represents a single team pick in a pickem fantasy contest
|
6
|
+
class Pick < BaseSubresource
|
7
|
+
# --- REQUIRED ATTRIBUTES ----------------------------------------------------------------------------------------
|
8
|
+
|
9
|
+
# @!attribute [r] team
|
10
|
+
# @return [String] the Yahoo team key (e.g., "nfl.t.1")
|
11
|
+
option :team
|
12
|
+
|
13
|
+
# @!attribute [r] result
|
14
|
+
# @return [Object] the result of the pick ("correct" or "strike")
|
15
|
+
option :result
|
16
|
+
|
17
|
+
# @!attribute [r] locked
|
18
|
+
# @return [Boolean] whether the pick is locked and cannot be changed
|
19
|
+
option :locked, type: Types::Params::Bool
|
20
|
+
|
21
|
+
# :nocov:
|
22
|
+
|
23
|
+
# @return [Hash] Team details (city, team name, abbreviation) for the pick
|
24
|
+
def team_details
|
25
|
+
Ref::Nfl.team(team)
|
26
|
+
end
|
27
|
+
|
28
|
+
# :nocov:
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YFantasy
|
4
|
+
class PickemTeam
|
5
|
+
# Represents a single week of picks for a team in a Yahoo Fantasy NFL Survival Group.
|
6
|
+
# There may be multiple picks per week.
|
7
|
+
class WeekPick < BaseSubresource
|
8
|
+
# --- REQUIRED ATTRIBUTES ----------------------------------------------------------------------------------------
|
9
|
+
|
10
|
+
# @!attribute [r] week
|
11
|
+
# @return [Integer] the week number
|
12
|
+
option :week, type: Types::Coercible::Integer
|
13
|
+
|
14
|
+
# @!attribute [r] picks_completed
|
15
|
+
# @return [Integer] the number of picks completed for this week
|
16
|
+
option :picks_completed, type: Types::Coercible::Integer
|
17
|
+
|
18
|
+
# @!attribute [r] picks
|
19
|
+
# @return [Array<Pick>] the picks made for this week
|
20
|
+
option :picks, type: array_of(Pick)
|
21
|
+
|
22
|
+
# @return [Array<Hash>] team details for each pick
|
23
|
+
def pick_details
|
24
|
+
picks.compact.map(&:team_details)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|