-
Notifications
You must be signed in to change notification settings - Fork 0
/
getData.js
35 lines (33 loc) · 1.12 KB
/
getData.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
var getData = {
photoObjToURL: function(photoObj) {
return [ 'https://farm',
photoObj.farm, '.staticflickr.com/',
photoObj.server, '/',
photoObj.id, '_',
photoObj.secret, '_b.jpg'
].join('');
},
transformPhotoObj: function(photoObj) {
return {
title: photoObj.title,
url: getData.photoObjToURL(photoObj)
};
},
getFlickrData: function(apiKey, fetch) {
if ((!fetch) && (typeof jQuery !== 'undefined')) {
fetch = jQuery.getJSON.bind(jQuery);
}
var url = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=' +
apiKey + '&text=travel+spain&safe_search=1&format=json&nojsoncallback=1';
return fetch(url);
},
getPhotosThenMap: function(apiKey, fetch) {
return getData.getFlickrData(apiKey, fetch)
.then(function(data) {
return data.photos.photo.map(getData.transformPhotoObj);
});
}
};
if ((typeof module !== 'undefined') && (typeof module.exports !== 'undefined')) {
module.exports = getData;
}