forked from urfu-2016/qa-task-04
-
Notifications
You must be signed in to change notification settings - Fork 0
/
showTweets.js
33 lines (28 loc) · 855 Bytes
/
showTweets.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
const formatDate = require('./formatDate');
const request = require('request');
function showTweets(cb) {
const urladdr = 'https://api.twitter.com/1.1/search/tweets.json?q=%23urfu-testing-2016';
request(urladdr, function (error, response, body) {
if (error){
console.error(error.message);
return cb();
}
else if (response.statusCode != 200) {
console.log('statusCode: ' + response.statusCode);
return cb();
}
else {
try{
const data = JSON.parse(body);
data.forEach(tweet => {
console.log(formatDate(tweet.createdAt) + '\n' + tweet.text);
});
}
catch (parseError){ // следует-ли сюда добавлять проверку на выброс Error из formatDate?
console.error(parseError.message);
}
return cb();
}
});
}
module.exports = showTweets;