<commit_before><commit_msg>Add api_caller.rb, the base of our API talking framework<commit_after>require 'net/https'
require 'json'

class APICaller
	require_relative 'auth.rb'

	API_VERSION = "2"
	API_SERVER = "app.smartfile.com"
	API_BASE_URL = "/api/#{API_VERSION}"

	def doAPICall(method, path, parameters=nil) 
		http = Net::HTTP.new(API_SERVER, 443)
		http.use_ssl = true
		http.verify_mode = OpenSSL::SSL::VERIFY_NONE
		req = getHTTPRequestForVerb(method, API_BASE_URL + path)

		# For use until we get OAUTH working. Great for testing!
		# Be sure to keep auth.rb private.
		req.basic_auth UNAME, PASSWD

		if !parameters.nil?
			post_body = []
			post_body << params
			req.body = post_body.join
		end

		resp, data = http.request(req)
		if resp.code == "200"
			return resp.body
		else
			return 'Error ' + resp.code
		end
	end

	def getHTTPRequestForVerb(verb, path)
		req = Net::HTTP::Get.new(path) if verb.upcase == "GET"
		req = Net::HTTP::Post.new(path) if verb.upcase == "POST"
		req = Net::HTTP::Put.new(path) if verb.upcase == "PUT"
		req = Net::HTTP::Delete.new(path) if verb.upcase == "DELETE"
		raise NetworkException.new("Invalid HTTP Verb - \'#{verb}\'") if req.nil?
		return req
	end

end

api = APICaller.new
print api.doAPICall('GET', '/path/info/') + "\n"
{'fraction_non_alphanumeric': 0.13884555382215288, 'fraction_numerical': 0.00546021840873635, 'mean_word_length': 3.9728682170542635, 'pattern_counts': {'":': 0, '<': 5, '<?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': '82649', 'n_tokens_mistral': 511, 'n_tokens_neox': 471, 'n_words': 118}