common/corpus-common-addon/lib/commands/dl-fixtures.js
changeset 161 5f011170de74
parent 160 c77f06ff3e54
child 164 5f1e1cc17e8a
--- a/common/corpus-common-addon/lib/commands/dl-fixtures.js	Sun May 08 14:21:22 2016 +0200
+++ b/common/corpus-common-addon/lib/commands/dl-fixtures.js	Thu May 12 11:19:26 2016 +0200
@@ -47,18 +47,15 @@
         { name: 'page', type: Number, default: 1 , aliases: ['p'], description: 'number of page to download'},
         { name: 'format', type: String, default: 'es6' , aliases: ['f'], description: 'Format for module export, es6 or require'}
     ],
-    dl_discourses: function(commandOptions) {
-        return this.dl_themes(commandOptions);
-    },
-    dl_themes: function(commandOptions) {
+    dl_countmap: function(commandOptions, rootKey) {
         var done = Q.defer();
         var that = this;
         request.get({url: commandOptions.url, json: true}, function (err, res, body) {
             var objectList = _.reduce(
-                _.keys(body.themes),
-                function(res, themeKey) {
-                    var themeValue = body.themes[themeKey];
-                    res.push({id: themeKey, count: themeValue.count, label: themeValue.label});
+                _.keys(body[rootKey]),
+                function(res, objKey) {
+                    var objValue = body[rootKey][objKey];
+                    res.push({id: objKey, count: objValue.count, label: objValue.label});
                     return res;
                 },
                 []
@@ -73,6 +70,12 @@
         });
         return done.promise;
     },
+    dl_discourses: function(commandOptions) {
+        return this.dl_countmap(commandOptions, 'discourses');
+    },
+    dl_themes: function(commandOptions) {
+        return this.dl_countmap(commandOptions, 'themes');
+    },
     dl_documents: function(commandOptions, rawArgs) { // eslint-disable-line no-unused-vars
 
         var ids = [];