forked from oxguy3/ImLiveYo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
justyo.js
46 lines (40 loc) · 1.04 KB
/
justyo.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
var request = require('request');
var config = require('./config');
var justyo = {};
/**
* Sends a yo. Calls the callback function with the id of
* the yo, or 'false' if an error occurred.
*
* The link parameter is optional
*/
justyo.yo = function(username, callback, link) {
var formData = {
'api_token': config.justyo.apiToken,
'username': username
};
if (typeof link !== 'undefined') {
formData.link = link;
}
request.post({
url: config.justyo.apiRoot + "/yo/",
form: formData
},
function (error, response, body) {
if (error || response.statusCode != 200) {
console.log('error while yoing: ' + response.statusCode);
callback(false);
return;
}
var data = JSON.parse(body);
if (typeof data.success === 'undefined'
|| !data.success
|| typeof data.yo_id === 'undefined') {
console.log('error while yoing: bad api reply');
callback(false);
return;
}
callback(data.yo_id);
}
);
}
module.exports = justyo;