 		(new Image()).src = url
 
 
+# ## KissmetricsClient
+# --------------------
+
+# Wrapper for interacting with the Kissmetrics API.
+#
+# Instantiates a new client with your Kissmetrics API key and an identifier
+# for the person you're recording data about. A new client must be created
+# for each person you record data about.
+#
+# `key` (String): Your API key from Kissmetrics
+#
+#	`person` (String): An identifier for the person you'll record data about
+#
+# ```
+# km = new KissmetricsClient(API_KEY, 'evan@example.com')
+# ```
 class KissmetricsClient
 	constructor: (@key, @person) ->
 		@host        = 'trk.kissmetrics.com'

			set    : 's'
			alias  : 'a'

	record: (action, properties = {}) ->
		properties._n = action
		@generateQuery 'record', properties

	set: (properties) ->
		# Each property has to be sent in its own query
		for name, value of properties
			data       = {}
			data[name] = value
			@generateQuery 'set', data

	alias: (to) ->
		@generateQuery 'alias', _n: to

	generateQuery: (type, data) ->
		data._k = @key
		data._p = @person


		@request "#{@query_types[type]}?#{queryString}"

	# ### record
	# ----------

	# Query the Kissmetrics API
	#
	# `endpoint` (String): URL path (without a leading slash) that will be used
	#   as a Kissmetrics API endpoint.
	request: (endpoint) ->
		httpRequest "https://#{@host}:#{@port}/#{endpoint}"


# ### Exports
# -----------

# Make `KissmetricsClient` available either as a Node module or a property
# on the current context in the browser.
if ENV is 'node'
	exports.KissmetricsClient = KissmetricsClient
else
