forked from whatadewitt/yahoo-fantasy-sports-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
YahooFantasy.mjs
83 lines (64 loc) · 1.54 KB
/
YahooFantasy.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* global module, require */
// ("use strict");
import {
Game,
League,
Player,
Roster,
Team,
Transaction,
User
} from "./resources";
import { Games, Leagues, Players, Teams } from "./collections"; // Transactions, Users } from "./collections";
import request from "request";
class YahooFantasy {
constructor(consumerKey, consumerSecret) {
this.GET = "GET";
this.POST = "POST";
this.game = new Game(this);
this.games = new Games(this);
this.league = new League(this);
this.leagues = new Leagues(this);
this.player = new Player(this);
this.players = new Players(this);
this.team = new Team(this);
this.teams = new Teams(this);
this.transaction = new Transaction(this);
// this.transactions = new Transactions(this);
this.roster = new Roster(this);
this.user = new User(this);
// this.users = new Users(); // TODO
this.yahooUserToken = null;
}
setUserToken(token) {
this.yahooUserToken = token;
}
api(...args) {
const method = args.shift();
const url = args.shift();
const cb = args.pop();
let postData = false;
if (args.length) {
postData = args.pop();
}
var options = {
url: url,
method: method,
json: true,
auth: {
bearer: this.yahooUserToken
}
};
request(options, (e, body, data) => {
if (e) {
return cb(e);
} else {
if (data.error) {
return cb(data.error);
}
return cb(null, data);
}
});
}
}
export default YahooFantasy;