Node.js and express wrapper for Yahoo Fantasy API

With the NFL season just 31 days away (8/3/2014), I'm proud to release a Node.js wrapper for the Yahoo Fantasy API! It's not a whole lot yet, and basically just helps with the setup and not with individual API calls, but it's still one of the only one's around, and should greatly ease the pain of working with the API.

https://github.com/jcreamer898/fantasy-sports

You can check out the README on the repository for a more in depth look, but the basic idea is you setup an express app, setup some options, and hook into a few routes to setup and call the API.

var FantasySports = require('FantasySports');  
FantasySports.options({  
    "accessTokenUrl": "https://api.login.yahoo.com/oauth/v2/get_request_token",
    "requestTokenUrl": "https://api.login.yahoo.com/oauth/v2/get_token",
    "oauthKey": process.env.OAUTHKEY,
    "oauthSecret": process.env.OAUTHSECRET,
    "version": "1.0",
    "callback": "http://yourwebsite.com//auth/oauth/callback",
    "encryption": "HMAC-SHA1"
});

// app.get("/auth/oauth")
exports.oauth = function(req, res) {  
    FantasySports.startAuth(req, res);
};

// app.get("/auth/oauth/callback")
exports.authorize = function(req, res) {  
    FantasySports.endAuth(req, res);
};

exports.myTeams = function(req, res) {  
    FantasySports
        .request(req, res)
        .api('http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=nfl/leagues?format=json')
        .done(function(data) {
            // Do stuff with data
            res.json(/* your response */);
        });
};

Hope it'll ease your pain in setting up your own Fantasy App for your league!

As usual per OSS, feel free to have at it and let me know if you have questions or any feature ideas.

Jonathan Creamer

Read more posts by this author.

comments powered by Disqus