Skip to content

Commit 825a3f3

Browse files
committed
Merge branch 'master' of github.com:outboundio/lib-ruby
2 parents 9cf8866 + 2054ccf commit 825a3f3

File tree

2 files changed

+20
-34
lines changed

2 files changed

+20
-34
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ build/
1919
/_yardoc/
2020
/doc/
2121
/rdoc/
22+
.idea/
23+
/lib/.idea/
2224

2325
## Environment normalisation:
2426
/.bundle/

lib/outbound.rb

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,51 +29,51 @@ module Defaults
2929
}
3030
end
3131

32-
def Outbound.init api_key, log_level=Logger::ERROR
32+
def Outbound.init(api_key, log_level=Logger::ERROR)
3333
@logger.level = log_level
3434
@ob = Outbound::Client.new api_key, @logger
3535
end
3636

37-
def Outbound.identify user_id, info={}
37+
def Outbound.identify(user_id, info={})
3838
if @ob == nil
3939
res = Result.new Outbound::ERROR_INIT, false
4040
@logger.error res.error
4141
return res
4242
end
43-
return @ob.identify user_id, info
43+
return @ob.identify(user_id, info)
4444
end
4545

46-
def Outbound.track user_id, event, properties={}, user_info={}, timestamp
46+
def Outbound.track(user_id, event, properties={}, timestamp=Time.now.to_i)
4747
if @ob == nil
4848
res = Result.new Outbound::ERROR_INIT, false
4949
@logger.error res.error
5050
return res
5151
end
52-
return @ob.track user_id, event, properties, user_info, timestamp
52+
return @ob.track(user_id, event, properties, timestamp)
5353
end
5454

55-
def Outbound.disable platform, user_id, token
55+
def Outbound.disable(platform, user_id, token)
5656
if @ob == nil
5757
res = Result.new Outbound::ERROR_INIT, false
5858
@logger.error res.error
5959
return res
6060
end
61-
return @ob.disable platform, user_id, token
61+
return @ob.disable(platform, user_id, token)
6262
end
6363

64-
def Outbound.register platform, user_id, token
64+
def Outbound.register(platform, user_id, token)
6565
if @ob == nil
6666
res = Result.new Outbound::ERROR_INIT, false
6767
@logger.error res.error
6868
return res
6969
end
70-
return @ob.register platform, user_id, token
70+
return @ob.register(platform, user_id, token)
7171
end
7272

7373
class Result
7474
include Defaults
7575

76-
def initialize error, received_call
76+
def initialize(error, received_call)
7777
@error = error
7878
@received_call = received_call
7979
end
@@ -113,12 +113,12 @@ def platform_error?
113113
class Client
114114
include Defaults
115115

116-
def initialize api_key, logger
116+
def initialize(api_key, logger)
117117
@api_key = api_key
118118
@logger = logger
119119
end
120120

121-
def identify user_id, info={}
121+
def identify(user_id, info={})
122122
unless user_id.is_a? String or user_id.is_a? Numeric
123123
res = Result.new Outbound::ERROR_USER_ID, false
124124
@logger.error res.error
@@ -136,7 +136,7 @@ def identify user_id, info={}
136136
return post(@api_key, '/identify', user_data)
137137
end
138138

139-
def track user_id, event, properties={}, user_info={}, timestamp
139+
def track(user_id, event, properties={}, user_info={}, timestamp=Time.now.to_i)
140140
unless user_id.is_a? String or user_id.is_a? Numeric
141141
res = Result.new Outbound::ERROR_USER_ID, false
142142
@logger.error res.error
@@ -151,15 +151,6 @@ def track user_id, event, properties={}, user_info={}, timestamp
151151

152152
data = {:user_id => user_id, :event => event}
153153

154-
begin
155-
user = user(user_info)
156-
if user.length > 0
157-
data[:user] = user
158-
end
159-
rescue
160-
@logger.error "Could not use user info (#{user_info}) and/or user attributes #{user_attributes} given to track call."
161-
end
162-
163154
if properties.is_a? Hash
164155
if properties.length > 0
165156
data[:properties] = properties
@@ -168,20 +159,13 @@ def track user_id, event, properties={}, user_info={}, timestamp
168159
@logger.error "Could not use event properties (#{properties}) given to track call."
169160
end
170161

162+
data[:timestamp] = timestamp
171163
puts timestamp
172164

173-
unless timestamp == {}
174-
data[:timestamp] = timestamp
175-
else
176-
data[:timestamp] = Time.now.to_i
177-
end
178-
179-
puts data[:timestamp]
180-
181165
return post(@api_key, '/track', data)
182166
end
183167

184-
def disable platform, user_id, token
168+
def disable(platform, user_id, token)
185169
unless user_id.is_a? String or user_id.is_a? Numeric
186170
res = Result.new Outbound::ERROR_USER_ID, false
187171
@logger.error res.error
@@ -203,7 +187,7 @@ def disable platform, user_id, token
203187
return post(@api_key, "/#{platform}/disable", {:token => token, :user_id => user_id})
204188
end
205189

206-
def register platform, user_id, token
190+
def register(platform, user_id, token)
207191
unless user_id.is_a? String or user_id.is_a? Numeric
208192
res = Result.new Outbound::ERROR_USER_ID, false
209193
@logger.error res.error
@@ -227,7 +211,7 @@ def register platform, user_id, token
227211

228212
private
229213

230-
def post api_key, path, data
214+
def post(api_key, path, data)
231215
begin
232216
headers = HEADERS
233217
headers['X-Outbound-Key'] = api_key
@@ -253,7 +237,7 @@ def post api_key, path, data
253237
return err, true
254238
end
255239

256-
def user info={}
240+
def user(info={})
257241
unless info.is_a? Hash
258242
raise
259243
end

0 commit comments

Comments
 (0)