refactor api

diff --git a/.fstimizelyrc b/.fstimizelyrc
index 1cdf587..3d96a53 100644
--- a/.fstimizelyrc
+++ b/.fstimizelyrc
@@ -1,7 +1 @@
-{
-  // https://www.optimizely.com/tokens
-  "api_token": "abcdefghijklmnopqrstuvwxyz:123456",
-
-  // https://www.optimizely.com/edit?experiment_id=123456789
-  "experiment_id": "1234567890"
-}
+experiment_id=1451760292
diff --git a/fstimizely.js b/fstimizely.js
index 3e453a4..d35082a 100755
--- a/fstimizely.js
+++ b/fstimizely.js
@@ -10,15 +10,22 @@ var conf = require('rc')('fstimizely', {});
 var prompt = require('sync-prompt').prompt;
 var yesNo = require('yes-no').parse;
 var jsdiff = require('diff');
+var git = require('git-promise');
+var gitUtil = require('git-promise/util');
 require('colors');

+var log = function () {
+  if (arguments[0] !== undefined)
+    console.log(arguments[0]);
+};
+
 var onError = function (err) {
-  console.log('ERROR :( / Docs: https://github.com/tomfuertes/fstimizely');
-  console.log(err);
+  log('ERROR :( / Docs: https://github.com/tomfuertes/opthub');
+  log(err);
 };

 var different = function (start, end) {
-  // console.log(start, end);
+  // log(start, end);
   var diff = jsdiff.diffLines(start, end);
   diff.forEach(function (part) {
     // green for additions, red for deletions
@@ -27,17 +34,12 @@ var different = function (start, end) {
       part.removed ? 'red' : 'grey';
     process.stderr.write(part.value[color]);
   });
-  console.log();
+  log();
   return start != end; // jshint ignore:line
 };

-if (!conf.api_token || conf.api_token === 'abcdefghijklmnopqrstuvwxyz:123456' ||
-  !conf.experiment_id || conf.experiment_id === '123456789') {
-  console.error('.fstimizelyrc needs to have an api_token and experiment_id');
-  console.error('EXAMPLE: https://github.com/tomfuertes/fstimizely/blob/master/.fstimizelyrc');
-  throw new Error('rc config error');
-}
-
+if (!conf.api_token) throw new Error('.opthubrc needs to have an api_token');
+if (!conf.experiment_id) throw new Error('.opthubrc needs to have an experiment_id');

 var client = request.newClient('https://www.optimizelyapis.com/experiment/v1/', {
   headers: {
@@ -64,8 +66,8 @@ var put = function (url, data) {
 };

 var getAnswer = function (q) {
-  var a = prompt(q + '? [Y/n]: ');
-  if (a === '') a = true;
+  var a = prompt(q + '? [y/N]: ');
+  if (a === '') a = false;
   else a = yesNo(a);
   return a;
 };
@@ -73,7 +75,7 @@ var getAnswer = function (q) {
 var conditionalWriteFile = function (name, txt) {
   fs.readFile(name, function (err, data) {
     if (err) data = '';
-    console.log(('############ diff of ' + name + ' ############').blue);
+    log(('############ diff of ' + name + ' ############').blue);
     if (different(data.toString(), txt)) {
       if (getAnswer('Write diff to ' + name))
         fs.writeFile(name, txt);
@@ -81,47 +83,69 @@ var conditionalWriteFile = function (name, txt) {
   });
 };

-
-get('experiments/' + conf.experiment_id + '/')
-  .then(function (experiment) {
-    function processGlobal(fileName, key) {
-      fs.readFile(fileName, function (err, data) {
-        if (different(experiment[key], data.toString())) {
-          if (getAnswer('Upload diff to ' + fileName)) {
-            var x = {};
-            x[key] = data.toString();
-            put('experiments/' + experiment.id, x).fail(onError);
+function getExperiments(eid) {
+  get('experiments/' + eid + '/')
+    .then(function (experiment) {
+      function processGlobal(fileName, key) {
+        fs.readFile(fileName, function (err, data) {
+          if (err) return;
+          if (different(experiment[key], data.toString())) {
+            if (getAnswer('Upload diff to ' + fileName)) {
+              var x = {};
+              x[key] = data.toString();
+              put('experiments/' + experiment.id, x, log).then(function () {
+                log('Uploaded to: https://www.optimizely.com/edit?experiment_id=' + eid);
+              });
+            }
           }
-        }
-      });
-    }
+        });
+      }

-    if (UPLOAD) {
-      processGlobal('global.js', 'custom_js');
-      processGlobal('global.css', 'custom_css');
-    } else {
-      conditionalWriteFile('global.js', experiment.custom_js);
-      conditionalWriteFile('global.css', experiment.custom_css);
-    }
-  }, onError);
+      if (UPLOAD) {
+        processGlobal('global.js', 'custom_js');
+        processGlobal('global.css', 'custom_css');
+      } else {
+        conditionalWriteFile('global.js', experiment.custom_js);
+        conditionalWriteFile('global.css', experiment.custom_css);
+      }
+    }, onError);
+}

-get('experiments/' + conf.experiment_id + '/variations/')
-  .then(function (variations) {
-    if (UPLOAD) {
-      variations.forEach(function (variation) {
-        var name = slug(variation.description).toLowerCase() + '.js';
-        fs.readFile(name, function (err, data) {
-          if (different(variation.js_component, data.toString())) {
-            if (getAnswer('Upload diff to ' + name)) {
-              variation.js_component = data.toString();
-              put('variations/' + variation.id, variation).fail(onError);
+function getVariations(eid) {
+  get('experiments/' + eid + '/variations/')
+    .then(function (variations) {
+      if (UPLOAD) {
+        variations.forEach(function (variation) {
+          var name = slug(variation.description).toLowerCase() + '.js';
+          fs.readFile(name, function (err, data) {
+            if (err) return;
+            if (different(variation.js_component, data.toString())) {
+              if (getAnswer('Upload diff to ' + name)) {
+                variation.js_component = data.toString();
+                put('variations/' + variation.id, variation).then(function () {
+                  log('Uploaded to: https://www.optimizely.com/edit?experiment_id=' + eid);
+                });
+              }
             }
-          }
+          });
+        });
+      } else {
+        variations.forEach(function (variation) {
+          conditionalWriteFile(slug(variation.description).toLowerCase() + '.js', variation.js_component);
         });
-      });
-    } else {
-      variations.forEach(function (variation) {
-        conditionalWriteFile(slug(variation.description).toLowerCase() + '.js', variation.js_component);
-      });
+      }
+    }, onError);
+}
+
+git('status --porcelain', gitUtil.extractStatus).then(function (status) {
+  var err;
+  ['modified', 'added', 'deleted', 'renamed', 'copied'].forEach(function (b) {
+    if (status.workingTree[b].length) {
+      err = 'dirty git tree - please stash/commit first';
+      console.error(err.red);
+      throw err;
     }
-  }, onError);
+  });
+  getExperiments(conf.experiment_id);
+  getVariations(conf.experiment_id);
+});
diff --git a/package.json b/package.json
index 3967ed6..348741e 100644
--- a/package.json
+++ b/package.json
@@ -7,13 +7,13 @@
     "fstimizely": "./fstimizely.js"
   },
   "devDependencies": {
-    "request-json": "^0.4.10",
+    "colors": "^0.6.2",
+    "diff": "^1.0.8",
+    "git-promise": "^0.2.0",
     "q": "^1.0.1",
-    "q-io": "^1.11.2",
     "rc": "^0.4.0",
+    "request-json": "^0.4.11",
     "slug": "^0.5.0",
-    "colors": "^0.6.2",
-    "diff": "^1.0.8",
     "sync-prompt": "^0.4.1",
     "yes-no": "0.0.1"
   },