-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.js
44 lines (33 loc) · 1.04 KB
/
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
var spashttp = require("spas-http")
, _ = require("underscore")._
, url = "https://api.smugmug.com/services/api/json/1.3.0/?method="
;
//
// ## Custom - These do not have equivelants in the SmugMug API
//
exports["custom"] = {
getAlbumsWithPhotos: function(params, credentials, cb) {
params.url = url + "smugmug.albums.get";
spashttp.request(params, credentials, function( err, albums ) {
var result, error;
if (!err) {
var n = albums && albums.Albums ? albums.Albums.length : 0;
_.each(albums.Albums, function( obj, key) {
params.url = url + "smugmug.images.get" + "&Heavy=true&AlbumID=" + obj.id + "&AlbumKey=" + obj.Key + "&APIKey="+params.APIKey;
spashttp.request(params, credentials, function( err, photos ) {
n = n - 1;
if (_.has(photos, 'Album')) {
albums.Albums[key].Images = photos.Album.Images;
albums.size += photos.size;
}
if (n === 0) {
cb( null, albums );
}
});
});
} else {
cb(error, {} );
}
});
}
}