gretzky / nhl-api Goto Github PK
View Code? Open in Web Editor NEWNHL data and utilities to work with it
License: MIT License
NHL data and utilities to work with it
License: MIT License
This is the request I'm running:
nhl.getPlayer({
name: "wayne"
}).then(players => {
console.log('huh', players)
res.status(200).json({ players })
}).catch(error => {
console.log('error ', error)
res.status(500)
})
Basically just trying to fetch a player using just the name property โ but I'm getting a type error. Any help is much appreciated.
TypeError: Cannot read property 'some' of undefined
at /Users/taylorbourne/_PROJECTS/_NAMESAUCER/_WEB/namesaucer/node_modules/@nhl-api/client/lib/src/util/index.js:26:23
at Array.filter (<anonymous>)
at Object.exports.getId (/Users/taylorbourne/_PROJECTS/_NAMESAUCER/_WEB/namesaucer/node_modules/@nhl-api/client/lib/src/util/index.js:25:27)
at Object.exports.handleUrl (/Users/taylorbourne/_PROJECTS/_NAMESAUCER/_WEB/namesaucer/node_modules/@nhl-api/client/lib/src/util/index.js:45:23)
at Object.<anonymous> (/Users/taylorbourne/_PROJECTS/_NAMESAUCER/_WEB/namesaucer/node_modules/@nhl-api/client/lib/src/player/index.js:15:32)
at Generator.next (<anonymous>)
at /Users/taylorbourne/_PROJECTS/_NAMESAUCER/_WEB/namesaucer/node_modules/@nhl-api/client/lib/src/player/index.js:8:71
at new Promise (<anonymous>)
at __awaiter (/Users/taylorbourne/_PROJECTS/_NAMESAUCER/_WEB/namesaucer/node_modules/@nhl-api/client/lib/src/player/index.js:4:12)
at Object.getPlayer (/Users/taylorbourne/_PROJECTS/_NAMESAUCER/_WEB/namesaucer/node_modules/@nhl-api/client/lib/src/player/index.js:14:12)
Hi Gretzky!
First of all great work, i love what you have done and I have not ran into any issues yet. However, I am quite new with the NHL API and thankfully came accros your work. I was wondering if you could explain to me the methodology you used to write this list of players with their matching ID. With my brief experience with the NHL API I seemed to be only able to retrieve active players ID through their respective teams. How did you manage to get the ID's of non active players?
Thanks
Make a call to the .getTeams() method similar to the following:
nhlApi.getTeams({
expand: "stats"
});
Call .getTeams()
without specifying a team (via name
or id
) and use the expand
option
Example:
nhl.getTeams({
expand: "stats"
});
Here, the desired output would be an array of all teams and their current season stats, however the request will fail with a 400
code.
In the getTeams()
function there is an if...else block that checks for the inclusion of "roster" or "stats" in options.expand. If they do exist, /roster and /stats are appended to the baseUrl accordingly. If a single team was selected via an id or name, this partially works as the roster or stats for that team are returned albeit without the other team data, but if more than one team is requested these routes do not exist on the NHL's API, leading to the 400 response.
Don't add the /stats or /roster paths to the baseUrl and simply let url = baseUrl. The if statement that follows and checks for the options.expand property appends the appropriate query to the request
This also means that the expand option works as it is intended to and expands on the information provided in comparison to its omission.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.