bttmly / nba

Node.js client for nba.com API endpoints
MIT License
710 stars 180 forks source link

New JSON endpoints from 2014-2015 season #2

Closed albertlyu closed 9 years ago

albertlyu commented 9 years ago

Hi there -- I just stumbled upon this repo thanks to a www.poundingtherock.com post, and wanted to make you aware of some endpoints that NBA.com recently added. I figured if you knew about them already, you could update your documentation, update your codebase to pull those in as well.

The nice thing about these new endpoints are that they are summarized SportVU data (at the player level) with the same object schema as all the other endpoints you've explored (with the resource and resultSets properties and so on). They are:

There's also http://stats.nba.com/stats/videoevents but it looks non-standard. Examples of the SportVU JSON:

DeAndre Jordan shot logs: http://stats.nba.com/player/#!/201599/tracking/shotslogs/ JSON: http://stats.nba.com/stats/playerdashptshotlog?DateFrom=&DateTo=&GameSegment=&LastNGames=0&LeagueID=00&Location=&Month=0&OpponentTeamID=0&Outcome=&Period=0&PlayerID=201599&Season=2014-15&SeasonSegment=&SeasonType=Regular+Season&TeamID=0&VsConference=&VsDivision=

DeAndre Jordan rebound logs: http://stats.nba.com/player/#!/201599/tracking/reboundslogs/ JSON: http://stats.nba.com/stats/playerdashptreboundlogs?DateFrom=&DateTo=&GameSegment=&LastNGames=0&LeagueID=00&Location=&Month=0&OpponentTeamID=0&Outcome=&Period=0&PlayerID=201599&Season=2014-15&SeasonSegment=&SeasonType=Regular+Season&TeamID=0&VsConference=&VsDivision=

This data appears to be available for all of the 2013-14 season as well.

bttmly commented 9 years ago

Awesome, thanks for the heads up! The shot log defender distance is super interesting. I'll try to get these in soon, or if you want to take a shot at it open up a PR – might not be able to get to it for a bit

albertlyu commented 9 years ago

Hi @nickb1080, sure! I'd love to give this a shot this week. Without npm install nba-ing yet and looking strictly at the codebase, here's my guess at what I should be modifying:

So this is all just a guess, and if you have the time, feel free to let me know if there's anything else I missed additionally. Also, which node module do you use to minify nba.js? I'm also not exactly sure how else I can 'manually test' to make sure the scraping works. Do you simply run a bunch of getJSON commands? Forgive me as I'm somewhat new to node, though I do have node and npm on my machines.

calesce commented 9 years ago

@albertlyu, looks like you'll need to do npm run build-all, which uses UglifyJS to minify the code. You can see that all in the package.json, as well as the other scripts for testing, linting, etc.

I also found a few more endpoints I didn't see listed, but correct me if I'm wrong. I'll try my best to implement these, as well, but am pretty new to node as well. :

bttmly commented 9 years ago

Hey guys, so basically the only source file you should have to modify is lib/endpoints.js. Each endpoint gets made into an API method in lib/api.js. Each endpoint is like

someMethod: {
  url: "http://stats.nba.com/stats/somemethod",
  defaults: function () {
    return { /* object with defaults for this endpoint */ },
  },
  transform: /* transformation function applied to result before passing it back */
}

(I should really add a utility function that takes a query string and turns it into a default object.)

After adding to endpoints.js, run npm build-all to bundle up the code into the dist directory. Tests on endpoints go in test/api-test.js but, as you can see, they're not very comprehensive.

Thanks for the help, much appreciated!

bttmly commented 9 years ago

Looks like #4 resolves this.