<commit_before>require 'set'

module AwsSdkCodeGenerator
  module Generators
    class ClientClass < Dsl::Class

      include Helper

      # @api private
      DEFAULT_PLUGINS = [
        'Seahorse::Client::Plugins::ContentLength',
        'Aws::Plugins::Logging',
        'Aws::Plugins::ParamConverter',
        'Aws::Plugins::ParamValidator',
        'Aws::Plugins::UserAgent',
        'Aws::Plugins::RetryErrors',
        'Aws::Plugins::GlobalConfiguration',
        'Aws::Plugins::RegionalEndpoint',
        'Aws::Plugins::RequestSigner',
        'Aws::Plugins::ResponsePaging',
        'Aws::Plugins::StubResponses',
      ]

      # @api private
      PROTOCOL_PLUGINS = Hash.new(DEFAULT_PLUGINS).merge({
        'json'      => DEFAULT_PLUGINS + %w(Aws::Plugins::Protocols::JsonRpc),
        'rest-json' => DEFAULT_PLUGINS + %w(Aws::Plugins::Protocols::RestJson),
        'rest-xml'  => DEFAULT_PLUGINS + %w(Aws::Plugins::Protocols::RestXml),
        'query'     => DEFAULT_PLUGINS + %w(Aws::Plugins::Protocols::Query),
        'ec2'       => DEFAULT_PLUGINS + %w(Aws::Plugins::Protocols::EC2),
        nil         => DEFAULT_PLUGINS,
      })

      def initialize(identifier:, api:, waiters:, examples:)
        @identifier = identifier
        @api = api
        @waiters = waiters
        @examples = examples
        super('Client', extends: 'Seahorse::Client::Base')
        apply_modules(self)
        apply_identifier(self)
        apply_api(self)
        apply_plugins(self)
        apply_operations(self)
        apply_waiter_methods(self)
        eigenclass do |eigenclass|
          eigenclass.docstring('@api private')
          eigenclass.attr_reader('identifier')
          eigenclass.method('errors_module') do |m|
            m.code('Errors')
          end
        end
      end

      private

      def apply_modules(klass)
        klass.include('Aws::ClientStubs')
        klass.include('Aws::ClientWaiters')
      end

      def apply_identifier(klass)
        klass.code do |c|
          c << "@identifier = :#{@identifier}"
        end
      end

      def apply_api(klass)
        klass.code("set_api(ClientApi::API)")
      end

      def apply_plugins(klass)
        protocol = (@api['metadata'] || {})['protocol']
        plugins = PROTOCOL_PLUGINS[protocol]
        klass.code do |c|
          plugins.each do |plugin|
            c << "add_plugin(#{plugin})"
          end
        end
      end

      def apply_operations(klass)
        (@api['operations'] || {}).each do |operation_name, operation|
          method_name = underscore(operation_name)
          klass.method(method_name) do |m|
            ClientOperationDocumentation.apply(
              api: @api,
              service_identifier: @identifier,
              operation_name: operation_name,
              operation: operation,
              examples: @examples,
              method: m
            )
            m.param('params', type: Hash, default: {})
            m.param('options', type: Hash, default: {})
            m.code do |c|
              c << "req = build_request(:#{method_name}, params)"
              c << "req.send_request(options)"
            end
          end
        end
      end

      def apply_waiter_methods(klass)

        waiters = {}
        waiter_names = []
        ((@waiters || {})['waiters'] || {}).keys.each do |name|
          class_name = "Waiters::#{name}"
          name = underscore(name).to_sym
          waiter_names << name
          waiters[name] = class_name
        end
        waiters = HashFormatter.new.format(waiters)<commit_msg>Grouping API operaitons.<commit_after>require 'set'

module AwsSdkCodeGenerator
  module Generators
    class ClientClass < Dsl::Class

      include Helper

      # @api private
      DEFAULT_PLUGINS = [
        'Seahorse::Client::Plugins::ContentLength',
        'Aws::Plugins::Logging',
        'Aws::Plugins::ParamConverter',
        'Aws::Plugins::ParamValidator',
        'Aws::Plugins::UserAgent',
        'Aws::Plugins::RetryErrors',
        'Aws::Plugins::GlobalConfiguration',
        'Aws::Plugins::RegionalEndpoint',
        'Aws::Plugins::RequestSigner',
        'Aws::Plugins::ResponsePaging',
        'Aws::Plugins::StubResponses',
      ]

      # @api private
      PROTOCOL_PLUGINS = Hash.new(DEFAULT_PLUGINS).merge({
        'json'      => DEFAULT_PLUGINS + %w(Aws::Plugins::Protocols::JsonRpc),
        'rest-json' => DEFAULT_PLUGINS + %w(Aws::Plugins::Protocols::RestJson),
        'rest-xml'  => DEFAULT_PLUGINS + %w(Aws::Plugins::Protocols::RestXml),
        'query'     => DEFAULT_PLUGINS + %w(Aws::Plugins::Protocols::Query),
        'ec2'       => DEFAULT_PLUGINS + %w(Aws::Plugins::Protocols::EC2),
        nil         => DEFAULT_PLUGINS,
      })

      def initialize(identifier:, api:, waiters:, examples:)
        @identifier = identifier
        @api = api
        @waiters = waiters
        @examples = examples
        super('Client', extends: 'Seahorse::Client::Base')
        apply_modules(self)
        apply_identifier(self)
        apply_api(self)
        apply_plugins(self)
        apply_operations(self)
        apply_waiter_methods(self)
        eigenclass do |eigenclass|
          eigenclass.docstring('@api private')
          eigenclass.attr_reader('identifier')
          eigenclass.method('errors_module') do |m|
            m.code('Errors')
          end
        end
      end

      private

      def apply_modules(klass)
        klass.include('Aws::ClientStubs')
        klass.include('Aws::ClientWaiters')
      end

      def apply_identifier(klass)
        klass.code do |c|
          c << "@identifier = :#{@identifier}"
        end
      end

      def apply_api(klass)
        klass.code("set_api(ClientApi::API)")
      end

      def apply_plugins(klass)
        protocol = (@api['metadata'] || {})['protocol']
        plugins = PROTOCOL_PLUGINS[protocol]
        klass.code do |c|
          plugins.each do |plugin|
            c << "add_plugin(#{plugin})"
          end
        end
      end

      def apply_operations(klass)
        code('# @!group API Operations')
        (@api['operations'] || {}).each do |operation_name, operation|
          method_name = underscore(operation_name)
          klass.method(method_name) do |m|
            ClientOperationDocumentation.apply(
              api: @api,
              service_identifier: @identifier,
              operation_name: operation_name,
              operation: operation,
              examples: @examples,
              method: m
            )
            m.param('params', type: Hash, default: {})
            m.param('options', type: Hash, default: {})
            m.code do |c|
              c << "req = build_request(:#{method_name}, params)"
              c << "req.send_request(options)"
            end
          end
        end
        code('# @!endgroup')
      end

      def apply_waiter_methods(klass)

        waiters = {}
        waiter_names = []
        ((@waiters || {})['waiters'] || {}).keys.each do |name|
          class_name = "Waiters::#{name}"
          name = underscore(name).to_sym
          waiter_names << name
          waiters[name] = class_name
        end
        waiters = HashFormatter.new.format(waiters)
{'fraction_non_alphanumeric': 0.1302909141045085, 'fraction_numerical': 0.0005514959327174962, 'mean_word_length': 2.137543252595156, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2407227', 'n_tokens_mistral': 2147, 'n_tokens_neox': 2167, 'n_words': 377}