<commit_before>var fs = require('fs'),
    path = require('path'),
    parseUrl = require('url').parse,
    request = require('request'),
    argv = require('optimist').argv,
    prompt = require('prompt'),
    FormData = require('form-data'),
    IonicProject = require('./project'),
    IonicTask = require('./task').IonicTask,
    IonicStats = require('./stats').IonicStats;
    Task = require('./task').Task,
    IonicLoginTask = require('./login').IonicTask;

var IonicTask = function() {};

IonicTask.prototype = new Task();

IonicTask.prototype.run = function(ionic) {
  var self = this;

  self.ionic = ionic;
  self.inputValues = {};
  self.inputFiles = {};
  self.useCmdArgs = false;

  this.getCmdLineOptions();

  var login = new IonicLoginTask();
  login.get(ionic, function(jar) {
    self.jar = jar;

    if (argv._[1] && argv._[1].trim() == 'webhook_url') {
      if (argv._[2]) {
        self.set_webhook_url(self, argv._[2].trim());
      } else {
        console.log('You need to specify a webhook url!'.bold.red);
      }
    } else if (argv['send'] || argv.s) {
      // Dev wants to send a push notification
      self.send_push(self);
    } else if (argv['ios-dev-cert'] || argv['ios-prod-cert'] || argv.d || argv.p) {
      // Dev wants to upload an ios push cert
      self.upload_cert(self);
    } else if (argv['production-mode'] || argv.l) {
      // Dev wants to switch between test/live mode
      // this will look like --live-mode=[y/n]
      // where y will put into live and n will put into dev
      self.set_production_mode(self);
    }
  
  });
};

IonicTask.prototype.set_webhook_url = function(self, webhook_url) {
  var project = IonicProject.load();

  if (!project.get('app_id')) {
    console.log("You need to upload your app first!".bold.red);
    return false;
  }

  var url = self.ionic.IONIC_DASH + self.ionic.IONIC_API + 'app/' + project.get('app_id') + '/push/webhook-url';
  var params = parseUrl(url);

  var form = new FormData();
  form.append('csrfmiddlewaretoken', self.getCsrfToken(self.jar));
  form.append('webhook_url', webhook_url);

  form.submit({
      protocol: params.protocol,
      hostname: params.hostname,
      port: params.port,
      path: params.path,
      headers: form.getHeaders({
        cookie: self.jar.map(function(c) {
          return c.key + "=" + encodeURIComponent(c.value);
        }).join("; ")
      })
    },
    function (err, response) {
      response.on("data", function(data) {
        if (err) {
          return self.ionic.fail('Error setting Webhook URL: ' + err);
        }

        if (response.statusCode == '200') {
          console.log("Webhook URL set to", webhook_url);
        } else {
          return self.ionic.fail('App not found');
        }
      })
    }
  );

  return true;
};

