forked from shindigs/node-twitchtv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-twitchtv.js
99 lines (76 loc) · 2.52 KB
/
node-twitchtv.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var request = require("request"),
_ = require("underscore")
logger = require("winston");
var twitch_url = "https://api.twitch.tv/kraken";
TwitchClient = function(config) {
try {
this.client_id = config.client_id;
this.username = config.username;
this.password = config.password;
this.scope = config.scope;
} catch (err) {
logger.warn("Please remember to set your client_id!");
}
return this;
};
TwitchClient.prototype.auth = function authenticate(config) {
logger.warn("Authorization is still being implemented.");
var params = _.extend({}, {
client_id: this.client_id,
username: this.username,
password: this.password,
scope: this.scope,
response_type: "token"
}, config);
request.post({
url: twitch_url + "/oauth2/authorize",
form: params
}, function(err, response, body) {
});
};
TwitchClient.prototype.games = function retrieveGames(params, callback) {
if (!callback || typeof callback != 'function') return false;
var self = this;
request.get({
url: twitch_url + "/games/top",
qs: params
}, function(err, response, body) {
body = JSON.parse(body);
var games = body.top;
if (callback) callback.call(self, null, games, body);
});
};
TwitchClient.prototype.channels = function retrieveChannels(params, callback) {
if (!callback || typeof callback != 'function') return false;
if (typeof params.channel == 'undefined' || !params.channel) return false;
var self = this;
request.get({
url: twitch_url + "/channels/" + params.channel
}, function(err, response, body) {
body = JSON.parse(body);
if (callback) callback.call(self, null, body);
});
};
TwitchClient.prototype.streams = function retrieveStreams(params, callback) {
if (!callback || typeof callback != 'function') return false;
if (typeof params.stream == 'undefined' || !params.stream) return false;
var self = this;
request.get({
url: twitch_url + "/streams/" + params.stream
}, function(err, response, body) {
body = JSON.parse(body);
if (callback) callback.call(self, null, body);
});
};
TwitchClient.prototype.users = function retrieveUserInformation(params, callback) {
if (!callback || typeof callback != 'function') return false;
if (typeof params.user == 'undefined' || !params.user) return false;
var self = this;
request.get({
url: twitch_url + "/users/" + params.user
}, function(err, response, body) {
body = JSON.parse(body);
if (callback) callback.call(self, null, body);
});
};
module.exports = TwitchClient;