<commit_before>require 'cleverbot/parser'

module Cleverbot
  # Ruby wrapper for Cleverbot.com.
  class Client
    include HTTParty

    # The default form variables for POSTing to Cleverbot.com
    DEFAULT_PARAMS = {
      'stimulus' => '',
      'start' => 'y',
      'sessionid' => '',
      'vText8' => '',
      'vText7' => '',
      'vText6' => '',
      'vText5' => '',
      'vText4' => '',
      'vText3' => '',
      'vText2' => '',
      'icognoid' => 'wsf',
      'icognocheck' => '',
      'fno' => '0',
      'prevref' => '',
      'emotionaloutput' => '',
      'emotionalhistory' => '',
      'asbotname' => '',
      'ttsvoice' => '',
      'typing' => '',
      'lineref' => '',
      'sub' => 'Say',
      'islearning' => '1',
      'cleanslate' => 'false',
    }

    # The path to the form endpoint on Cleverbot.com.
    PATH = '/webservicemin'

    base_uri 'http://www.cleverbot.com'

    parser Parser

    # Holds the parameters for an instantiated Cleverbot::Base.
    attr_reader :params

    # Creates a digest from the form parameters.
    #
    # ==== Parameters
    #
    # [<tt>body</tt>] <tt>String</tt> to be digested.
    def self.digest body
      Digest::MD5.hexdigest body[9...29]
    end

    # Sends a message to Cleverbot.com and returns a <tt>Hash</tt> containing the parameters received.
    #
    # ==== Parameters
    #
    # [<tt>message</tt>] Optional <tt>String</tt> holding the message to be sent. Defaults to <tt>''</tt>.
    # [<tt>params</tt>] Optional <tt>Hash</tt> with form parameters. Merged with DEFAULT_PARAMS. Defaults to <tt>{}</tt>.
    def self.write message='', params={}
      body = DEFAULT_PARAMS.merge params
      body['stimulus'] = message
      body['icognocheck'] = digest HashConversions.to_params(body)

      post(PATH, :body => body).parsed_response
    end

    # Initializes a Cleverbot::Base with given parameters.
    #<commit_msg>Rename references to Cleverbot::Base to Client in documentation for Cleverbot::Client.<commit_after>require 'cleverbot/parser'

module Cleverbot
  # Ruby wrapper for Cleverbot.com.
  class Client
    include HTTParty

    # The default form variables for POSTing to Cleverbot.com
    DEFAULT_PARAMS = {
      'stimulus' => '',
      'start' => 'y',
      'sessionid' => '',
      'vText8' => '',
      'vText7' => '',
      'vText6' => '',
      'vText5' => '',
      'vText4' => '',
      'vText3' => '',
      'vText2' => '',
      'icognoid' => 'wsf',
      'icognocheck' => '',
      'fno' => '0',
      'prevref' => '',
      'emotionaloutput' => '',
      'emotionalhistory' => '',
      'asbotname' => '',
      'ttsvoice' => '',
      'typing' => '',
      'lineref' => '',
      'sub' => 'Say',
      'islearning' => '1',
      'cleanslate' => 'false',
    }

    # The path to the form endpoint on Cleverbot.com.
    PATH = '/webservicemin'

    base_uri 'http://www.cleverbot.com'

    parser Parser

    # Holds the parameters for an instantiated Client.
    attr_reader :params

    # Creates a digest from the form parameters.
    #
    # ==== Parameters
    #
    # [<tt>body</tt>] <tt>String</tt> to be digested.
    def self.digest body
      Digest::MD5.hexdigest body[9...29]
    end

    # Sends a message to Cleverbot.com and returns a <tt>Hash</tt> containing the parameters received.
    #
    # ==== Parameters
    #
    # [<tt>message</tt>] Optional <tt>String</tt> holding the message to be sent. Defaults to <tt>''</tt>.
    # [<tt>params</tt>] Optional <tt>Hash</tt> with form parameters. Merged with DEFAULT_PARAMS. Defaults to <tt>{}</tt>.
    def self.write message='', params={}
      body = DEFAULT_PARAMS.merge params
      body['stimulus'] = message
      body['icognocheck'] = digest HashConversions.to_params(body)

      post(PATH, :body => body).parsed_response
    end

    # Initializes a Client with given parameters.
    #
{'fraction_non_alphanumeric': 0.16593548387096774, 'fraction_numerical': 0.006709677419354839, 'mean_word_length': 2.5013550135501355, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 87, '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': '3064701', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1264, 'n_words': 313}