/**
 * @module utils
 */
var utils = module.exports = {};


/**
 * Given a JSON string, convert it to its base64 representation.
 *
 * @method
 * @memberOf utils
 */
utils.jsonToBase64 = function (json) {
  var bytes = new Buffer(JSON.stringify(json));

  return bytes
    .toString('base64')
    .replace(/\+/g, '-')
    .replace(/\//g, '_')
    .replace(/=+$/, '');
};


/**
 * Simple wrapper that, given a class, a property name and a method name,
 * creates a new method in the class that is a wrapper for the given
 * property method.
 *
 * @method
 * @memberOf utils
 */
utils.wrapPropertyMethod = function (Parent, name, propertyMethod) {
  var path = propertyMethod.split('.');
  var property = path.shift();
  var method = path.pop();

  Object.defineProperty(Parent.prototype, name, {
    enumerable: false,
    get: function () {
      return this[property][method].bind(this[property]);
    }
  });
}


@@ -1,12 +1,86 @@
+var Promise = require('bluebird');%0Avar request = require('superagent');%0A%0A%0A
 /**%0A * @modu
@@ -981,8 +981,720 @@
  %7D);%0A%7D%0A%0A
+%0A/**%0A * Perform a request with the given settings and return a promise that resolves%0A * when the request is successfull and rejects when there's an error.%0A *%0A * @method%0A * @memberOf utils%0A */%0Autils.getRequestPromise = function (settings) %7B%0A  return new Promise(function (resolve, reject) %7B%0A    var method = settings.method.toLowerCase();%0A    var req = request%5Bmethod%5D(settings.url);%0A%0A    for (var name in settings.headers) %7B%0A      req = req.set(name, settings.headers%5Bname%5D);%0A    %7D%0A%0A    if (typeof settings.data === 'object') %7B%0A      req = req.send(settings.data);%0A    %7D%0A%0A    req.end(function (err, res) %7B%0A      if (err) %7B%0A        reject(err);%0A        return;%0A      %7D%0A%0A      resolve(res.body);%0A    %7D);%0A  %7D);%0A%7D;%0A%0A

Add utility function that abstracts the request process