This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// flickr-fetcher.js | |
fetchFlickrData: function(apiKey, fetch) { | |
var url = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=' | |
+ apiKey + '&text=pugs&format=json&nojsoncallback=1' | |
return fetch(url).then(function(data) { | |
return data; | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// flickr-fetcher-spec.js | |
describe("#fetchFlickrData()", function() { | |
it("should take an API key and fetcher function argument and return a promise for JSON data.", function(done) { | |
var apiKey = "does not matter much what this is right now", | |
fakeData = { | |
photos: { | |
page: 1, | |
pages: 2872, | |
perpage: 100, | |
total: "287170", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchFlickrData: function(apiKey, fetch) { | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// flickr-fetcher.js | |
//… lược bớt cho ngắn gọn … | |
transformPhotoObj: function(photoObj) { | |
return { | |
title: photoObj.title, | |
url: FlickrFetcher.photoObjToURL(photoObj) | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('#transformPhotoObj()', function() { | |
it('should take a photo object and return an object with just title and URL', function() { | |
var input = { | |
id: '25373736106', | |
owner: '99117316@N03', | |
secret: '146731fcb7', | |
server: '1669', | |
farm: 2, | |
title: 'Dog goes to desperate measure to avoid walking on a leash', | |
ispublic: 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
transformPhotoObj: function() { | |
return { | |
title: 'Dog goes to desperate measure to avoid walking on a leash', | |
url: 'https://farm2.staticflickr.com/1669/25373736106_146731fcb7_b.jpg' | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// flickr-fetcher-spec.js | |
describe('#transformPhotoObj()', function() { | |
it('should take a photo object and return an object with just title and URL', function() { | |
var input = { | |
id: '25373736106', | |
owner: '99117316@N03', | |
secret: '146731fcb7', | |
server: '1669', | |
farm: 2, | |
title: 'Dog goes to desperate measure to avoid walking on a leash', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FlickrFetcher = { | |
photoObjToURL: function(photoObj) { | |
return [ 'https://farm', | |
photoObj.farm, '.staticflickr.com/', | |
photoObj.server, '/', | |
photoObj.id, '_', | |
photoObj.secret, '_b.jpg' | |
].join(''); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// flickr-fetcher.js | |
FlickrFetcher = { | |
photoObjToURL: function(photoObj) { | |
return 'https://farm' + photoObj.farm + '.staticflickr.com/' + photoObj.server + '/' + photoObj.id + '_' + | |
photoObj.secret + '_b.jpg'; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// flickr-fetcher-spec.js | |
describe('#photoObjToURL()', function() { | |
it('should take a photo object from Flickr and return a string', function() { | |
var input = { | |
id: '24770505034', | |
owner: '97248275@N03', | |
secret: '31a9986429', | |
server: '1577', | |
farm: 2, | |
title: '20160229090898', |