<commit_before>require "aria2/version"

module Aria2

	class Downloader

		def self.new(host = 'localhost', port = 6800)
			@host = host
			@port = port
		end

	end

end
<commit_msg>Implements basic RPC call procedures and 'check' function.<commit_after>require "aria2/version"

module Aria2

	class Downloader

		require 'open-uri'
		require 'json'
		require 'base64'
		require 'cgi'

		def self.new(host = 'localhost', port = 6800)
			@host = host
			@port = port
			self
		end

		def self.check
			begin
				self.rpc_call('getGlobalStat', {})
				true
			rescue
				false
			end
		end

		private

			def self.rpc_path
				"http://#{@host}:#{@port}/jsonrpc"
			end

			def self.rpc_call(method, params)
				method = "aria2.#{method}"
				id = 'ruby-aria2'
				params_encoded = 
					(params && !params.empty?) ? 
					CGI.escape(Base64.encode64(JSON.generate(params))) :
					''

				url = "#{self.rpc_path}?method=#{method}&id=#{id}&params=#{params_encoded}"
				answer = JSON.parse(open(url).read)

				answer['result']
			end

	end

end

{'fraction_non_alphanumeric': 0.1362763915547025, 'fraction_numerical': 0.019193857965451054, 'mean_word_length': 3.0115384615384615, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5233117', 'n_tokens_mistral': 470, 'n_tokens_neox': 371, 'n_words': 83}