<commit_before># Copyright 2016 Liqwyd Ltd.
#
# Licensed 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.

require 'securerandom'
require 'oj'
require 'yaml'
require 'logger'

require 'cyclid/config'
require 'cyclid/auth_methods'

require 'cyclid/client/api'
require 'cyclid/client/user'
require 'cyclid/client/organization'
require 'cyclid/client/job'
require 'cyclid/client/stage'

module Cyclid
  # Cyclid client methods
  module Client
    # Tilapia is the standard Cyclid Ruby client. It provides an inteligent
    # programmable API on top of the standard Cyclid REST API, complete with
    # automatic signing of HTTP requests and HTTP error handling.
    #
    # The client provides interfaces for managing Users, Organizations, Stages
    # & Jobs. Refer to the documentation for those modules for more information.
    #
    # In case you're wondering, this class required a name: it couldn't be
    # 'Cyclid' and it couldn't be 'Client'. Tilapia are a common type of
    # Cichlid...
    class Tilapia
      attr_reader :config, :logger
      # @!attribute [r] config
      #   @return [Config] Client configuration object
      # @!attribute [r] logger
      #   @return [Logger] Client logger object

      # @param config_path [String] Fully qualified path to the configuration file
      # @param log_level [FixNum] Logger output level
      def initialize(options)
        @config = Config.new(options)

        # Create a logger
        log_level = options[:log_level] || Logger::FATAL
        @logger = Logger.new(STDERR)
        @logger.level = log_level

        # Select the API methods to use
        @api = case @config.auth
               when AuthMethods::AUTH_HMAC
                 Api::Hmac.new(@config, @logger)
               when AuthMethods::AUTH_BASIC
                 Api::Basic.new(@config, @logger)
               when AuthMethods::AUTH_TOKEN
                 Api::Token.new(@config, @logger)
               end
      end

      include User
      include Organization
      include Job
      include Stage

      private

      # Build a URI for the configured server & required resource
      def server_uri(path)
        URI::HTTP.build(host: @config.server,
                        port: @config.port,
                        path: path)
      end

      def method_missing(method, *args, &block)
        @api.send(method, *args, &block)
      end
    end
  end
end<commit_msg>Put the AuthMethods at the top level<commit_after># Copyright 2016 Liqwyd Ltd.
#
# Licensed 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.

require 'securerandom'
require 'oj'
require 'yaml'
require 'logger'

require 'cyclid/config'
require 'cyclid/auth_methods'

require 'cyclid/client/api'
require 'cyclid/client/user'
require 'cyclid/client/organization'
require 'cyclid/client/job'
require 'cyclid/client/stage'

module Cyclid
  # Cyclid client methods
  module Client
    # Tilapia is the standard Cyclid Ruby client. It provides an inteligent
    # programmable API on top of the standard Cyclid REST API, complete with
    # automatic signing of HTTP requests and HTTP error handling.
    #
    # The client provides interfaces for managing Users, Organizations, Stages
    # & Jobs. Refer to the documentation for those modules for more information.
    #
    # In case you're wondering, this class required a name: it couldn't be
    # 'Cyclid' and it couldn't be 'Client'. Tilapia are a common type of
    # Cichlid...
    class Tilapia
      attr_reader :config, :logger
      # @!attribute [r] config
      #   @return [Config] Client configuration object
      # @!attribute [r] logger
      #   @return [Logger] Client logger object

      # @param config_path [String] Fully qualified path to the configuration file
      # @param log_level [FixNum] Logger output level
      def initialize(options)
        @config = Config.new(options)

        # Create a logger
        log_level = options[:log_level] || Logger::FATAL
        @logger = Logger.new(STDERR)
        @logger.level = log_level

        # Select the API methods to use
        @api = case @config.auth
               when AuthMethods::AUTH_HMAC
                 Api::Hmac.new(@config, @logger)
               when AuthMethods::AUTH_BASIC
                 Api::Basic.new(@config, @logger)
               when AuthMethods::AUTH_TOKEN
                 Api::Token.new(@config, @logger)
               end
      end

      include User
      include Organization
      include Job
      include Stage

      private

      # Build a URI for the configured server & required resource
      def server_uri(path)
        URI::HTTP.build(host: @config.server,
                        port: @config.port,
                        path: path)
      end

      def method_missing(method, *args, &block)
        @api.send(method, *args, &block)
      end
    end

    include AuthMethods
  end
end
{'fraction_non_alphanumeric': 0.0776068376068376, 'fraction_numerical': 0.002735042735042735, 'mean_word_length': 2.61619283065513, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7350551', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1546, 'n_words': 609}