<commit_before>class Configuration
  include Enumerable

  ## def initialize(args)
  ## args - array of hashes:
  #  args = [
  #      {
  #          :host => '127.0.0.1',
  #          :port => 9091,
  #          :down => true
  #      },
  #      {
  #          :host => '127.0.0.1',
  #          :port => 9092,
  #          :up => true
  #      },
  #      {
  #          :host => '192.168.100.199',
  #          :port => 9091,
  #          :username => 'username',
  #          :password => 'password',
  #          :down => true,
  #          :up => true
  #      }
  #  ]
  def initialize(args = [])
    @clients = []
    @downs = []
    @ups = []
    args.each do |arg|
      client = Client.new(arg)
      @clients << client
      @downs << client if arg.key?(:down) && arg[:down]
      @ups << client if arg.key?(:up) && arg[:up]
    end
  end

  def each
    @clients.each{|i| yield i}
  end

  def each_ups
    @ups.each{|i| yield i}
  end

  def each_downs
    @downs.each{|i| yield i}
  end

  class Client
    FIELDS = ['downloadDir', 'error', 'errorString', 'eta', 'hashString', 'id', 'name', 'peersConnected', 'peersKnown', 'peersSendingToUs', 'percentDone', 'rateDownload', 'rateUpload', 'recheckProgress', 'startDate', 'status', 'totalSize', 'torrentFile']
    attr_reader :interval
    def initialize(args)
      @host = args.delete(:host) || '127.0.0.1'
      @port = args.delete(:port) || 9091
      @username = args[:username]
      @password = args[:password]
      @interval = args.delete(:interval) || 5
      @transmission = Transmission::Client.new(@host, @port, @username, @password)
    end

    def report
      @transmission.torrents(FIELDS) do |torrents|
        result = {:host => "#{@host}:#{@port}"}
        torrents.each do |torrent|
          puts 'torrent'
          result[torrent.hashString.to_sym] = torrent.attributes
        end
        EM::HttpRequest.new('http://127.0.0.1:3000/transmission/').post :query => {:torrents => result.to_json}
      end
    end

    def session_stats
      @transmission.session_stat do |ss|
        puts 'session'
        result = ss.attributes.merge({:host => "#{@host}:#{@port}"})
        EM::HttpRequest.new('http://127.0.0.1:3000/transmission/stat').post :query => {:session_stat => result.to_json}
      end
    end

  end

end<commit_msg>Post data in a body, not in query string<commit_after>class Configuration
  include Enumerable

  ## def initialize(args)
  ## args - array of hashes:
  #  args = [
  #      {
  #          :host => '127.0.0.1',
  #          :port => 9091,
  #          :down => true
  #      },
  #      {
  #          :host => '127.0.0.1',
  #          :port => 9092,
  #          :up => true
  #      },
  #      {
  #          :host => '192.168.100.199',
  #          :port => 9091,
  #          :username => 'username',
  #          :password => 'password',
  #          :down => true,
  #          :up => true
  #      }
  #  ]
  def initialize(args = [])
    @clients = []
    @downs = []
    @ups = []
    args.each do |arg|
      client = Client.new(arg)
      @clients << client
      @downs << client if arg.key?(:down) && arg[:down]
      @ups << client if arg.key?(:up) && arg[:up]
    end
  end

  def each
    @clients.each{|i| yield i}
  end

  def each_ups
    @ups.each{|i| yield i}
  end

  def each_downs
    @downs.each{|i| yield i}
  end

  class Client
#    HOST = 'http://127.0.0.1:3000'
    HOST = 'http://peerlize.hitlan.ru'
    FIELDS = ['downloadDir', 'error', 'errorString', 'eta', 'hashString', 'id', 'name', 'peersConnected', 'peersKnown', 'peersSendingToUs', 'percentDone', 'rateDownload', 'rateUpload', 'recheckProgress', 'startDate', 'status', 'totalSize', 'torrentFile']
    attr_reader :interval
    def initialize(args)
      @host = args.delete(:host) || '127.0.0.1'
      @port = args.delete(:port) || 9091
      @username = args[:username]
      @password = args[:password]
      @interval = args.delete(:interval) || 5
      @transmission = Transmission::Client.new(@host, @port, @username, @password)
    end

    def report
      @transmission.torrents(FIELDS) do |torrents|
        result = {:host => "#{@host}:#{@port}"}
        torrents.each do |torrent|
          puts 'torrent'
          result[torrent.hashString.to_sym] = torrent.attributes
        end
        EM::HttpRequest.new("#{HOST}/transmission/").post :body => {:torrents => result.to_json}
      end
    end

    def session_stats
      @transmission.session_stat do |ss|
        puts 'session'
        result = ss.attributes.merge({:host => "#{@host}:#{@port}"})
        EM::HttpRequest.new("#{HOST}/transmission/stat").post :body => {:session_stat => result.to_json}
      end
    end

  end

end
{'fraction_non_alphanumeric': 0.17332200509770604, 'fraction_numerical': 0.026338147833474938, 'mean_word_length': 2.186062246278755, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 11, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6601275', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1613, 'n_words': 333}