// Generated by CoffeeScript 1.10.0
(function() {
  var createUpdater, request;

  request = require('request');

  createUpdater = function(app) {
    var api, updateDD;
    updateDD = function() {
      if (!app.config.useMobileDetect) {
        console.log('Not going to download MobileDetect');
        return;
      }
      return request({
        url: 'https://raw.githubusercontent.com/serbanghita/Mobile-Detect/master/Mobile_Detect.json',
        json: true
      }, function(err, response, body) {
        if (err != null) {
          return console.error('Error updating MobileDetect: ' + err);
        } else if (body) {
          if (!app.config.MobileDetect || body.version !== app.config.MobileDetect.version) {
            app.config.MobileDetect = body;
            return app.saveConfig(function(err) {
              if (err != null) {
                return console.error('Error updating MobileDetect: ' + err);
              } else {
                return console.log('MobileDetect updated to ' + body.version);
              }
            });
          } else {
            return console.log('MobileDetect is up-to-date');
          }
        }
      });
    };
    return api = {
      init: function(cb) {
        updateDD();
        return cb();
      }
    };
  };

  module.exports = createUpdater;

}).call(this);
