Skip to content

Commit

Permalink
josuebrunel#37 : edit_waivers, trade_response, commissioner_trade_res…
Browse files Browse the repository at this point in the history
…ponse, vote_against_trade. Testing to proceed soon.
  • Loading branch information
peacing committed Jul 26, 2015
1 parent b18507b commit 77d00e5
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 15 deletions.
76 changes: 66 additions & 10 deletions fantasy_sport/fantasy_sport.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def set_roster_players(self, team_keys, roster):
>>> p1 = Player('242.p.8332','WR')
>>> p2 = Player('242.p.8334','WL')
>>> roster = Roster([p1, p2], date='2015-01-11')
>>> yfs.set_roster_players(['238.l.627062'], roster)
>>> yfs.set_roster_players(['238.l.627062.t.1'], roster)
"""
uri = self._build_uri(None, team_keys, sub='roster')
uri = 'team/{0}'.format(uri)
Expand All @@ -376,6 +376,8 @@ def set_roster_players(self, team_keys, roster):
#
##############################################

### GET Functions

def get_transactions(self, transaction_keys, players=None):
"""Return transaction data
>>> yfs.get_transaction(['transaction_key'])
Expand All @@ -391,28 +393,82 @@ def get_transactions(self, transaction_keys, players=None):
return response

def get_all_completed_leagues_transactions(self, league_keys):
"""Return all transactions form multiple leagues
"""Return all transactions from multiple leagues
>>>yfs.get_all_completed_leagues_transactions(['league_key1', 'leaguekey2'])
"""

uri = self._build_uri('leagues;league_keys', league_keys, sub='transactions')
response = self._get(uri)
return response

def get_teams_pending_transactions(self, league_key, team_key)
"""Return pending transactions for a specific team
>>> yfs.get_teams_pending_transactions('league_key', 'team_key')
"""

uri = self._build_uri(None, 'league/{0}'.format(league_key), sub='transactions')
uri += ';types=waiver,pending_trade;team_key={1}'.format(team_key)

response = self._get(uri)
return response


### PUT Functions

def edit_waivers(self, transaction_keys, transactions):
def edit_waivers(self, roster):
"""
>>> from fantasy_sport import Roster, Player
>>> p1 = Player('242.p.8332','WR')
>>> p2 = Player('242.p.8334','WL')
>>> roster = Roster([p1, p2], date='2015-01-11')
>>> ysf.edit_waivers(['238.l.627062'], roster)
>>> from fantasy_sport import Transaction
>>> roster = Transaction(type='waiver', 'transaction_key', waiver_priority='1', faab_bid='10')
>>> yfs.edit_waivers(roster)
"""
uri = self._build_uri(None, team_keys, sub='roster/players')
uri = 'team/{0}'.format(uri)
uri = self._build_uri(None, None, sub='transaction')

response = self._put(uri, roster)

def trade_response(self, roster):
"""
Accept OR decline a trade proposal
>>> from fantasy_sport import Transaction
>>> roster = Transaction(type='pending_trade', 'transaction_key', action='accept', trade_note='Great offer!')
>>> yfs.trade_response(roster)
"""
uri = self._build_uri(None, None, sub='transaction')

response = self._put(uri, roster)

def commissioner_trade_response(self, roster):
"""
Allow or disallow trade ONLY if commissioner of league
>>> from fantasy_sport import Transaction
>>> roster = Transaction(type='pending_trade', 'transaction_key', action='allow')
>>> yfs.commissioner_trade_response(roster)
"""
uri = self._build_uri(None, None, sub='transaction')

response = self._put(uri, roster)

def vote_against_trade(self, roster):
"""
Vote against a trade proposal
>>> from fantasy_sport import Transaction
>>> roster = Transaction(type='pending_trade', 'transaction_key', action='vote_against', voter_team_key='team_key')
>>> yfs.vote_against_trade(roster)
"""
uri = self._build_uri(None, None, sub='transaction')

response = self._put(uri, roster)

### POST Functions

def make_roster_move(self, league_keys, roster)
"""
Add, drop, or add & drop a player
>>> from fantasy_sport import Transaction
>>> roster = Transaction(type='add/drop', add_player_key='346.p.9171')
>>> yfs.make_roster_move(['346.l.1328'], roster)
"""
uri = self._build_uri(None, league_keys, sub='roster')
uri = 'league/{0}'.format(uri)



9 changes: 5 additions & 4 deletions fantasy_sport/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ class Transaction(Base):
- action
"""

def __init__(self, transaction_key, type, waiver_priority=None, faab_bid=None, action=None, trade_note=None, voter_team_key=None):
def __init__(self, type, transaction_key=None, waiver_priority=None, faab_bid=None, action=None, trade_note=None, voter_team_key=None):
"""Initialize a Transaction object
"""
super(Base, self).__init()

self.transaction_key = transaction_key
self.type = type
self.transaction_key = transaction_key
self.waiver_priority = waiver_priority
self.faab_bid = faab_bid
self.action = action
Expand All @@ -155,8 +155,9 @@ def xml_builder(self,):
content = ctree.Element('fantasy_content')
transaction = ctree.SubElement(content, 'transaction')

transaction_key = ctree.SubElement(transaction, 'transaction_key')
transaction_key.text = self.transaction_key
if transaction_key:
transaction_key = ctree.SubElement(transaction, 'transaction_key')
transaction_key.text = self.transaction_key

type = ctree.SubElement(transaction, 'type')
type.text = self.type
Expand Down
2 changes: 1 addition & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from yahoo_oauth import OAuth1

from fantasy_sport import FantasySport
from fantasy_sport.roster import Player, Roster
from fantasy_sport.roster import Player, Roster, Transaction
from fantasy_sport.utils import pretty_json, pretty_xml

logging.getLogger('yahoo_oauth').setLevel(logging.WARNING)
Expand Down

0 comments on commit 77d00e5

Please sign in to comment.