-
Notifications
You must be signed in to change notification settings - Fork 0
/
qonto_test_giphy_api.js
58 lines (38 loc) · 1.19 KB
/
qonto_test_giphy_api.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
const request = require('request');
var api = "https://api.giphy.com/v1/gifs/trending?" ;
var api_key = "&api_key=XG886kbVNTrJZf09J6mhV93jKxzBiGgs" ;
var limit = "&limit=5" ;
//var query = "&q=bob" ;
var url_giphy = api + api_key + limit ;
function getData(url){
request(url, { json: true }, (err, res, body) => {
if (err) { return console.log(err); }
//print(body)
printFiltered(body);
});
}
function print(value){
var json_output = [] ;
for ( var i = 0 ; i < value.data.length ; i++)
json_output.push({
type: value.data[i].type ,
id : value.data[i].id ,
url : value.data[i].url ,
title : value.data[i].title ,
rating : value.data[i].rating })
console.log(json_output);
}
function printFiltered(value){
var json_output = [] ;
for ( var i = 0 ; i < value.data.length ; i++)
json_output.push({
type: value.data[i].type ,
id : value.data[i].id ,
url : value.data[i].url ,
title : value.data[i].title ,
rating : value.data[i].rating })
var json_filtered = json_output.filter(function(i){
return i.rating !== 'r' ;})
console.log(json_filtered);
}
getData(url_giphy);