-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgur.js
31 lines (28 loc) · 879 Bytes
/
imgur.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
var request = require('request');
exports.search = function (q, p, callback) {
var options = {
url: 'https://api.imgur.com/3/gallery/search/' + p + '?q=' + q,
headers: {Authorization: 'Client-ID 7e988ce6dc7fe6e'},
json: true
};
function getImgLinks(err, response, body) {
if (!err && response.statusCode == 200) {
body = body.data.filter(function (image) {
if (!image.is_album) {
return image;
}
}).map(function (image) {
return {
url: image.link,
snippet: image.title,
context: 'https://imgur.com/' + image.id
};
});
callback(body);
}
else {
callback(body);
}
}
request(options, getImgLinks);
};