espn_nba_fantasy 0.0.4.2 → 1.0.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 +4 -4
- data/lib/espn_nba_fantasy/league.rb +12 -4
- data/lib/espn_nba_fantasy/player.rb +7 -2
- data/lib/espn_nba_fantasy/player_finder.rb +1 -1
- data/lib/espn_nba_fantasy/team.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e525cd853cdbf18b2ce2db80ccd0e80a46af69facd46817334a0facf9edcb9b5
|
|
4
|
+
data.tar.gz: 174cc7b70bef212dcbcd35649c62040bd101227e8eca35789ad4af6b00ab090f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f6e91b50da4dfe5c46bf6e994356bcc9516b6cb6e2696f3b087d8a10ef0ae51371d3efbd6bdf9f1843f9e4ffb435929a12daefd66f6e4930d2ca7a78af238619
|
|
7
|
+
data.tar.gz: 654d3be2486b24728b49123fc0f426b0495fb935e24a4f00dc07904398367a8fee82f11bbbb78d03b5603a68873f56577707f8e1debec5ceafcba0cd9c0cc9f5
|
|
@@ -3,24 +3,28 @@ require 'json'
|
|
|
3
3
|
require_relative 'constants'
|
|
4
4
|
require_relative 'team'
|
|
5
5
|
require_relative 'player_finder'
|
|
6
|
+
require_relative 'user'
|
|
6
7
|
|
|
7
8
|
module ESPNNBAFantasy
|
|
8
9
|
class League
|
|
9
10
|
|
|
10
11
|
include PlayerFinder
|
|
11
12
|
|
|
12
|
-
attr_accessor :teams, :stat_data
|
|
13
|
+
attr_accessor :teams, :stat_data, :league_id, :name, :current_start_year, :current_end_year, :users
|
|
13
14
|
|
|
14
15
|
#initializes the league
|
|
15
16
|
|
|
16
17
|
def initialize(league_id, year, s2, sw)
|
|
17
|
-
@league_id = league_id
|
|
18
|
-
|
|
19
18
|
@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"
|
|
20
19
|
@cookies = {'espn_s2': "#{s2}", 'SWID': "#{sw}"}
|
|
21
20
|
@data = JSON.parse(RestClient.get(@uri, {cookies: @cookies}))
|
|
22
21
|
@teams = make_team_objects
|
|
22
|
+
@users = make_user_objects
|
|
23
23
|
@stat_data = make_stat_data
|
|
24
|
+
@league_id = @data['id']
|
|
25
|
+
@name = @data['name']
|
|
26
|
+
@current_start_year = @data['seasonId']
|
|
27
|
+
@current_end_year = @current_start_year + 1
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
def to_s
|
|
@@ -36,7 +40,7 @@ module ESPNNBAFantasy
|
|
|
36
40
|
#pull up a Player object based on their name and their team
|
|
37
41
|
|
|
38
42
|
def findplayer(team_name, str)
|
|
39
|
-
team = teams.select{|t| t.name == team_name}.first
|
|
43
|
+
team = @teams.select{|t| t.name == team_name}.first
|
|
40
44
|
return "No team named #{team_name}" unless team
|
|
41
45
|
|
|
42
46
|
find_players(team.players, str) || "#{str} cannot be found in #{team_name}'s roster"
|
|
@@ -48,6 +52,10 @@ module ESPNNBAFantasy
|
|
|
48
52
|
@data['teams'].map{|team| ESPNNBAFantasy::Team.new(team, self)}
|
|
49
53
|
end
|
|
50
54
|
|
|
55
|
+
def make_user_objects
|
|
56
|
+
@data['members'].map{|user| ESPNNBAFantasy::User.new(user, self)}
|
|
57
|
+
end
|
|
58
|
+
|
|
51
59
|
def make_stat_data
|
|
52
60
|
stats = {}
|
|
53
61
|
teams.each do |team|
|
|
@@ -6,16 +6,21 @@ module ESPNNBAFantasy
|
|
|
6
6
|
|
|
7
7
|
include CalculateStats
|
|
8
8
|
|
|
9
|
-
attr_reader :
|
|
9
|
+
attr_reader :first_name, :last_name, :full_name,
|
|
10
|
+
:player_id, :position, :stats, :team,
|
|
11
|
+
:slug
|
|
10
12
|
|
|
11
13
|
#basic initialization with attributes
|
|
12
14
|
|
|
13
15
|
def initialize(player, team)
|
|
14
|
-
@
|
|
16
|
+
@first_name = player['firstName']
|
|
17
|
+
@last_name = player['lastName']
|
|
18
|
+
@full_name = player['fullName']
|
|
15
19
|
@player_id = player['id']
|
|
16
20
|
@position = ESPNNBAFantasy::POSITION_MAP[player['defaultPositionId']-1]
|
|
17
21
|
@stats = stat_card_maker(player)
|
|
18
22
|
@team = team
|
|
23
|
+
@slug = @full_name.scan(/\w+|\s/).join.downcase.split(' ').join('-')
|
|
19
24
|
end
|
|
20
25
|
|
|
21
26
|
def to_s
|
|
@@ -38,15 +38,15 @@ module ESPNNBAFantasy
|
|
|
38
38
|
own_players = to_trade.map{|player| find_players(players, player)}
|
|
39
39
|
other_players = to_receive.map{|player| find_players(other_team.players, player)}
|
|
40
40
|
return "This trade included players not one of the specified teams" if (own_players.include?(nil)|| other_players.include?(nil))
|
|
41
|
-
{'Trading:' => own_players.map{|p| p.
|
|
42
|
-
'Receiving:' => other_players.map{|p| p.
|
|
41
|
+
{'Trading:' => own_players.map{|p| p.full_name},
|
|
42
|
+
'Receiving:' => other_players.map{|p| p.full_name}}.merge(new_team_stats(own_players, other_players))
|
|
43
43
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
private
|
|
47
47
|
|
|
48
48
|
def roster_names
|
|
49
|
-
players.map(&:
|
|
49
|
+
players.map(&:full_name)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def stat_differences(old, new)
|