Skip to content

Commit 9060071

Browse files
committed
alias method
1 parent 3d813b5 commit 9060071

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/outbound.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Outbound
1111
GCM = "gcm"
1212

1313
ERROR_USER_ID = "User ID must be a string or number."
14+
ERROR_PREVIOUS_ID = "Previous ID must be a string or number."
1415
ERROR_EVENT_NAME = "Event name must be a string."
1516
ERROR_CONNECTION = "Outbound connection error"
1617
ERROR_INIT = "Must call init() before identify() or track()."
@@ -35,6 +36,15 @@ def Outbound.init(api_key, log_level=Logger::ERROR)
3536
@ob = Outbound::Client.new api_key, @logger
3637
end
3738

39+
def Outbound.alias(user_id, previous_id)
40+
if @ob == nil
41+
res = Result.new Outbound::ERROR_INIT, false
42+
@logger.error res.error
43+
return res
44+
end
45+
return @ob.identify(user_id, previous_id)
46+
end
47+
3848
def Outbound.identify(user_id, info={})
3949
if @ob == nil
4050
res = Result.new Outbound::ERROR_INIT, false
@@ -150,6 +160,23 @@ def initialize(api_key, logger)
150160
@logger = logger
151161
end
152162

163+
def alias(user_id, previous_id)
164+
unless user_id.is_a? String or user_id.is_a? Numeric
165+
res = Result.new Outbound::ERROR_USER_ID, false
166+
@logger.error res.error
167+
return res
168+
end
169+
170+
unless previous_id.is_a? String or previous_id.is_a? Numeric
171+
res = Result.new Outbound::ERROR_PREVIOUS_ID, false
172+
@logger.error res.error
173+
return res
174+
end
175+
176+
user_data = {:user_id => user_id, :previous_id => previous_id}
177+
return post(@api_key, '/identify', user_data)
178+
end
179+
153180
def identify(user_id, info={})
154181
unless user_id.is_a? String or user_id.is_a? Numeric
155182
res = Result.new Outbound::ERROR_USER_ID, false

0 commit comments

Comments
 (0)