<commit_before>class Rackspace::Email::Api::Endpoint
	class << self
		def request_base=(x)
			@@request_path = x
		end

		def request_base
			@@request_path
		end

		def data_class=(x)
			@@data_class = x
		end

		def data_class
			@@data_class
		end
	end

	def endpoint_path
		self.class.request_base
	end

	def base_url
		url = Rackspace::Email::Api.configuration.base_url.dup
		url.path = url.path + "/" + endpoint_path
		url
	end

	def timestamp
		Time.now.strftime('%Y%m%d%H%M%S')
	end

	# SHA1 Hash:
	# A SHA1 (Secure Hash Algorithm) hash must be applied to a string with the following information:
	# <User Key><User Agent><Timestamp><Secret Key>
	# Note that the 'User Agent' must be the exact same as what is specified in the User-Agent HTTP header. Using the above example data, the string before hashing is:
	# eGbq9/2hcZsRlr1JV1PiRackspace Management Interface20010308143725QHOvchm/40czXhJ1OxfxK7jDHr3t
	# Resulting base-64 SHA1 Hash:
	# 46VIwd66mOFGG8IkbgnLlXnfnkU=
	# Be sure to encode the binary hash, not the hex hash, into base-64. The resulting string should be 28 characters long.
	def hash(ts)
		sig = [
			Rackspace::Email::Api.configuration.user_key,
			Rackspace::Email::Api.configuration.user_agent,
			ts,
			Rackspace::Email::Api.configuration.api_key
		].join("")

		Base64.encode64(Digest::SHA1.digest(sig))
	end

	# X-Api-Signature Header
	# Format is as follows: <User Key>:<Timestamp>:<SHA1 Hash>
	# Example: eGbq9/2hcZsRlr1JV1Pi:20010317143725:46VIwd66mOFGG8IkbgnLlXnfnkU=
	# Remember to include the colons between the data strings!
	def api_signature
		ts = timestamp
		[
			Rackspace::Email::Api.configuration.user_key,
			ts,
			hash(ts)
		].join(":")
	end

	def ensure_api_credentials
		raise Rackspace::Email::Api::Error.new("You must specify a user_key") if Rackspace::Email::Api.configuration.user_key.nil?
		raise Rackspace::Email::Api::Error.new("You must specify an api_key") if Rackspace::Email::Api.configuration.api_key.nil?
	end


	def url_for(verb, opts={})
		target = base_url
		id = opts.delete(:id)
		# substititue customer_id, domain_id, etc

		if ! opts.empty?
			target.query_values = opts
		end
		return target if verb == :index


		raise Rackspace::Email::Api::Error.new("You must specify an object_id") if id.nil?
		target.path << "/#{id}"

		target
	end

	def execute(verb, opts={})
		ensure_api_credentials

		puts opts.inspect

		target_url = base_url
		action = ""
		if verb != :index
			action = opts.delete(:id)
		end

		#store = ActiveSupport::Cache.lookup_store(:mem_cache_store, ['localhost:11211'])
		conn = Faraday.new(target_url) do |c|
			c.response :logger, ::Logger.new(STDOUT) #, bodies: true
			c.use Faraday::Request::UrlEncoded

			if defined?(Rails)
				c.use :http_cache
			end

			c.request :url_encoded
			c.adapter Faraday.default_adapter
		end

		x = conn.send(verb, action, opts) do |req|
			req.headers['User-Agent'] = Rackspace::Email::Api.configuration.user_agent
			req.headers['X-Api-Signature'] = api_signature<commit_msg>add http caching support<commit_after>class Rackspace::Email::Api::Endpoint
	class << self
		def request_base=(x)
			@@request_path = x
		end

		def request_base
			@@request_path
		end

		def data_class=(x)
			@@data_class = x
		end

		def data_class
			@@data_class
		end
	end

	def endpoint_path
		self.class.request_base
	end

	def base_url
		url = Rackspace::Email::Api.configuration.base_url.dup
		url.path = url.path + "/" + endpoint_path
		url
	end

	def timestamp
		Time.now.strftime('%Y%m%d%H%M%S')
	end

	# SHA1 Hash:
	# A SHA1 (Secure Hash Algorithm) hash must be applied to a string with the following information:
	# <User Key><User Agent><Timestamp><Secret Key>
	# Note that the 'User Agent' must be the exact same as what is specified in the User-Agent HTTP header. Using the above example data, the string before hashing is:
	# eGbq9/2hcZsRlr1JV1PiRackspace Management Interface20010308143725QHOvchm/40czXhJ1OxfxK7jDHr3t
	# Resulting base-64 SHA1 Hash:
	# 46VIwd66mOFGG8IkbgnLlXnfnkU=
	# Be sure to encode the binary hash, not the hex hash, into base-64. The resulting string should be 28 characters long.
	def hash(ts)
		sig = [
			Rackspace::Email::Api.configuration.user_key,
			Rackspace::Email::Api.configuration.user_agent,
			ts,
			Rackspace::Email::Api.configuration.api_key
		].join("")

		Base64.encode64(Digest::SHA1.digest(sig))
	end

	# X-Api-Signature Header
	# Format is as follows: <User Key>:<Timestamp>:<SHA1 Hash>
	# Example: eGbq9/2hcZsRlr1JV1Pi:20010317143725:46VIwd66mOFGG8IkbgnLlXnfnkU=
	# Remember to include the colons between the data strings!
	def api_signature
		ts = timestamp
		[
			Rackspace::Email::Api.configuration.user_key,
			ts,
			hash(ts)
		].join(":")
	end

	def ensure_api_credentials
		raise Rackspace::Email::Api::Error.new("You must specify a user_key") if Rackspace::Email::Api.configuration.user_key.nil?
		raise Rackspace::Email::Api::Error.new("You must specify an api_key") if Rackspace::Email::Api.configuration.api_key.nil?
	end


	def url_for(verb, opts={})
		target = base_url
		id = opts.delete(:id)
		# substititue customer_id, domain_id, etc

		if ! opts.empty?
			target.query_values = opts
		end
		return target if verb == :index


		raise Rackspace::Email::Api::Error.new("You must specify an object_id") if id.nil?
		target.path << "/#{id}"

		target
	end

	def execute(verb, opts={})
		ensure_api_credentials

		puts opts.inspect

		target_url = base_url
		action = ""
		if verb != :index
			action = opts.delete(:id)
		end

		#store = ActiveSupport::Cache.lookup_store(:mem_cache_store, ['localhost:11211'])
		conn = Faraday.new(target_url) do |c|
			c.response :logger, ::Logger.new(STDOUT) #, bodies: true
			c.use Faraday::Request::UrlEncoded

			if defined?(Rails)
				c.use :http_cache, store: Rails.cache, logger: Rails.logger
			end

			c.request :url_encoded
			c.adapter Faraday.default_adapter
		end

		x = conn.send(verb, action, opts) do |req|
			req.headers['User-Agent'] = Rackspace::Email::Api.configuration.user_agent
			req.headers['X-Api-Signature'] = api_signature
{'fraction_non_alphanumeric': 0.11559361106537132, 'fraction_numerical': 0.023382183434875678, 'mean_word_length': 4.309440559440559, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 17, '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': '3728414', 'n_tokens_mistral': 2461, 'n_tokens_neox': 2161, 'n_words': 526}