<commit_before>require 'json'

class Chef
  class Knife
    class Raw < Chef::Knife
      banner "knife raw REQUEST_PATH"

      option :method,
        :long => '--method METHOD',
        :short => '-m METHOD',
        :default => "GET",
        :description => "Request method (GET, POST, PUT or DELETE)"

      option :pretty,
        :long => '--[no-]pretty',
        :boolean => true,
        :default => true,
        :description => "Pretty-print JSON output"

      option :input,
        :long => '--input FILE',
        :short => '-i FILE',
        :description => "Name of file to use for PUT or POST"

      def run
        if name_args.length == 0
          show_usage
          ui.fatal("You must provide the path you want to hit on the server")
          exit(1)
        elsif name_args.length > 1
          show_usage
          ui.fatal("Only one path accepted for knife raw")
          exit(1)
        end

        path = name_args[0]
        data = false
        if config[:input]
          data = IO.read(config[:input])
        end
        chef_rest = Chef::REST.new(Chef::Config[:chef_server_url])
        puts api_request(chef_rest, config[:method].to_sym, chef_rest.create_url(name_args[0]), {}, data)
      end

      ACCEPT_ENCODING = "Accept-Encoding".freeze
      ENCODING_GZIP_DEFLATE = "gzip;q=1.0,deflate;q=0.6,identity;q=0.3".freeze

      def redirected_to(response)
        return nil  unless response.kind_of?(Net::HTTPRedirection)
        # Net::HTTPNotModified is undesired subclass of Net::HTTPRedirection so test for this
        return nil  if response.kind_of?(Net::HTTPNotModified)
        response['location']
      end

      def api_request(chef_rest, method, url, headers={}, data=false)
        json_body = data
#        json_body = data ? Chef::JSONCompat.to_json(data) : nil<commit_msg>Fix warning under Ruby 1.9.3+Chef 11<commit_after>require 'json'

class Chef
  class Knife
    class Raw < Chef::Knife
      banner "knife raw REQUEST_PATH"

      option :method,
        :long => '--method METHOD',
        :short => '-m METHOD',
        :default => "GET",
        :description => "Request method (GET, POST, PUT or DELETE)"

      option :pretty,
        :long => '--[no-]pretty',
        :boolean => true,
        :default => true,
        :description => "Pretty-print JSON output"

      option :input,
        :long => '--input FILE',
        :short => '-i FILE',
        :description => "Name of file to use for PUT or POST"

      def run
        if name_args.length == 0
          show_usage
          ui.fatal("You must provide the path you want to hit on the server")
          exit(1)
        elsif name_args.length > 1
          show_usage
          ui.fatal("Only one path accepted for knife raw")
          exit(1)
        end

        path = name_args[0]
        data = false
        if config[:input]
          data = IO.read(config[:input])
        end
        chef_rest = Chef::REST.new(Chef::Config[:chef_server_url])
        puts api_request(chef_rest, config[:method].to_sym, chef_rest.create_url(name_args[0]), {}, data)
      end

      ACCEPT_ENCODING = "Accept-Encoding".freeze unless ACCEPT_ENCODING
      ENCODING_GZIP_DEFLATE = "gzip;q=1.0,deflate;q=0.6,identity;q=0.3".freeze unless ENCODING_GZIP_DEFLATE

      def redirected_to(response)
        return nil  unless response.kind_of?(Net::HTTPRedirection)
        # Net::HTTPNotModified is undesired subclass of Net::HTTPRedirection so test for this
        return nil  if response.kind_of?(Net::HTTPNotModified)
        response['location']
      end

      def api_request(chef_rest, method, url, headers={}, data=false)
        json_body = data
#        json_body = data ? Chef::JSONCompat.to_json(data) : nil
{'fraction_non_alphanumeric': 0.11568260753406359, 'fraction_numerical': 0.007747795885653219, 'mean_word_length': 2.3015873015873014, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '1057351', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1151, 'n_words': 304}