IonicTask.prototype.send_push = function(self) {
  var project = IonicProject.load();

  if (!project.get('app_id')) {
    console.log("You need to upload your app first!".bold.red);
    return false;
  }

  // So, we need the push API key to send notifications.
  var promptProperties = {};

  promptProperties['push-api-key'] = {
    name: 'push-api-key',
    description: 'What is your push API key'.yellow.bold,
    required: true,
    isFile: false
  };

  promptProperties['device-token'] = {
    name: 'device-token',
    description: 'What device token do you want to send to'.yellow.bold,
    required: true,
    isFile: false
  }

  promptProperties['alert'] = {
    name: 'alert',
    description: 'Notification alert message'.yellow.bold,
    required: false,
    isFile: false
  };

  promptProperties['badge'] = {
    name: 'badge',
    description: 'Badge count'.yellow.bold,
    required: false,
    isFile: false
  }

  promptProperties['sound'] = {
    name: 'sound',
    description: 'Sound file name'.yellow.bold,
    required: false,
    isFile: false
  }
  
  prompt.start();

  prompt.get({properties: promptProperties}, function(err, promptResult) {
    if (err) {
      return self.ionic.fail('Error: ' + err);
    }

    var api_key = promptResult['push-api-key'];

    var notification = {
      platform: 'ios',
      tokens: [promptResult['device-token']],
      notification: {
        alert: promptResult['alert'],
        badge: promptResult['badge'],
        sound: promptResult['sound']
      }
    }

    var options = {
      url: 'http://push.ionic.io/api/v1/push',
      method: 'POST',
      json: true,
      headers: {
        'X-Ionic-Application-Id': project.get('app_id'), 
        'X-Ionic-API-Key': api_key<commit_msg>Adding Google API Key upload<commit_after>var fs = require('fs'),
    path = require('path'),
    parseUrl = require('url').parse,
    request = require('request'),
    argv = require('optimist').argv,
    prompt = require('prompt'),
    FormData = require('form-data'),
    IonicProject = require('./project'),
    IonicTask = require('./task').IonicTask,
    IonicStats = require('./stats').IonicStats;
    Task = require('./task').Task,
    IonicLoginTask = require('./login').IonicTask;

var IonicTask = function() {};

IonicTask.prototype = new Task();

IonicTask.prototype.run = function(ionic) {
  var self = this;

  self.ionic = ionic;
  self.inputValues = {};
  self.inputFiles = {};
  self.useCmdArgs = false;

  this.getCmdLineOptions();

  var login = new IonicLoginTask();
  login.get(ionic, function(jar) {
    self.jar = jar;

    if (argv._[1] && argv._[1].trim() == 'webhook_url') {
      if (argv._[2]) {
        self.set_webhook_url(self, argv._[2].trim());
      } else {
        console.log('You need to specify a webhook url!'.bold.red);
      }
    } else if (argv._[1] && argv._[1].trim() == 'google-api-key') {
      if (argv._[2]) {
        self.set_google_api_key(self, argv._[2].trim());
      } else {
        console.log('You need to specify a Google API Key!'.bold.red);
      }
    } else if (argv['send'] || argv.s) {
      // Dev wants to send a push notification
      self.send_push(self);
    } else if (argv['ios-dev-cert'] || argv['ios-prod-cert'] || argv.d || argv.p) {
      // Dev wants to upload an ios push cert
      self.upload_cert(self);
    } else if (argv['production-mode'] || argv.l) {
      // Dev wants to switch between test/live mode
      // this will look like --live-mode=[y/n]
      // where y will put into live and n will put into dev
      self.set_production_mode(self);
    }
  
  });
};

IonicTask.prototype.set_webhook_url = function(self, webhook_url) {
  var project = IonicProject.load();

  if (!project.get('app_id')) {
    console.log("You need to upload your app first!".bold.red);
    return false;
  }

  var url = self.ionic.IONIC_DASH + self.ionic.IONIC_API + 'app/' + project.get('app_id') + '/push/webhook-url';
  var params = parseUrl(url);

  var form = new FormData();
  form.append('csrfmiddlewaretoken', self.getCsrfToken(self.jar));
  form.append('webhook_url', webhook_url);

  form.submit({
      protocol: params.protocol,
      hostname: params.hostname,
      port: params.port,
      path: params.path,
      headers: form.getHeaders({
        cookie: self.jar.map(function(c) {
          return c.key + "=" + encodeURIComponent(c.value);
        }).join("; ")
      })
    },
    function (err, response) {
      response.on("data", function(data) {
        if (err) {
          return self.ionic.fail('Error setting Webhook URL: ' + err);
        }

        if (response.statusCode == '200') {
          console.log("Webhook URL set to", webhook_url);
        } else {
          return self.ionic.fail('App not found');
        }
      })
    }
  );

  return true;
};


IonicTask.prototype.set_google_api_key = function(self, google_api_key) {
  var project = IonicProject.load();

  if (!project.get('app_id')) {
    console.log("You need to upload your app first!".bold.red);
    return false;
  }

  var url = self.ionic.IONIC_DASH + self.ionic.IONIC_API + 'app/' + project.get('app_id') + '/push/google-api-key';
  var params = parseUrl(url);

  var form = new FormData();
  form.append('csrfmiddlewaretoken', self.getCsrfToken(self.jar));
  form.append('android_api_key', google_api_key);

  form.submit({
      protocol: params.protocol,
      hostname: params.hostname,
      port: params.port,
      path: params.path,
      headers: form.getHeaders({
        cookie: self.jar.map(function(c) {
          return c.key + "=" + encodeURIComponent(c.value);
        }).join("; ")
      })
    },
    function (err, response) {
      response.on("data", function(data) {
        if (err) {
          return self.ionic.fail('Error setting Google API Key: ' + err);
        }

        if (response.statusCode == '200') {
          console.log("Google API Key Saved".green);
        } else {
          return self.ionic.fail('App not found');
        }
      })
    }
  );

  return true;
};


IonicTask.prototype.send_push = function(self) {
  var project = IonicProject.load();

  if (!project.get('app_id')) {
    console.log("You need to upload your app first!".bold.red);
    return false;
  }

  // So, we need the push API key to send notifications.
  var promptProperties = {};

  promptProperties['push-api-key'] = {
    name: 'push-api-key',
    description: 'What is your push API key'.yellow.bold,
    required: true,
    isFile: false
  };

  promptProperties['device-token'] = {
    name: 'device-token',
    description: 'What device token do you want to send to'.yellow.bold,
    required: true,
    isFile: false
  }

  promptProperties['alert'] = {
    name: 'alert',
    description: 'Notification alert message'.yellow.bold,
    required: false,
    isFile: false
  };

  promptProperties['badge'] = {
    name: 'badge',
    description: 'Badge count'.yellow.bold,
    required: false,
    isFile: false
  }

  promptProperties['sound'] = {
    name: 'sound',
    description: 'Sound file name'.yellow.bold,
    required: false,
    isFile: false
  }
  
  prompt.start();

  prompt.get({properties: promptProperties}, function(err, promptResult) {
    if (err) {
      return self.ionic.fail('Error: ' + err);
    }

    var api_key = promptResult['push-api-key'];

    var notification = {
      platform: 'ios',
      tokens: [promptResult['device-token']],
      notification: {
        alert: promptResult['alert'],
        ios: {
          badge: promptResult['badge'],
          sound: promptResult['sound']
        }
      }
    }

    var options = {
      url: 'http://push.ionic.io/api/v1/push',
      method: 'POST',
      json: true,
      headers: {
        'X-Ionic-Application-Id': project.get('app_id'), 
        'X-Ionic-API-Key': api_key
{'fraction_non_alphanumeric': 0.15791948833709557, 'fraction_numerical': 0.002163280662151994, 'mean_word_length': 2.645183407610559, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5585481', 'n_tokens_mistral': 3487, 'n_tokens_neox': 3395, 'n_words': 768}