<commit_before>require File.join(File.dirname(__FILE__), 'client')

module Blather
  module DSL
    def client
      @client ||= Client.new
    end
    module_function :client

    ##
    # Prepare server settings
    #   setup [node@domain/resource], [password], [host], [port]
    # host and port are optional defaulting to the domain in the JID and 5222 respectively
    def setup(jid, password, host = nil, port = nil)
      client.setup(jid, password, host, port)
    end

    ##
    # Shutdown the connection.
    # Flushes the write buffer then stops EventMachine
    def shutdown
      client.stop
    end

    ##
    # Set handler for a stanza type
    def handle(stanza_type, *guards, &block)
      client.register_handler stanza_type, *guards, &block
    end

    ##
    # Wrapper for "handle :ready" (just a bit of syntactic sugar)
    def when_ready(&block)
      handle :ready, &block
    end

    ##
    # Set current status
    def status(state = nil, msg = nil)
      client.status = state, msg
    end

    ##
    # Direct access to the roster
    def roster
      client.roster
    end

    ##
    # Write data to the stream
    # Anything that resonds to #to_s can be paseed to the stream
    def write(stanza)
      client.write(stanza)
    end

    ##
    # Helper method to make sending basic messages easier
    #   say [jid], [msg]
    def say(to, msg)
      client.write Blather::Stanza::Message.new(to, msg)
    end

    ##
    # Wrapper to grab the current JID
    def jid
      client.jid
    end

    ##
    #
    def discover(what, who, where, &callback)
      stanza = Blather::Stanza.class_from_registration(:query, "http://jabber.org/protocol/disco##{what}").new
      stanza.to = who
      stanza.node = where

      client.temporary_handler stanza.id, &callback
      write stanza
    end

    ##
    # PubSub proxy
    def pubsub
      client.pubsub
    end

    ##
    # Checks to see if the method is part of the handlers list.
    # If so it creates a handler, otherwise it'll pass it back
    # to Ruby's method_missing handler<commit_msg>small documentation stuffs and remove pubsub from the DSL (it is not ready yet)<commit_after>require File.join(File.dirname(__FILE__), 'client')

module Blather
  module DSL
    def client
      @client ||= Client.new
    end
    module_function :client

    ##
    # Prepare server settings
    #   setup [node@domain/resource], [password], [host], [port]
    # host and port are optional defaulting to the domain in the JID and 5222 respectively
    def setup(jid, password, host = nil, port = nil)
      client.setup(jid, password, host, port)
    end

    ##
    # Shutdown the connection.
    # Flushes the write buffer then stops EventMachine
    def shutdown
      client.stop
    end

    ##
    # Set handler for a stanza type
    def handle(stanza_type, *guards, &block)
      client.register_handler stanza_type, *guards, &block
    end

    ##
    # Wrapper for "handle :ready" (just a bit of syntactic sugar)
    def when_ready(&block)
      handle :ready, &block
    end

    ##
    # Set current status
    def status(state = nil, msg = nil)
      client.status = state, msg
    end

    ##
    # Direct access to the roster
    def roster
      client.roster
    end

    ##
    # Write data to the stream
    # Anything that resonds to #to_s can be paseed to the stream
    def write(stanza)
      client.write stanza
    end

    ##
    # Helper method to make sending basic messages easier
    #   say [jid], [msg]
    def say(to, msg)
      client.write Blather::Stanza::Message.new(to, msg)
    end

    ##
    # Wrapper to grab the current JID
    def jid
      client.jid
    end

    ##
    # Request items or info from an entity
    #   discover (items|info), [jid], [node] do |response|
    #   end
    def discover(what, who, where, &callback)
      stanza = Blather::Stanza.class_from_registration(:query, "http://jabber.org/protocol/disco##{what}").new
      stanza.to = who
      stanza.node = where

      client.temporary_handler stanza.id, &callback
      write stanza
    end

    ##
    # Checks to see if the method is part of the handlers list.
    # If so it creates a handler, otherwise it'll pass it back
    # to Ruby's method_missing handler
{'fraction_non_alphanumeric': 0.08843537414965986, 'fraction_numerical': 0.0018766127140511376, 'mean_word_length': 2.4084732214228617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2100606', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1285, 'n_words': 449}