<commit_before>/*
 * Licensed to Cloudkick, Inc ('Cloudkick') under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * Cloudkick licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var sys = require('sys');
var fs = require('fs');
var path = require('path');

var sprintf = require('extern/sprintf').sprintf;
var async = require('extern/async');

var http = require('util/http');
var misc = require('util/misc');

var enable_commands = require('cast-client/commands/instances/enable');

var config = {
  'short_description': 'Create a new application instance',
  'long_description': 'Create a new application instance.',
  'required_arguments' : [
    ['name', 'Instance name'],
    ['bundle', 'Bundle name'],
    ['version', 'Bundle version number']
  ],
  'optional_arguments': [],
  'uses_global_options': ['remote']
};

function handle_command(args) {
  var instance_name = args.name;
  var bundle_name_full = misc.get_full_bundle_name(args.bundle, args.version);
  var remote_path = sprintf('/instances/%s/%s/', bundle_name_full, instance_name);

  http.get_response(args.remote, remote_path, 'POST', true, function(error, response) {
    if (error) {
      return sys.puts(sprintf('Error: %s', error.message));
    }

    if (response.status_code !== 200) {
      return sys.puts(sprintf('HTTP Error, status code: %d, returned body: %s', response.status_code,
                                                                                response.body.message));
    }

    sys.puts('Instance Created');
  });
}

exports.config = config;
exports.handle_command = handle_command;<commit_msg>Update 'instances create' to use new API<commit_after>/*
 * Licensed to Cloudkick, Inc ('Cloudkick') under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * Cloudkick licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var sys = require('sys');
var fs = require('fs');
var path = require('path');
var querystring = require('querystring');

var sprintf = require('extern/sprintf').sprintf;
var async = require('extern/async');

var http = require('util/http');
var misc = require('util/misc');

var enable_commands = require('cast-client/commands/instances/enable');

var config = {
  'short_description': 'Create a new application instance',
  'long_description': 'Create a new application instance.',
  'required_arguments' : [
    ['name', 'Instance name'],
    ['bundle', 'Bundle name'],
    ['version', 'Bundle version number']
  ],
  'optional_arguments': [],
  'uses_global_options': ['remote']
};

function handle_command(args) {
  var remote_path = sprintf('/instances/%s/', args.name);

  http.client(args.remote, function(err, client) {
    client.on('error', function() {
      sys.puts('A connection error occurred');
      process.exit();
    });

    var body = querystring.stringify({
      bundle_name: args.bundle,
      bundle_version: args.version
    });

    var headers = client.headers;
    headers['content-length'] = body.length;

    var request = client.request('PUT', remote_path, headers);
    request.end(body);
    request.on('response', function(response) {
      var data = [];
      response.on('data', function(chunk) {
        data.push(chunk);
      });

      response.on('end', function() {
        try {
          var response_obj = JSON.parse(data.join(''));
          if (response.statusCode !== 200) {
            sys.puts('Error: ' + response_obj.message);
          }
          else {
            sys.puts('Instance \'' + args.name + '\' created');
          }
        }
        catch (e) {
          sys.puts('Error: invalid response');
        }
      });
    });
  });
}

exports.config = config;
exports.handle_command = handle_command;
{'fraction_non_alphanumeric': 0.12775419446128966, 'fraction_numerical': 0.0028299979785728724, 'mean_word_length': 3.421805183199285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1779220', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1338, 'n_words': 443}