'use strict';
var unirest = require('unirest'),
    config = require('../../config/'),
    fs = require('fs-extra');

exports.putPackageData = function(name, version) {
  return new Promise(function(resolve, reject) {
    unirest.put(config.moServer + "/api/packages/" + name + "/" + version)
      .header('Accept', 'application/json')
      .field('s', 'f')
      .attach({'package': '' + name + "-" + version + ".zip"})
      .end(function(response) {
        if(response.error) {
          return reject(response.error.message)
        }

        if(response.status !== 200) {
          return reject(response.body)
        }

        fs.remove('' + name + "-" + version + ".zip", function(err) {
          return resolve(response.body)
        })
      })

  })
}

exports.postPackageData = function(json) {
  return new Promise(function(resolve, reject) {
    unirest.post(config.moServer + '/api/packages')
      .header('Accept', 'application/json')
      .type('json')
      .send({"data": json})
      .end(function (response) {
        if(response.error) {
          return reject(response.error.message)
        }
        
        if(response.status !== 200) {
          return reject(response.body)
        }

        return resolve(response.body)
      });
  })
}

exports.deletePackage = function(json) {
  return new Promise(function(resolve, reject) {
    unirest.delete(config.moServer + '/api/packages/' + json.name)
      .header('Accept', 'application/json')
      .type('json')
      .end(function (response) {
        if(response.error) {
          return reject(response.error.message)
        }

        if(response.status !== 200) {
          return reject(response.body.error)
        }
        
        return resolve(response.body)
      });
  })
}

@@ -460,32 +460,54 @@
     if(response.
+body && response.body.
 error) %7B%0A       
@@ -528,37 +528,34 @@
 ct(response.
+body.
 error
-.message
 )%0A        %7D%0A
@@ -1063,32 +1063,54 @@
     if(response.
+body && response.body.
 error) %7B%0A       
@@ -1131,37 +1131,34 @@
 ct(response.
+body.
 error
-.message
 )%0A        %7D%0A
@@ -1153,32 +1153,24 @@
 )%0A        %7D%0A
-        
 %0A        if(

fix messages