var rest = require('./rest');

module.exports.init = function (projectId) {
    
    var module = {};

    var fetchProjectSlug = function (projectid, cb) {
        rest.fetch(process.env.API_URL, '/projects/' + projectId, process.env.API_KEY, function (project) {
            console.log(project.name);
            var slug = project.name.replace(/ /g, '-');
            slug = slug.toLowerCase();
            console.log(slug);
            cb(slug);
        });
    };

    var tasks = function (cb) {
        fetchProjectSlug(projectId, function (projectSlug) {
            var endpoint = '/projects/' + projectSlug + '/tasks';
            console.log(endpoint);
            rest.fetch(process.env.API_URL, endpoint, process.env.API_KEY, cb);
        });
        
    };

    tasks.archived = function (cb) {
        fetchProjectSlug(projectId, function (projectSlug) {
            rest.fetch(process.env.API_URL, '/projects/' + projectSlug + '/tasks/archive', process.env.API_KEY, cb);
        });
    };

    tasks.add = function (data, cb) {
        data = formatBodyDataForSending('task', data);
        fetchProjectSlug(projectId, function (projectSlug) {
            rest.create(process.env.API_URL, '/projects/' + projectSlug + '/tasks/add', process.env.API_KEY, data, cb);
        });
    };

    var task = function (id, cb) {
        
        //if a callback is provided...
        if (typeof cb === 'function') {
            fetchProjectSlug(projectId, function (projectSlug) {
                rest.fetch(process.env.API_URL, '/projects/' + projectSlug + '/tasks/' + id, process.env.API_KEY, cb);
                return;
            });
        }

        return {
            'edit': function (data, cb) {
                data = formatBodyDataForSending('task', data);
                fetchProjectSlug(projectId, function (projectSlug) {
                    rest.edit(process.env.API_URL, '/projects/' + projectSlug + '/tasks/' + id + '/edit', process.env.API_KEY, data, cb);
                });
            }
        };
        

    };

    module.tasks = tasks;

    module.task = task;

    return module;

};



@@ -25,223 +25,144 @@
 st')
-;%0A%0Amodule.exports.init = function (projectId) %7B%0A    %0A    var module = %7B%7D;%0A%0A    var fetchProjectSlug = function (projectid, cb) %7B%0A        rest.fetch(process.env.API_URL, '/projects/' + projectId, process.env.API_KEY,
+,%0A    formatBodyDataForSending = require('./bodyDataFormatter'),%0A    fetchProjectSlug = require('./projectSlug');%0A%0Amodule.exports.init =
  fun
@@ -175,24 +175,26 @@
 (project
+Id
 ) %7B%0A    
         
@@ -189,207 +189,27 @@
     
-        console.log(project.name);%0A            var slug = project.name.replace(/ /g, '-');%0A            slug = slug.toLowerCase();%0A            console.log(slug);%0A            cb(slug);%0A        %7D);%0A    
+%0A    var module = %7B
 %7D;%0A%0A

Remove fetchProjectSlug method from module