Class: Keepify::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/keepify.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_id, async = false) ⇒ Tracker

Returns a new instance of Tracker.



11
12
13
14
15
16
17
18
19
20
# File 'lib/keepify.rb', line 11

def initialize(client_id, async = false)
	raise "client_id must be supplied" if(client_id.nil? || client_id.empty?)
	if async
		require 'thread'
		@async = true
	end
	@options = {}
	@options[:kpusr] = client_id
	@logger = Logger.new(STDOUT)
end

Instance Method Details

#trackEvent(event_type, user_id, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/keepify.rb', line 22

def trackEvent(event_type, user_id, options = {})
	# merge with static params
	options.merge!(@options)

	# check for mandatory params
	if(event_type.nil? || event_type.empty?)
		raise "event_type should be supplied"
	elsif (user_id.nil? || user_id.empty?)
		raise "A user identifier (user email) should be supplied"
	else
		options[:kpuid] = user_id
		options[:kpet] = event_type
	end

	uri = URI(REQUEST_URL)
	uri.query = URI.encode_www_form(options)

	if(@async)
		Thread.new {
			send_request(uri)
		}
	else
		send_request(uri)
	end
	
end