lib/main.js
function(project) {
        return request.read(project.lang_catalog)
            .then(function(response) {
                // consume language data
                if(response.status !== 200) return Promise.reject(response);

                let data;
                try {
                    data = JSON.parse(response.data);
                } catch(err) {
                    return Promise.reject(err);
                }

                let projects = [];
                for(let language of data) {
                    try {
                        let language_id = library.addSourceLanguage({
                            slug: language.language.slug,
                            name: language.language.name,
                            direction: language.language.direction
                        });

                        project.categories = _.map(project.meta, function (names, slug, index) {
                            return {name: names[index], slug: slug};
                        }.bind(this, language.project.meta));

                        if (project.slug.toLowerCase() !== 'obs') {
                            project.chunks_url = 'https://api.unfoldingword.org/bible/txt/1/' + project.slug + '/chunks.json';
                        }

                        let projectId = library.addProject({
                            slug: project.slug,
                            name: language.project.name,
                            desc: language.project.desc,
                            icon: project.icon,
                            sort: project.sort,
                            chunks_url: project.chunks_url,
                            categories: project.categories,
                        }, language_id);

                        projects.push({
                            id: projectId,
                            chunks_url: project.chunks_url,
                            slug: project.slug,
                            resourceUrl: language.res_catalog,
                            source_language_slug: language.language.slug,
                            source_language_id: language_id
                        });
                    } catch (err) {
                        return Promise.reject(err);
                    }
                }

                // TRICKY: we just flipped the data hierarchy from project->lang to lang->project for future compatibility
                return projects;
            });
    }
function(project) {
        return request.read(project.lang_catalog)
            .then(function(response) {
                // consume language data
                if(response.status !== 200) return Promise.reject(response);

                let data;
                try {
                    data = JSON.parse(response.data);
                } catch(err) {
                    return Promise.reject(err);
                }

                let projects = [];
                for(let language of data) {
                    try {
                        let language_id = library.addSourceLanguage({
                            slug: language.language.slug,
                            name: language.language.name,
                            direction: language.language.direction
                        });

                        project.categories = _.map(project.meta, function (names, slug, index) {
                            return {name: names[index], slug: slug};
                        }.bind(this, language.project.meta));

                        if (project.slug.toLowerCase() !== 'obs') {
                            project.chunks_url = 'https://api.unfoldingword.org/bible/txt/1/' + project.slug + '/chunks.json';
                        }

                        let projectId = library.addProject({
                            slug: project.slug,
                            name: language.project.name,
                            desc: language.project.desc,
                            icon: project.icon,
                            sort: project.sort,
                            chunks_url: project.chunks_url,
                            categories: project.categories,
                        }, language_id);

                        projects.push({
                            id: projectId,
                            chunks_url: project.chunks_url,
                            slug: project.slug,
                            resourceUrl: language.res_catalog,
                            source_language_slug: language.language.slug,
                            source_language_id: language_id
                        });
                    } catch (err) {
                        return Promise.reject(err);
                    }
                }

                // TRICKY: we just flipped the data hierarchy from project->lang to lang->project for future compatibility
                return projects;
            });
    }
function ( project ) { return request . read ( project . lang_catalog ) . then ( function ( response ) { // consume language data if ( response . status !== 200 ) return Promise . reject ( response ) ; let data ; try { data = JSON . parse ( response . data ) ; } catch ( err ) { return Promise . reject ( err ) ; } let projects = [ ] ; for ( let language of data ) { try { let language_id = library . addSourceLanguage ( { slug : language . language . slug , name : language . language . name , direction : language . language . direction } ) ; project . categories = _ . map ( project . meta , function ( names , slug , index ) { return { name : names [ index ] , slug : slug } ; } . bind ( this , language . project . meta ) ) ; if ( project . slug . toLowerCase ( ) !== 'obs' ) { project . chunks_url = 'https://api.unfoldingword.org/bible/txt/1/' + project . slug + '/chunks.json' ; } let projectId = library . addProject ( { slug : project . slug , name : language . project . name , desc : language . project . desc , icon : project . icon , sort : project . sort , chunks_url : project . chunks_url , categories : project . categories , } , language_id ) ; projects . push ( { id : projectId , chunks_url : project . chunks_url , slug : project . slug , resourceUrl : language . res_catalog , source_language_slug : language . language . slug , source_language_id : language_id } ) ; } catch ( err ) { return Promise . reject ( err ) ; } } // TRICKY: we just flipped the data hierarchy from project->lang to lang->project for future compatibility return projects ; } ) ; }
Downloads the source languages for a project
@param project {{}}
@returns {Promise}
Downloads the source languages for a project