josuebrunel / yahoo-fantasy-sport

Python Yahoo! Fantasy Sports
MIT License
28 stars 9 forks source link

Progress so far... #48

Closed EmilMaric closed 8 years ago

EmilMaric commented 8 years ago

So I just finished my exams, and I've been working on this project since then. This pull request does not need to be merged in, I just wanted to show you my progress so far (also ignore my terrible commit messages, I was playing around with some stuff).

I thought long and hard about the overall design of this API. I went with a complete redesign because I think it's more modular and will help us scale easier when we start adding in more resources/collections like League and Team. I hope the code is clean enough and the comments thorough enough for you to understand my thought process.

I'll try to explain some of the basic parts of my design and implementation. I've only implemented functionality for the Game resource and Games collection for now. To start off, I'll go through how to use the redesigned API. The first part is very similar to what you already have:

from yahoo_oauth import OAuth1
from yahoo_fantasy_sports import YahooFantasySports

oauth = OAuth1(None, None, from_file='git/yahoo-fantasy-sport/oauth.json', base_url='http://fantasysports.yahooapis.com/fantasy/v2/')
yfs = YahooFantasySports(oauth)
...

All I'm doing here is creating the oauth object and passing it to the main API handler YahooFantasySports.

...
# I want to see most current NBA fantasy game
> nba_game = yfs.games('nba')

# I want to see the game key
> nba_game.game_key
353

# Now I want to see if registration is over
nba_game.is_registration_over
> 0    # I should change this to say 'True/False' rather than '0/1'

# Tell me if this fantasy game is still available
> nba_game.is_available
True
...

As you can see, it's pretty straightforward to use. You can also get fantasy games by their integer game_key. For example, yfs.games(353) will give you the same result as yfs.games('nba').

I also thought about adding support for querying for multiple fantasy games. I'll explain this next:

...
# I'm now interested in the most current NBA and NFL fantasy games
> multi_games = yfs.games('nba', 'nfl')

# Let's see what multi_games looks like...
> multi_games
<Games {353: <yahoo_fantasy_sports.game.Game object at 0x10eaf49d0>, 348: <yahoo_fantasy_sports.game.Game object at 0x10ea175d0>}>

# What games do we have?
> multi_games.games
[353, 348]

# Indexing to get a Game object
> multi_games[353]
<yahoo_fantasy_sports.game.Game object at 0x10eaf49d0>

# We can do the same thing we did above with a Game object
> multi_games[353].is_registration_over
0

So, the most important part to take away from this is that passing in a single key to yfs.games(...) will give you a Game resource object, while passing in more than one key to yfs.games(...) will give you a Games collection object which contains multiple Game resource objects. Again, you can mix-and-match with string or integer game_keys. So yfs.games('nba', 348) or yfs.games(358, 348) would give you the same thing as yfs.games('nba', 'mlb').

That's the gist of what I have so far. Let me know if you have any questions, or any criticisms of this approach. I'd love to hear what you have to say!

josuebrunel commented 8 years ago

Hello @EmilMaric . You did a very good job. I honestly like your design. Indeed it's way more straightforward. I just added you as collaborator so you can be lil bit free.

peacing commented 8 years ago

@EmilMaric I think it's great you're taking on this project. I feel bad for abandoning it without fully completing it. I look forward to seeing what you do!