RLovelett/sports_data_api — pull request #26 by trdinich (2013-12-16 18:35:33+00:00)
Title: Implement basic NBA calls

This is the first wave of NBA related calls, including:
- league (team) hierarchy
- team roster
- season schedule
- daily schedule
- game summary (player game stats)

I would say I mostly stayed true to the way you were doing things, but there are some important changes here that you may want to mess with a bit more or chat for a bit. I'm happy to Skype or something to discuss, because I certainly have incentive to make this gem as awesome as possible because I'll be using it quite often :)

The most sweeping change is moving to a world where we can handle multiple API keys. As it turns out, Sports Data issues a different API key *per sport*, which is a bit odd, but is the way it is. You'll find these changes in lib/sports_data_api.rb, but of course it forced a change in many other places throughout the code and the specs. It will unfortunately break backwards compatibility, but when I attempted to maintain it it felt pretty hack-y in that the user may feel some false sense of security not really understanding what their api key is good for.

The only other place I think I did something slightly differently in NBA than NFL is in the team roster. Rather than implement a TeamRoster object, I simply just had a team object which has a players attribute on it (Array of Player objects). Based on how I was using this, it felt fairly logical to me, in that teams can sometimes have players, and players can sometimes have stats. This way, when you're getting the game summary, you have this nice hierarchy of objects:
- Game has home_team and away_team
- home_team and away_team each have players
- players all have stats

If you don't like this, I'd be happy to conform to the way you'd like to do things, as this is, afterall, your baby :)

There are also clearly ways that we can DRY this up, but I figured I'd toss functionality and structure your way before we attempt some large refactor. Unfortunately, NBA is on v3 and NFL on v1, and they do in fact have some changes that make a totally DRY solution difficult. I think we can certainly improve things now that there are two sports, however.

Either way... I'm stoked to be able to work with you on this, and I think we at TopLine Game Labs plan on filling out all of NFL, NBA, NHL and MLB in the next four months or so!