-
Notifications
You must be signed in to change notification settings - Fork 0
/
met.js
46 lines (43 loc) · 1.47 KB
/
met.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
const request = require('request');
function searchObjects(param, callback) {
const museumUrl = "https://collectionapi.metmuseum.org/public/collection/v1/search?q=" + param;
request({url: museumUrl, json: true}, function(error, response){
if(error) {
callback('something went wrong :(', undefined);
}
else if(response.body.total == 0) {
callback('No se econtraron objetos con ese termino', undefined);
}
else {
const result = {
objectId: response.body.objectIDs[0]
}
callback(undefined, result);
}
})
}
function getInfoOfObject(param, callback) {
const url = "https://collectionapi.metmuseum.org/public/collection/v1/objects/" + param;
request({url: url, json: true}, function(error, response) {
if(error) {
callback('something went wrong :(', undefined);
}
else if(response.body.message == "ObjectID not found") {
callback('object id no valido', undefined);
}
else {
const data = {
artist : response.body.constituents[0].name,
title: response.body.title,
year: response.body.objectEndDate,
technique: response.body.medium,
metUrl: response.body.objectURL
}
callback(undefined, data);
}
})
}
module.exports = {
getObject: searchObjects,
getInfo: getInfoOfObject
}