Ok, I found something in the API documentation that might help, but I'm not sure, so I need help understanding.
Under Player Resources: http://developer.yahoo.com/fantasysports/g...r-resource.html
The sub-resource "stats" states: Player stats and points (if in a league context)
What does "if in a league context" mean? How do I put the URL in "league context?
Thanks
David B.
Oh. You're right, that might be a bit confusing. Let's give an example:
Say that you're writing a MLB application. You've gotten the user to authenticate with you, and you grabbed his league ID from the list of MLB leagues that he belongs to.
CODE
http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=mlb/leagues
Armed with this league key (let's say it's 238.l.627060), you want to let him search for a particular player, like Pujols, and get his stats. You could search for Pujols to find his player key...
CODE
http://fantasysports.yahooapis.com/fantasy/v2/league/238.l.627060/players;search=pujols
And then plug that key (238.p.6619) into a stats call within the context of the league (this is what we mean by that):
CODE
http://fantasysports.yahooapis.com/fantasy/v2/league/238.l.627060/players;player_key=238.p.6619/stats
This is sort of a bad example, because this league is actually a roto league, so it doesn't use points, but trust me, the points would show up if your league were using a scoring type that supported points (head-to-head points and points for NBA, NHL, and MLB; plain head-to-head and points for NFL). If you wanted to avoid the trouble of making that second call, you could actually combine the requests together:
CODE
http://fantasysports.yahooapis.com/fantasy/v2/league/238.l.627060/players;search=pujols/stats
And, hell, you could actually combine all of those requests into one if you wanted to figure out the stats that Pujols earned across all my leagues:
CODE
http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=mlb/leagues/players;search=pujols/stats
Does that make sense how all this fits together? There's a nesting order for how resources can fit beneath other resources, and you can chain those together to get the information you want. So when we say that we want a player in the context of a league, it just means that the player resources are nested below the league resource in the XML hierarchy. A similar type of request might be, give me the stats for all the players on all the teams that I own, and that would go a little something like:
CODE
http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=mlb/leagues/teams/players/stats
I think we've said a couple times that we designed these services with flexibility in mind, to let you get the most information you want with the fewest requests, and hopefully this helps explain a little bit what we mean by that.
(if you're still not seeing how this applies to your situation, just let me know and I'll try to tailor the examples a bit better)
EDIT: Random note: if you were set on calculating the points yourself, then you'd probably want to make the league settings request, loop through the stat_modifiers element and create a hash mapping stat_id to value, then make the player request, loop through the stats, figure out the stat modifier by indexing into the hash you created earlier (using the stat_id that's part of the stat element), and then multiply the modifier times the value. Then, if your league has 31 stats and 15 players, it would be a small loop of 31 to create the stat_modifier hash, then 465 hash lookups (instead of loops) to pull out the right modifier and multiply it to find the right value. But, yeah, it would be way better to just ask for the stats in the league context.