userinfuser 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +15 -0
- data/lib/userinfuser.rb +292 -0
- data/test/tc_awardbadges.rb +83 -0
- data/test/tc_awardpoints.rb +51 -0
- data/test/tc_getuserdata.rb +101 -0
- data/test/tc_getwidgets.rb +37 -0
- data/test/tc_users.rb +106 -0
- data/test/test_helper.rb +11 -0
- data/test/ts_userinfuser.rb +85 -0
- metadata +90 -0
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Copyright (C) 2011 CloudCaptive
|
2
|
+
|
3
|
+
This program is free software: you can redistribute it and/or modify
|
4
|
+
it under the terms of the GNU General Public License as published by
|
5
|
+
the Free Software Foundation, either version 3 of the License, or
|
6
|
+
(at your option) any later version.
|
7
|
+
|
8
|
+
This program is distributed in the hope that it will be useful,
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
GNU General Public License for more details.
|
12
|
+
|
13
|
+
You should have received a copy of the GNU General Public License
|
14
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
data/lib/userinfuser.rb
ADDED
@@ -0,0 +1,292 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2011 CloudCaptive
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
=end
|
17
|
+
|
18
|
+
# Programmer: Chris Bunch
|
19
|
+
|
20
|
+
require 'rubygems'
|
21
|
+
require 'json'
|
22
|
+
|
23
|
+
require 'digest/sha1'
|
24
|
+
require 'logger'
|
25
|
+
require 'net/http'
|
26
|
+
require 'uri'
|
27
|
+
|
28
|
+
class UserInfuserBadConfiguration < StandardError
|
29
|
+
end
|
30
|
+
|
31
|
+
class UserInfuserUnknownWidget < StandardError
|
32
|
+
end
|
33
|
+
|
34
|
+
class UserInfuser
|
35
|
+
UI_SPATH = "https://cloudcaptive-userinfuser.appspot.com/api/"
|
36
|
+
UI_PATH = "http://cloudcaptive-userinfuser.appspot.com/api/"
|
37
|
+
LOCAL_TEST = "http://localhost:8080/api/"
|
38
|
+
API_VER = "1"
|
39
|
+
VALID_WIDGETS = ["trophy_case", "milestones", "notifier", "points", "rank", "availablebadges", "leaderboard"]
|
40
|
+
UPDATE_USER_PATH = "updateuser"
|
41
|
+
GET_USER_DATA_PATH = "getuserdata"
|
42
|
+
AWARD_BADGE_PATH = "awardbadge"
|
43
|
+
REMOVE_BADGE_PATH = "removebadge"
|
44
|
+
AWARD_BADGE_POINTS_PATH = "awardbadgepoints"
|
45
|
+
AWARD_POINTS_PATH = "awardpoints"
|
46
|
+
WIDGET_PATH = "getwidget"
|
47
|
+
CREATE_BADGE_PATH= "createbadge"
|
48
|
+
RAISE_EXCEPTIONS = false
|
49
|
+
|
50
|
+
def initialize(account, api_key, debug=false, local=false, encrypt=true, sync_all=false)
|
51
|
+
@ui_url = UI_PATH
|
52
|
+
@ui_url = UI_SPATH if encrypt
|
53
|
+
|
54
|
+
@isGAE = false
|
55
|
+
@sync_all = sync_all
|
56
|
+
|
57
|
+
@debug = debug
|
58
|
+
log_debug "debug is on, account: #{account}, apikey: #{api_key}"
|
59
|
+
|
60
|
+
@api_key = api_key
|
61
|
+
raise UserInfuserBadConfiguration if account.nil? or api_key.nil?
|
62
|
+
|
63
|
+
@account = account
|
64
|
+
|
65
|
+
@raise_exceptions = RAISE_EXCEPTIONS
|
66
|
+
|
67
|
+
if local
|
68
|
+
@ui_url = LOCAL_TEST
|
69
|
+
log_debug "Local testing enabled"
|
70
|
+
@raise_exceptions = true
|
71
|
+
end
|
72
|
+
|
73
|
+
@update_user_path = @ui_url + API_VER + "/" + UPDATE_USER_PATH
|
74
|
+
@award_badge_path = @ui_url + API_VER + "/" + AWARD_BADGE_PATH
|
75
|
+
@award_badge_points_path = @ui_url + API_VER + "/"+ AWARD_BADGE_POINTS_PATH
|
76
|
+
@award_points_path = @ui_url + API_VER + "/"+ AWARD_POINTS_PATH
|
77
|
+
@get_user_data_path = @ui_url + API_VER + "/" + GET_USER_DATA_PATH
|
78
|
+
@remove_badge_path = @ui_url + API_VER + "/" + REMOVE_BADGE_PATH
|
79
|
+
@widget_path = @ui_url + API_VER + "/" + WIDGET_PATH
|
80
|
+
@create_badge_path = @ui_url + API_VER + "/" + CREATE_BADGE_PATH
|
81
|
+
|
82
|
+
@timeout = 10 # seconds
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_user_data(id)
|
86
|
+
params = { "apikey" => @api_key,
|
87
|
+
"userid" => id,
|
88
|
+
"accountid" => @account
|
89
|
+
}
|
90
|
+
|
91
|
+
result = '{"status":"failed"}'
|
92
|
+
|
93
|
+
begin
|
94
|
+
result = post(@get_user_data_path, params)
|
95
|
+
log_debug "Received #{result}"
|
96
|
+
rescue Exception => e
|
97
|
+
log_debug "Connection Error"
|
98
|
+
raise e if @raise_exceptions
|
99
|
+
end
|
100
|
+
|
101
|
+
begin
|
102
|
+
result = JSON.parse(result)
|
103
|
+
rescue
|
104
|
+
log_debug "Unable to parse return message"
|
105
|
+
end
|
106
|
+
|
107
|
+
return result
|
108
|
+
end
|
109
|
+
|
110
|
+
def update_user(id, name, link_to_profile, link_to_profile_image)
|
111
|
+
params = { "apikey" => @api_key,
|
112
|
+
"userid" => id,
|
113
|
+
"accountid" => @account,
|
114
|
+
"profile_name" => name,
|
115
|
+
"profile_link" => link_to_profile,
|
116
|
+
"profile_img" => link_to_profile_image
|
117
|
+
}
|
118
|
+
|
119
|
+
if @sync_all
|
120
|
+
result = post(@update_user_path, params)
|
121
|
+
return parse_return(result)
|
122
|
+
else
|
123
|
+
async_post(@update_user_path, params)
|
124
|
+
return true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def award_badge(user_id, badge_id, reason="", resource="")
|
129
|
+
params = { "apikey" => @api_key,
|
130
|
+
"accountid" => @account,
|
131
|
+
"userid" => user_id,
|
132
|
+
"badgeid" => badge_id,
|
133
|
+
"resource" => resource,
|
134
|
+
"reason" => reason}
|
135
|
+
|
136
|
+
result = nil
|
137
|
+
begin
|
138
|
+
if @sync_all
|
139
|
+
result = post(@award_badge_path, params)
|
140
|
+
else
|
141
|
+
async_post(@award_badge_path, params)
|
142
|
+
return true
|
143
|
+
end
|
144
|
+
|
145
|
+
log_debug "Received: #{result}"
|
146
|
+
rescue Exception => e
|
147
|
+
log_debug "Connection Error"
|
148
|
+
raise e if @raise_exceptions
|
149
|
+
end
|
150
|
+
|
151
|
+
return parse_return(result)
|
152
|
+
end
|
153
|
+
|
154
|
+
def remove_badge(user_id, badge_id)
|
155
|
+
params = {"apikey" => @api_key,
|
156
|
+
"accountid" => @account,
|
157
|
+
"userid" => user_id,
|
158
|
+
"badgeid" => badge_id
|
159
|
+
}
|
160
|
+
|
161
|
+
result = nil
|
162
|
+
begin
|
163
|
+
if @sync_all
|
164
|
+
result = post(@remove_badge_path, params)
|
165
|
+
else
|
166
|
+
async_post(@remove_badge_path, params)
|
167
|
+
return true
|
168
|
+
end
|
169
|
+
|
170
|
+
log_debug "Received: #{result}"
|
171
|
+
rescue Exception => e
|
172
|
+
log_debug "Connection Error"
|
173
|
+
raise e if @raise_exceptions
|
174
|
+
end
|
175
|
+
|
176
|
+
return parse_return(result)
|
177
|
+
end
|
178
|
+
|
179
|
+
def award_points(user_id, points_awarded, reason="")
|
180
|
+
params = { "apikey" => @api_key,
|
181
|
+
"accountid" => @account,
|
182
|
+
"userid" => user_id,
|
183
|
+
"pointsawarded" => points_awarded,
|
184
|
+
"reason" => reason
|
185
|
+
}
|
186
|
+
|
187
|
+
result = nil
|
188
|
+
begin
|
189
|
+
if @sync_all
|
190
|
+
result = post(@award_points_path, params)
|
191
|
+
else
|
192
|
+
async_post(@award_points_path, params)
|
193
|
+
return true
|
194
|
+
end
|
195
|
+
|
196
|
+
log_debug "Received #{result}"
|
197
|
+
rescue Exception => e
|
198
|
+
log_debug "Connection Error"
|
199
|
+
raise e if @raise_exceptions
|
200
|
+
end
|
201
|
+
|
202
|
+
return parse_return(result)
|
203
|
+
end
|
204
|
+
|
205
|
+
def award_badge_points(user_id, badge_id, points_awarded, points_required, reason="", resource="")
|
206
|
+
params = { "apikey" => @api_key,
|
207
|
+
"accountid" => @account,
|
208
|
+
"userid" => user_id,
|
209
|
+
"badgeid" => badge_id,
|
210
|
+
"pointsawarded" => points_awarded,
|
211
|
+
"pointsrequired" => points_required,
|
212
|
+
"reason" => reason,
|
213
|
+
"resource" => resource}
|
214
|
+
|
215
|
+
result = nil
|
216
|
+
begin
|
217
|
+
if @sync_all
|
218
|
+
result = post(@award_badge_points_path, params)
|
219
|
+
else
|
220
|
+
async_post(@award_badge_points_path, params)
|
221
|
+
return true
|
222
|
+
end
|
223
|
+
|
224
|
+
log_debug "Received: #{result}"
|
225
|
+
rescue Exception => e
|
226
|
+
log_debug "Connection Error"
|
227
|
+
raise e if @raise_exceptions
|
228
|
+
end
|
229
|
+
|
230
|
+
return parse_return(result)
|
231
|
+
end
|
232
|
+
|
233
|
+
def get_widget(user_id, widget_type, height=500, width=300)
|
234
|
+
raise UserInfuserUnknownWidget unless VALID_WIDGETS.include?(widget_type)
|
235
|
+
userhash = Digest::SHA1.hexdigest(@account + '---' + user_id)
|
236
|
+
prefetch_widget(widget_type, user_id)
|
237
|
+
|
238
|
+
if widget_type == "notifier"
|
239
|
+
return "<div style='z-index:9999; overflow: hidden; position: fixed; bottom: 0px; right: 10px;'><iframe style='border:none;' allowtransparency='true' height='#{height}px' width='#{width}px' scrolling='no' src='#{@widget_path}?widget=#{widget_type}&u=#{userhash}&height=#{height}&width=#{width}'>Sorry your browser does not support iframes!</iframe></div>"
|
240
|
+
else
|
241
|
+
return "<iframe border='0' z-index:9999; frameborder='0' height='#{height}px' width='#{width}px' scrolling='no' src='#{@widget_path}?widget=#{widget_type}&u=#{userhash}&height=#{height}&width=#{width}'>Sorry your browser does not support iframes!</iframe>"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
private
|
246
|
+
|
247
|
+
def post(path, params)
|
248
|
+
uri = URI.parse(path)
|
249
|
+
response = Net::HTTP.post_form(uri, params)
|
250
|
+
return response.body
|
251
|
+
end
|
252
|
+
|
253
|
+
def async_post(path, params)
|
254
|
+
Thread.new { post(path, params) }
|
255
|
+
end
|
256
|
+
|
257
|
+
def parse_return(string)
|
258
|
+
json = nil
|
259
|
+
|
260
|
+
begin
|
261
|
+
json = JSON.parse(string)
|
262
|
+
rescue
|
263
|
+
log_debug "unable to parse return message"
|
264
|
+
return false
|
265
|
+
end
|
266
|
+
|
267
|
+
if json['status'] == 'failed'
|
268
|
+
log_debug json['error']
|
269
|
+
return false
|
270
|
+
end
|
271
|
+
|
272
|
+
return true
|
273
|
+
end
|
274
|
+
|
275
|
+
def prefetch_widget(widget_type, user_id)
|
276
|
+
params = {"apikey" => @api_key,
|
277
|
+
"accountid" => @account,
|
278
|
+
"userid" => user_id,
|
279
|
+
"widget" => widget_type
|
280
|
+
}
|
281
|
+
|
282
|
+
begin
|
283
|
+
async_post(@widget_path, params)
|
284
|
+
rescue
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def log_debug(msg)
|
289
|
+
puts msg if @debug
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2011 CloudCaptive
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
=end
|
17
|
+
|
18
|
+
# Programmer: Chris Bunch
|
19
|
+
|
20
|
+
class TestAwardBadges < Test::Unit::TestCase
|
21
|
+
def test_award_sync_good
|
22
|
+
ui = get_good_ui(SYNC_ALL)
|
23
|
+
|
24
|
+
assert(ui.award_badge(ID1, BADGEID1, REASON))
|
25
|
+
assert_equal(false, ui.award_badge(ID1, "", REASON))
|
26
|
+
assert_equal(false, ui.award_badge(ID1, BADGEID1 + "xxx", REASON))
|
27
|
+
assert(ui.award_badge(ID1, BADGEID2, REASON))
|
28
|
+
|
29
|
+
assert(ui.remove_badge(ID1, BADGEID3))
|
30
|
+
assert_equal(false, ui.get_user_data(ID1).to_s.include?(BADGEID3))
|
31
|
+
|
32
|
+
assert(ui.award_badge_points(ID1, BADGEID3, 10, 100, REASON))
|
33
|
+
assert(ui.award_badge_points(ID1, BADGEID3, 10, 100, REASON))
|
34
|
+
assert(ui.award_badge_points(ID1, BADGEID3, 10, 100, REASON))
|
35
|
+
assert_equal(false, ui.get_user_data(ID1).to_s.include?(BADGEID3))
|
36
|
+
|
37
|
+
assert(ui.award_badge_points(ID1, BADGEID3, 70, 100, REASON))
|
38
|
+
assert(ui.get_user_data(ID1).to_s.include?(BADGEID3))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_award_sync_bad
|
42
|
+
ui = get_bad_ui(SYNC_ALL)
|
43
|
+
|
44
|
+
assert_equal(false, ui.award_badge(ID1, BADGEID1, REASON))
|
45
|
+
assert_equal(false, ui.award_badge(ID1, BADGEID2, REASON))
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_award_async_good
|
49
|
+
ui = get_good_ui(ASYNC_ALL)
|
50
|
+
|
51
|
+
assert(ui.award_badge(ID1, BADGEID1, REASON))
|
52
|
+
assert(ui.award_badge(ID1, "", REASON))
|
53
|
+
assert(ui.award_badge(ID1, BADGEID1 + "xxx", REASON))
|
54
|
+
assert(ui.award_badge(ID1, BADGEID2, REASON))
|
55
|
+
|
56
|
+
assert(ui.remove_badge(ID1, BADGEID3))
|
57
|
+
sleep(1)
|
58
|
+
assert_equal(false, ui.get_user_data(ID1).to_s.include?(BADGEID3))
|
59
|
+
|
60
|
+
3.times {
|
61
|
+
assert(ui.award_badge_points(ID1, BADGEID3, 10, 100, REASON))
|
62
|
+
sleep(1)
|
63
|
+
}
|
64
|
+
|
65
|
+
assert_equal(false, ui.get_user_data(ID1).to_s.include?(BADGEID3))
|
66
|
+
|
67
|
+
3.times {
|
68
|
+
assert(ui.award_badge_points(ID1, BADGEID3, 70, 100, REASON))
|
69
|
+
}
|
70
|
+
|
71
|
+
sleep(2)
|
72
|
+
|
73
|
+
assert(ui.get_user_data(ID1).to_s.include?(BADGEID3))
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_award_async_bad
|
77
|
+
ui = get_good_ui(ASYNC_ALL)
|
78
|
+
|
79
|
+
assert(ui.award_badge(ID1, BADGEID1, REASON))
|
80
|
+
assert(ui.award_badge(ID1, BADGEID2, REASON))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2011 CloudCaptive
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
=end
|
17
|
+
|
18
|
+
# Programmer: Chris Bunch
|
19
|
+
|
20
|
+
class TestAwardPoints < Test::Unit::TestCase
|
21
|
+
def test_award_sync_good
|
22
|
+
ui = get_good_ui(SYNC_ALL)
|
23
|
+
|
24
|
+
assert(ui.award_points(ID1, 100, REASON))
|
25
|
+
assert(ui.award_points(ID1, 100, REASON))
|
26
|
+
assert_equal(false, ui.award_points(ID1, "xxx", REASON))
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_award_sync_bad
|
30
|
+
ui = get_bad_ui(SYNC_ALL)
|
31
|
+
|
32
|
+
assert_equal(false, ui.award_points(ID1, 100, REASON))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_award_async_good
|
36
|
+
ui = get_good_ui(ASYNC_ALL)
|
37
|
+
|
38
|
+
2.times {
|
39
|
+
assert(ui.award_points(ID1, 100, REASON))
|
40
|
+
}
|
41
|
+
|
42
|
+
assert(ui.award_points(ID1, "xxx", REASON))
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_award_async_bad
|
46
|
+
ui = get_bad_ui(ASYNC_ALL)
|
47
|
+
|
48
|
+
assert(ui.award_points(ID1, 100, REASON))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2011 CloudCaptive
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
=end
|
17
|
+
|
18
|
+
# Programmer: Chris Bunch
|
19
|
+
|
20
|
+
class TestGetUserData < Test::Unit::TestCase
|
21
|
+
def test_getuserdata_sync_good
|
22
|
+
ui = get_good_ui(SYNC_ALL)
|
23
|
+
|
24
|
+
assert(ui.get_user_data(ID1).to_s.include?(BADGEID1))
|
25
|
+
assert(ui.get_user_data(ID1).to_s.include?(BADGEID2))
|
26
|
+
assert(ui.get_user_data(ID1).to_s.include?(ID1))
|
27
|
+
|
28
|
+
assert(ui.get_user_data(ID1).to_s.include?("200"))
|
29
|
+
assert_equal("failed", ui.get_user_data("blahblahblah___"))
|
30
|
+
|
31
|
+
if CLEANUP
|
32
|
+
assert(ui.remove_badge(ID1, BADGEID1))
|
33
|
+
assert(ui.remove_badge(ID1, BADGEID2))
|
34
|
+
assert(ui.remove_badge(ID1, BADGEID3))
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_equal(false, ui.remove_badge(ID1, "-x-x-x" + BADGEID3 + "xxx"))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_getuserdata_sync_bad
|
41
|
+
ui = get_bad_ui(SYNC_ALL)
|
42
|
+
|
43
|
+
assert(ui.get_user_data(ID1).to_s.include?("failed"))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_delete_path
|
47
|
+
assert_equal(SUCCESS, TestHelper.post(DELETE_PATH, PARAMS))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_getuserdata_async_good
|
51
|
+
ui = get_good_ui(ASYNC_ALL)
|
52
|
+
|
53
|
+
sleep(1)
|
54
|
+
[BADGEID1, BADGEID2, ID1, "200"].each { |item|
|
55
|
+
assert(ui.get_user_data(ID1).to_s.include?(item))
|
56
|
+
}
|
57
|
+
|
58
|
+
if CLEANUP
|
59
|
+
[BADGEID1, BADGEID2, BADGEID3].each { |badge|
|
60
|
+
assert(ui.remove_badge(ID1, badge))
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
assert(ui.remove_badge(TESTID, "-x-x-x" + BADGEID3 + "xxx"))
|
65
|
+
|
66
|
+
user_name = "Raj"
|
67
|
+
user_url = "http://www.facebook.com/nlake44"
|
68
|
+
user_img="http://profile.ak.fbcdn.net/hprofile-ak-snc4/203059_3610637_6604695_n.jpg"
|
69
|
+
assert(ui.update_user(ID2, user_name, user_url, user_img))
|
70
|
+
|
71
|
+
r = "rank"
|
72
|
+
assert(ui.get_widget(ID2, r).to_s.include?(r))
|
73
|
+
|
74
|
+
assert(ui.award_points(ID2, 10))
|
75
|
+
assert(ui.update_user(ID3))
|
76
|
+
|
77
|
+
badge_img = "http://cdn1.iconfinder.com/data/icons/Futurosoft%20Icons%200.5.2/128x128/apps/limewire.png"
|
78
|
+
assert(ui.create_badge("apple","oranges","fruit", badge_img))
|
79
|
+
sleep(1)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_cleanup
|
83
|
+
return unless CLEANUP
|
84
|
+
|
85
|
+
params = {
|
86
|
+
"apikey" => API_KEY,
|
87
|
+
"accountid" => ACCOUNT,
|
88
|
+
"badgeid" => BADGEID1,
|
89
|
+
"secret" => SECRET,
|
90
|
+
"user" => ID1,
|
91
|
+
"theme" => BADGETHEME
|
92
|
+
}
|
93
|
+
|
94
|
+
[ID1, ID2, ID3].each { |id|
|
95
|
+
params['user'] = id
|
96
|
+
assert(TestHelper.post(PRIME_PATH, params).include?("success"))
|
97
|
+
assert(TestHelper.post(DELETE_PATH, params).include?("success"))
|
98
|
+
}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2011 CloudCaptive
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
=end
|
17
|
+
|
18
|
+
# Programmer: Chris Bunch
|
19
|
+
|
20
|
+
class TestGetWidget < Test::Unit::TestCase
|
21
|
+
def test_user_good
|
22
|
+
[SYNC_ALL, ASYNC_ALL].each { |sync|
|
23
|
+
update_user_good(sync)
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def update_user_good(sync)
|
28
|
+
ui = get_good_ui(sync)
|
29
|
+
|
30
|
+
["trophy_case", "milestones", "points", "rank", "notifier"].each { |item|
|
31
|
+
assert(ui.get_widget(ID1, item).to_s.include?(item))
|
32
|
+
}
|
33
|
+
|
34
|
+
assert_raise(UserInfuserUnknownWidget) { ui.get_widget(ID1, "doesnotexist") }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/test/tc_users.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2011 CloudCaptive
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
=end
|
17
|
+
|
18
|
+
# Programmer: Chris Bunch
|
19
|
+
|
20
|
+
class TestUsers < Test::Unit::TestCase
|
21
|
+
def test_prime_db
|
22
|
+
prime_success = TestHelper.post(PRIME_PATH, PARAMS)
|
23
|
+
assert_equal(SUCCESS, prime_success)
|
24
|
+
|
25
|
+
delete_success = TestHelper.post(DELETE_PATH, PARAMS)
|
26
|
+
assert_equal(SUCCESS, delete_success)
|
27
|
+
|
28
|
+
prime_success = TestHelper.post(PRIME_PATH, PARAMS)
|
29
|
+
assert_equal(SUCCESS, prime_success)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_update_user_sync_good
|
33
|
+
ui = get_good_ui(SYNC_ALL)
|
34
|
+
|
35
|
+
user_name = "Raaaaaaj"
|
36
|
+
user_url = "http://facebook.com/nlake44"
|
37
|
+
user_img = "http://imgur.com/AK9Fw"
|
38
|
+
|
39
|
+
assert(ui.update_user(ID1, user_name, user_url, user_img))
|
40
|
+
|
41
|
+
user_name2 = "Raj"
|
42
|
+
user_img2 = "http://profile.ak.fbcdn.net/hprofile-ak-snc4/203059_3610637_6604695_n.jpg"
|
43
|
+
|
44
|
+
assert(ui.update_user(ID1, user_name2, user_url, user_img2))
|
45
|
+
|
46
|
+
user_name3 = "Billy Gene"
|
47
|
+
user_url3 = "http://www.facebook.com/isnotmylove"
|
48
|
+
user_img3 = "http://cdn3.iconfinder.com/data/icons/faceavatars/PNG/J01.png"
|
49
|
+
assert(ui.update_user(ID2, user_name3, user_url3, user_img3))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_update_user_sync_bad
|
53
|
+
ui = get_bad_ui(SYNC_ALL)
|
54
|
+
|
55
|
+
user_name = "Heather"
|
56
|
+
user_url = "http://www.facebook.com/profile.php?id=710661131"
|
57
|
+
user_img = "http://profile.ak.fbcdn.net/hprofile-ak-snc4/203293_710661131_7132437_n.jpg"
|
58
|
+
|
59
|
+
assert_equal(false, ui.update_user(ID1, user_name, user_url, user_img))
|
60
|
+
|
61
|
+
user_name2 = "Jack Smith"
|
62
|
+
user_url2 = "http://test.com/a"
|
63
|
+
user_img2 = "http://test.com/a/image"
|
64
|
+
|
65
|
+
assert_equal(false, ui.update_user(ID1, user_name2, user_url2, user_img2))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_update_user_async_good
|
69
|
+
ui = get_good_ui(ASYNC_ALL)
|
70
|
+
|
71
|
+
user_name = "Raj"
|
72
|
+
user_url = "http://facebook.com/nlake44"
|
73
|
+
user_img = "http://imgur.com/AK9Fw"
|
74
|
+
|
75
|
+
assert(ui.update_user(ID1, user_name, user_url, user_img))
|
76
|
+
|
77
|
+
user_name2 = "Jakob"
|
78
|
+
user_url2 = "http://profile.ak.fbcdn.net/hprofile-ak-snc4/49299_669633666_9641_n.jpg"
|
79
|
+
user_img2 = "http://profile.ak.fbcdn.net/hprofile-ak-snc4/49299_669633666_9641_n.jpg"
|
80
|
+
|
81
|
+
assert(ui.update_user(ID1, user_name2, user_url2, user_img2))
|
82
|
+
|
83
|
+
user_name3 = "Shan"
|
84
|
+
user_url3 = "http://www.facebook.com/profile.php?id=3627076"
|
85
|
+
user_img3 = "http://www.facebook.com/album.php?profile=1&id=3627076"
|
86
|
+
|
87
|
+
assert(ui.update_user(ID1, user_name3, user_url3, user_img3))
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_update_user_async_bad
|
91
|
+
ui = get_bad_ui(ASYNC_ALL)
|
92
|
+
|
93
|
+
user_name = "a"
|
94
|
+
user_url = "http://test.com/a"
|
95
|
+
user_img = "http://test.com/a/image"
|
96
|
+
|
97
|
+
assert(ui.update_user(ID1, user_name, user_url, user_img))
|
98
|
+
|
99
|
+
user_name2 = "Jack Smith"
|
100
|
+
user_url2 = "http://test.com/a"
|
101
|
+
user_img2 = "http://test.com/a/image"
|
102
|
+
|
103
|
+
assert(ui.update_user(ID1, user_name2, user_url2, user_img2))
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (C) 2011 CloudCaptive
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
=end
|
17
|
+
|
18
|
+
# Programmer: Chris Bunch
|
19
|
+
|
20
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
21
|
+
require 'userinfuser'
|
22
|
+
|
23
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "test")
|
24
|
+
require 'test_helper'
|
25
|
+
|
26
|
+
require 'test/unit'
|
27
|
+
|
28
|
+
ACCOUNT = "test@test.c"
|
29
|
+
API_KEY = "ABCDEFGHI"
|
30
|
+
|
31
|
+
DEFAULT_DEBUG = true
|
32
|
+
NO_DEBUG = false
|
33
|
+
|
34
|
+
IS_LOCAL = true
|
35
|
+
IS_REMOTE = false
|
36
|
+
|
37
|
+
ENCRYPT = true
|
38
|
+
NO_ENCRYPT = false
|
39
|
+
|
40
|
+
SYNC_ALL = true
|
41
|
+
ASYNC_ALL = false
|
42
|
+
|
43
|
+
SECRET = "8u8u9i9i"
|
44
|
+
|
45
|
+
ID1 = "testuserid"
|
46
|
+
ID2 = "anotheruser"
|
47
|
+
ID3 = "anotheruserxxxx"
|
48
|
+
|
49
|
+
BADGEID1 = "music-1-private"
|
50
|
+
BADGEID2 = "music-2-private"
|
51
|
+
BADGEID3 = "music-3-private"
|
52
|
+
BADGETHEME = "music"
|
53
|
+
|
54
|
+
PRIME_PATH = "http://localhost:8080/api/1/test"
|
55
|
+
DELETE_PATH = "http://localhost:8080/api/1/testcleanup"
|
56
|
+
|
57
|
+
CLEANUP = false
|
58
|
+
|
59
|
+
SUCCESS = '{"status": "success"}'
|
60
|
+
|
61
|
+
PARAMS = {
|
62
|
+
"apikey" => API_KEY,
|
63
|
+
"accountid" => ACCOUNT,
|
64
|
+
"badgeid" => BADGEID1,
|
65
|
+
"secret" => SECRET,
|
66
|
+
"user" => ID1,
|
67
|
+
"theme" => BADGETHEME
|
68
|
+
}
|
69
|
+
|
70
|
+
REASON = "just because"
|
71
|
+
|
72
|
+
def get_good_ui(sync)
|
73
|
+
return UserInfuser.new(ACCOUNT, API_KEY, DEFAULT_DEBUG, IS_LOCAL, NO_ENCRYPT, sync)
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_bad_ui(sync)
|
77
|
+
return UserInfuser.new(ACCOUNT, API_KEY + "x", DEFAULT_DEBUG, IS_LOCAL, NO_ENCRYPT, sync)
|
78
|
+
end
|
79
|
+
|
80
|
+
require 'tc_users'
|
81
|
+
require 'tc_awardbadges'
|
82
|
+
require 'tc_getwidgets'
|
83
|
+
require 'tc_awardpoints'
|
84
|
+
require 'tc_getuserdata'
|
85
|
+
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: userinfuser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 59
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Chris Bunch
|
14
|
+
autorequire: userinfuser
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-30 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 5
|
33
|
+
- 1
|
34
|
+
version: 1.5.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: " userinfuser provides customizable gamification elements designed to \n increase user interaction on websites. The project involves badging, \n points, live notifications, and leaderboards. Additonally, the \n platform provides analytics to track user participation. This particular\n library provides a Ruby interface to the userinfuser software service,\n hosted either locally, on AppScale, or on Google App Engine.\n"
|
38
|
+
email: cgb@cloudcaptive.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
files:
|
46
|
+
- lib/userinfuser.rb
|
47
|
+
- test/tc_awardbadges.rb
|
48
|
+
- test/tc_users.rb
|
49
|
+
- test/tc_awardpoints.rb
|
50
|
+
- test/test_helper.rb
|
51
|
+
- test/tc_getwidgets.rb
|
52
|
+
- test/tc_getuserdata.rb
|
53
|
+
- test/ts_userinfuser.rb
|
54
|
+
- LICENSE
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://www.cloudcaptive.com/
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.4.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: A Ruby interface to the userinfuser software service.
|
89
|
+
test_files: []
|
90
|
+
|