yahoo-fantasy
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -9,3 +9,2 @@ var _ = require('lodash'); | ||
exports.teamsMap = function(teams) { | ||
// todo: use team helper | ||
teams = _.filter(teams, function(t) { return typeof(t) == 'object'; }); | ||
@@ -52,2 +51,3 @@ teams = _.map(teams, function(t) { return teamHelper.mapTeam(t.team[0]); }); | ||
exports.scoreboardMap = function(scoreboard) { | ||
var self = this; | ||
// is this only for h2h? what about roto, and points? | ||
@@ -58,55 +58,16 @@ var matchups = _.filter(scoreboard, function(s) { return typeof(s) == 'object'; }); | ||
_.each(matchups, function(matchup) { | ||
// clean this up, but time... | ||
matchup.teams = []; | ||
var teams_data = matchup[0].teams; | ||
teams_data = _.filter(teams_data, function(t) { return typeof(t) == 'object'; }); | ||
var teams = _.map(teams_data, function(t) { return t.team[0]; }); | ||
var teams = matchup[0].teams; | ||
teams = _.filter(teams, function(t) { return typeof(t) == 'object'; }); | ||
teams = _.map(teams, function(t) { | ||
return { | ||
team_key: t[0].team_key, | ||
team_id: t[1].team_id, | ||
name: t[2].name, | ||
is_owned_by_current_login: t[3].is_owned_by_current_login, | ||
url: t[4].url, | ||
team_logo: t[5].team_logos[0].team_logo.url, | ||
waiver_priority: t[7].waiver_priority, | ||
number_of_moves: t[9].number_of_moves, | ||
number_of_trades: t[10].number_of_trades, | ||
// wtf is "roster adds" object? | ||
clinched_playoffs: t[12].clinched_playoffs, | ||
managers: _.map(t[13].managers, function(mgr) { | ||
return mgr.manager; | ||
}) | ||
}; | ||
}); // good, but ugly (codewise)... | ||
var team = teamHelper.mapTeam(t.team[0]); | ||
var scoring_data = _.map(teams_data, function(t) { return t.team[1]; }); | ||
team.points = t.team[1].team_points; | ||
team.stats = self.mapStats(t.team[1].team_stats.stats); | ||
var team_points = _.map(scoring_data, function(s) { return s.team_points; }); | ||
return team; | ||
}); | ||
// y so ugly | ||
var team_stats = _.map(scoring_data, function(s) { return s.team_stats; }); | ||
var stats = _.map(team_stats, function(s) { return s.stats }); | ||
stats[0] = _.map(stats[0], function(stat) { return stat.stat; }); | ||
stats[1] = _.map(stats[1], function(stat) { return stat.stat; }); | ||
team_stats[0].stats = stats[0]; | ||
team_stats[1].stats = stats[1]; | ||
// remove ugly data; | ||
delete matchup[0]; | ||
// gotta be a better way... | ||
matchup.teams.push({ | ||
team: teams[0], | ||
team_points: team_points[0], | ||
team_stats: team_stats[0] | ||
}); | ||
matchup.teams.push({ | ||
team: teams[1], | ||
team_points: team_points[1], | ||
team_stats: team_stats[1] | ||
}); | ||
matchup.teams = teams; | ||
}); | ||
@@ -120,7 +81,3 @@ | ||
// TODO: this map is re-used pretty much everywhere (to start, at least) | ||
exports.transactionMap = function(transactions) { | ||
// count actually useful here... | ||
var count = transactions.count; | ||
var transactions = _.filter(transactions, function(t) { return typeof(t) == 'object'; }); | ||
@@ -135,5 +92,10 @@ transactions = _.map(transactions, function(t) { return t.transaction; }); | ||
transactions.count = count; | ||
return transactions; | ||
}; | ||
exports.mapStats = function(stats) { | ||
stats = _.filter(stats, function(s) { return typeof(s) == 'object'; }); | ||
stats = _.map(stats, function(s) { return s.stat; }); | ||
return stats; | ||
}; |
var _ = require('lodash'); | ||
var playerHelper = require('./playerHelper.js'); | ||
var leagueHelper = require('./leagueHelper.js'); | ||
@@ -48,1 +49,27 @@ // todo: use this where possible... | ||
}; | ||
// todo: this gotta be cleaned up | ||
exports.mapMatchups = function(matchups) { | ||
var self = this; | ||
matchups = _.filter(matchups, function(m) { return typeof(m) == 'object'; }); | ||
matchups = _.map(matchups, function(m) { return m.matchup; }); | ||
debugger; | ||
matchups = _.map(matchups, function(m) { | ||
var teams = _.filter(m[0].teams, function(t) { return typeof(t) == 'object'; }); | ||
m.teams = _.map(teams, function(t) { | ||
var team = self.mapTeam(t.team[0]); | ||
team.points = t.team[1].team_points; | ||
team.stats = leagueHelper.mapStats(t.team[1].team_stats.stats); | ||
return team; | ||
}); | ||
delete m[0]; | ||
return m; | ||
}); | ||
return matchups; | ||
} |
{ | ||
"name": "yahoo-fantasy", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "An API to help facilitate the use of the Yahoo! Fantasy Sports API in NodeJS projects.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -57,2 +57,7 @@ Yahoo! Fantasy API Node Module | ||
#### 0.1.2 | ||
* Added 'Team Matchups' subresource | ||
* Added 'League Scoreboard' subresource | ||
* Minor code cleanup and improvements | ||
#### 0.1.1 | ||
@@ -59,0 +64,0 @@ * Refactored module to fix a bug where user sessions were not necessarily unique because of require caching. |
@@ -60,7 +60,7 @@ var leagueHelper = require('../helpers/leagueHelper.js'); | ||
// h2h only | ||
// todo: add weeks param | ||
LeagueResource.prototype.scoreboard = function(leagueKey, cb) { | ||
var self = this; | ||
// h2h only? | ||
this | ||
@@ -73,13 +73,5 @@ .api('http://fantasysports.yahooapis.com/fantasy/v2/league/' + leagueKey + '/scoreboard?format=json') | ||
league.scoreboard = scoreboard; | ||
league.scoreboard = scoreboard; | ||
league.scoreboard.week = week; | ||
// make sense to bring back 1 scoreboard, with all the matchups? | ||
// could mess up the consolation thing | ||
// scoreboard | ||
// matchups[] | ||
// teams[] | ||
// ??? -- seems better | ||
cb(league); | ||
@@ -86,0 +78,0 @@ }, function(e) { |
@@ -97,12 +97,16 @@ var teamHelper = require('../helpers/teamHelper.js'); | ||
// todo: this | ||
TeamResource.prototype.matchups = function(teamKey, weeks, cb) { | ||
// h2h leagues only | ||
// todo: add weeks param | ||
TeamResource.prototype.matchups = function(teamKey, cb) { | ||
var self = this; | ||
this | ||
.api('http://fantasysports.yahooapis.com/fantasy/v2/team/' + teamKey + '/matchups;weeks=' + weeks.split(',') + '?format=json') | ||
.api('http://fantasysports.yahooapis.com/fantasy/v2/team/' + teamKey + '/matchups?format=json') | ||
.then(function(data) { | ||
var matchups = data.fantasy_content; | ||
var matchups = teamHelper.mapMatchups(data.fantasy_content.team[1].matchups); | ||
var team = teamHelper.mapTeam(data.fantasy_content.team[0]); | ||
cb(matchups); | ||
team.matchups = matchups; | ||
cb(team); | ||
}, function(e) { | ||
@@ -109,0 +113,0 @@ self.err(e, cb); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67
47527
1247