App42_Ruby_API 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/App42_Ruby_API.gemspec +33 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/TODO.rb +3 -0
- data/lib/App42_Ruby_API.rb +232 -0
- data/lib/App42_Ruby_API/App42BadParameterException.rb +31 -0
- data/lib/App42_Ruby_API/App42Exception.rb +39 -0
- data/lib/App42_Ruby_API/App42LimitException.rb +15 -0
- data/lib/App42_Ruby_API/App42NotFoundException.rb +15 -0
- data/lib/App42_Ruby_API/App42Response.rb +13 -0
- data/lib/App42_Ruby_API/App42ResponseBuilder.rb +67 -0
- data/lib/App42_Ruby_API/App42SecurityException.rb +15 -0
- data/lib/App42_Ruby_API/version.rb +3 -0
- data/lib/connection/RESTConnection.rb +713 -0
- data/lib/email/Email.rb +51 -0
- data/lib/email/EmailMIME.rb +51 -0
- data/lib/email/EmailResponseBuilder.rb +76 -0
- data/lib/email/EmailService.rb +244 -0
- data/lib/gallery/Album.rb +56 -0
- data/lib/gallery/AlbumResponseBuilder.rb +168 -0
- data/lib/gallery/AlbumService.rb +337 -0
- data/lib/gallery/PhotoService.rb +591 -0
- data/lib/game/Game.rb +39 -0
- data/lib/game/GameResponseBuilder.rb +106 -0
- data/lib/game/GameService.rb +268 -0
- data/lib/game/Reward.rb +24 -0
- data/lib/game/RewardResponseBuilder.rb +85 -0
- data/lib/game/RewardService.rb +440 -0
- data/lib/game/ScoreBoardService.rb +433 -0
- data/lib/game/ScoreService.rb +157 -0
- data/lib/geo/Geo.rb +51 -0
- data/lib/geo/GeoPoint.rb +43 -0
- data/lib/geo/GeoResponseBuilder.rb +145 -0
- data/lib/geo/GeoService.rb +505 -0
- data/lib/imageProcessor/Image.rb +42 -0
- data/lib/imageProcessor/ImageProcessorResponseBuilder.rb +40 -0
- data/lib/imageProcessor/ImageProcessorService.rb +1054 -0
- data/lib/log/Log.rb +49 -0
- data/lib/log/LogResponseBuilder.rb +61 -0
- data/lib/log/LogService.rb +920 -0
- data/lib/message/Queue.rb +50 -0
- data/lib/message/QueueResponseBuilder.rb +64 -0
- data/lib/message/QueueService.rb +469 -0
- data/lib/push/DeviceType.rb +56 -0
- data/lib/push/PushNotification.rb +38 -0
- data/lib/push/PushNotificationResposneBuilder.rb +74 -0
- data/lib/push/PushNotificationService.rb +458 -0
- data/lib/recommend/PreferenceData.rb +25 -0
- data/lib/recommend/Recommender.rb +48 -0
- data/lib/recommend/RecommenderResponseBuilder.rb +70 -0
- data/lib/recommend/RecommenderService.rb +1092 -0
- data/lib/recommend/RecommenderSimilarity.rb +52 -0
- data/lib/review/Review.rb +38 -0
- data/lib/review/ReviewResponseBuilder.rb +76 -0
- data/lib/review/ReviewService.rb +590 -0
- data/lib/session/Session.rb +43 -0
- data/lib/session/SessionResponseBuilder.rb +70 -0
- data/lib/session/SessionService.rb +427 -0
- data/lib/shopping/Cart.rb +77 -0
- data/lib/shopping/CartResponseBuilder.rb +118 -0
- data/lib/shopping/CartService.rb +902 -0
- data/lib/shopping/Catalogue.rb +79 -0
- data/lib/shopping/CatalogueResponseBuilder.rb +170 -0
- data/lib/shopping/CatalogueService.rb +649 -0
- data/lib/shopping/ItemData.rb +29 -0
- data/lib/shopping/PaymentStatus.rb +60 -0
- data/lib/social/Social.rb +35 -0
- data/lib/social/SocialResponseBuilder.rb +38 -0
- data/lib/social/SocialService.rb +585 -0
- data/lib/storage/OrderByType.rb +29 -0
- data/lib/storage/Query.rb +39 -0
- data/lib/storage/QueryBuilder.rb +118 -0
- data/lib/storage/Storage.rb +45 -0
- data/lib/storage/StorageResponseBuilder.rb +86 -0
- data/lib/storage/StorageService.rb +775 -0
- data/lib/upload/Upload.rb +40 -0
- data/lib/upload/UploadFileType.rb +83 -0
- data/lib/upload/UploadResponseBuilder.rb +58 -0
- data/lib/upload/UploadService.rb +960 -0
- data/lib/user/User.rb +102 -0
- data/lib/user/UserResponseBuilder.rb +105 -0
- data/lib/user/UserService.rb +1209 -0
- data/lib/util/util.rb +244 -0
- data/question.rb +79 -0
- metadata +204 -0
@@ -0,0 +1,440 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'connection/RESTConnection'
|
7
|
+
require 'util/util.rb'
|
8
|
+
require 'json/pure'
|
9
|
+
require 'App42_Ruby_API/App42Response'
|
10
|
+
require 'game/RewardResponseBuilder'
|
11
|
+
require 'game/Reward'
|
12
|
+
|
13
|
+
module App42
|
14
|
+
module Game
|
15
|
+
#
|
16
|
+
# Define a Reward e.g. Sword, Energy etc. Is needed for Reward Points
|
17
|
+
# The Game service allows Game, User, Score and ScoreBoard Management on the Cloud.
|
18
|
+
# The service allows Game Developer to create a Game and then do in Game Scoring using the
|
19
|
+
# Score service. It also allows to maintain a Scoreboard across game sessions using the ScoreBoard
|
20
|
+
# service. One can query for average or highest score for user for a Game and highest and average score across users
|
21
|
+
# for a Game. It also gives ranking of the user against other users for a particular game.
|
22
|
+
# The Reward and RewardPoints allows the Game Developer to assign rewards to a user and redeem the rewards.
|
23
|
+
#
|
24
|
+
# E.g. One can give Swords or Energy etc.
|
25
|
+
# The services Game, Score, ScoreBoard, Reward, RewardPoints can be used in Conjunction for complete Game Scoring and Reward
|
26
|
+
# Management.
|
27
|
+
#
|
28
|
+
# @see Game, RewardPoint, Score, ScoreBoard
|
29
|
+
#
|
30
|
+
class RewardService
|
31
|
+
#
|
32
|
+
# this is a constructor that takes
|
33
|
+
#
|
34
|
+
# @param apiKey
|
35
|
+
# @param secretKey
|
36
|
+
# @param baseURL
|
37
|
+
#
|
38
|
+
def initialize(api_key, secret_key, base_url)
|
39
|
+
puts "Reward->initialize"
|
40
|
+
@api_key = api_key
|
41
|
+
@secret_key = secret_key
|
42
|
+
@base_url = base_url
|
43
|
+
@resource = "game/reward"
|
44
|
+
@version = "1.0"
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Creates Reward. Reward can be Sword, Energy etc. When Reward Points have to be
|
49
|
+
# added the Reward name created using this method has to be specified.
|
50
|
+
#
|
51
|
+
# @param rewardName
|
52
|
+
# - The reward that has to be created
|
53
|
+
# @param rewardDescription
|
54
|
+
# - The description of the reward to be created
|
55
|
+
#
|
56
|
+
# @return Reward object containing the reward that has been created
|
57
|
+
#
|
58
|
+
# @raise App42Exception
|
59
|
+
#
|
60
|
+
|
61
|
+
def create_reward(rewardName, rewardDescription)
|
62
|
+
puts "Create Reward Called "
|
63
|
+
puts "Base url #{@base_url}"
|
64
|
+
response = nil;
|
65
|
+
rewardObj = nil;
|
66
|
+
rewardObj = Reward.new()
|
67
|
+
util = Util.new
|
68
|
+
util.throwExceptionIfNullOrBlank(rewardName, "Reward Name");
|
69
|
+
util.throwExceptionIfNullOrBlank(rewardDescription, "Reward Description");
|
70
|
+
begin
|
71
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
72
|
+
body = {'app42' => {"rewards"=> { "reward"=> {
|
73
|
+
"name" => rewardName,
|
74
|
+
"description" => rewardDescription
|
75
|
+
}}}}.to_json
|
76
|
+
puts "Body #{body}"
|
77
|
+
query_params = Hash.new
|
78
|
+
params = {
|
79
|
+
'apiKey'=> @api_key,
|
80
|
+
'version' => @version,
|
81
|
+
'timeStamp' => util.get_timestamp_utc,
|
82
|
+
}
|
83
|
+
query_params = params.clone
|
84
|
+
params.store("body", body)
|
85
|
+
puts query_params
|
86
|
+
signature = util.sign(@secret_key, params)
|
87
|
+
resource_url = "#{@version}/#{@resource}"
|
88
|
+
response = connection.post(signature, resource_url, query_params, body)
|
89
|
+
puts "Response is #{response}"
|
90
|
+
reward = RewardResponseBuilder.new()
|
91
|
+
rewardObj = reward.buildResponse(response)
|
92
|
+
rescue App42Exception =>e
|
93
|
+
raise e
|
94
|
+
rescue Exception => e
|
95
|
+
raise App42Exception.new(e)
|
96
|
+
end
|
97
|
+
return rewardObj
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Fetches all the Rewards
|
102
|
+
#
|
103
|
+
# @return ArrayList of Reward objects containing all the rewards of the App
|
104
|
+
#
|
105
|
+
# @raise App42Exception
|
106
|
+
#
|
107
|
+
#
|
108
|
+
|
109
|
+
def get_all_rewards()
|
110
|
+
puts "Get All Rewards Called "
|
111
|
+
puts "Base url #{@base_url}"
|
112
|
+
response = nil;
|
113
|
+
rewardList = nil;
|
114
|
+
rewardList = Array.new
|
115
|
+
util = Util.new
|
116
|
+
begin
|
117
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
118
|
+
query_params = Hash.new
|
119
|
+
params = {
|
120
|
+
'apiKey'=> @api_key,
|
121
|
+
'version' => @version,
|
122
|
+
'timeStamp' => util.get_timestamp_utc,
|
123
|
+
}
|
124
|
+
query_params = params.clone
|
125
|
+
signature = util.sign(@secret_key, params)
|
126
|
+
resource_url = "#{@version}/#{@resource}"
|
127
|
+
response = connection.get(signature, resource_url, query_params)
|
128
|
+
puts "Response is #{response}"
|
129
|
+
reward = RewardResponseBuilder.new()
|
130
|
+
rewardList = reward.buildArrayRewards(response)
|
131
|
+
rescue App42Exception =>e
|
132
|
+
raise e
|
133
|
+
rescue Exception => e
|
134
|
+
raise App42Exception.new(e)
|
135
|
+
end
|
136
|
+
return rewardList
|
137
|
+
end
|
138
|
+
|
139
|
+
#
|
140
|
+
# Fetches all the Rewards by paging.
|
141
|
+
#
|
142
|
+
# @param max
|
143
|
+
# - Maximum number of records to be fetched
|
144
|
+
# @param offset
|
145
|
+
# - From where the records are to be fetched
|
146
|
+
#
|
147
|
+
# @return ArrayList of Reward objects containing all the rewards of the App
|
148
|
+
#
|
149
|
+
# @raise App42Exception
|
150
|
+
#
|
151
|
+
|
152
|
+
def get_all_rewards_by_paging(max, offset)
|
153
|
+
puts "get_all_rewards_by_paging Called "
|
154
|
+
puts "Base url #{@base_url}"
|
155
|
+
response = nil;
|
156
|
+
rewardList = nil;
|
157
|
+
rewardList = Array.new
|
158
|
+
util = Util.new
|
159
|
+
util.validateMax(max);
|
160
|
+
util.throwExceptionIfNullOrBlank(max, "Max");
|
161
|
+
util.throwExceptionIfNullOrBlank(offset, "Offset");
|
162
|
+
begin
|
163
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
164
|
+
query_params = Hash.new
|
165
|
+
params = {
|
166
|
+
'apiKey'=> @api_key,
|
167
|
+
'version' => @version,
|
168
|
+
'timeStamp' => util.get_timestamp_utc,
|
169
|
+
}
|
170
|
+
query_params = params.clone
|
171
|
+
params.store("max", "" + (max.to_i).to_s)
|
172
|
+
params.store("offset", "" + (offset.to_i).to_s)
|
173
|
+
signature = util.sign(@secret_key, params)
|
174
|
+
resource_url = "#{@version}/#{@resource}/paging/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
|
175
|
+
response = connection.get(signature, resource_url, query_params)
|
176
|
+
puts "Response is #{response}"
|
177
|
+
reward = RewardResponseBuilder.new()
|
178
|
+
rewardList = reward.buildArrayRewards(response)
|
179
|
+
rescue App42Exception =>e
|
180
|
+
raise e
|
181
|
+
rescue Exception => e
|
182
|
+
raise App42Exception.new(e)
|
183
|
+
end
|
184
|
+
return rewardList
|
185
|
+
end
|
186
|
+
|
187
|
+
#
|
188
|
+
# Retrieves the reward for the specified name
|
189
|
+
#
|
190
|
+
# @param rewardName
|
191
|
+
# - Name of the reward that has to be fetched
|
192
|
+
#
|
193
|
+
# @return Reward object containing the reward based on the rewardName
|
194
|
+
#
|
195
|
+
# @raise App42Exception
|
196
|
+
#
|
197
|
+
|
198
|
+
def get_reward_by_name(rewardName)
|
199
|
+
puts "Get reward By Name Called "
|
200
|
+
puts "Base url #{@base_url}"
|
201
|
+
response = nil;
|
202
|
+
rewardObj = nil;
|
203
|
+
rewardObj = Reward.new()
|
204
|
+
util = Util.new
|
205
|
+
util.throwExceptionIfNullOrBlank(rewardName, "Reward Name");
|
206
|
+
begin
|
207
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
208
|
+
query_params = Hash.new
|
209
|
+
params = {
|
210
|
+
'apiKey'=> @api_key,
|
211
|
+
'version' => @version,
|
212
|
+
'timeStamp' => util.get_timestamp_utc,
|
213
|
+
}
|
214
|
+
query_params = params.clone
|
215
|
+
params.store("name", rewardName)
|
216
|
+
puts query_params
|
217
|
+
signature = util.sign(@secret_key, params)
|
218
|
+
resource_url = "#{@version}/#{@resource}/#{rewardName}"
|
219
|
+
response = connection.get(signature, resource_url, query_params)
|
220
|
+
puts "Response is #{response}"
|
221
|
+
reward = RewardResponseBuilder.new()
|
222
|
+
rewardObj = reward.buildResponse(response)
|
223
|
+
rescue App42Exception =>e
|
224
|
+
raise e
|
225
|
+
rescue Exception => e
|
226
|
+
raise App42Exception.new(e)
|
227
|
+
end
|
228
|
+
return rewardObj
|
229
|
+
end
|
230
|
+
|
231
|
+
#
|
232
|
+
# Adds the reward points to an users account. Reward Points can be earned by the user
|
233
|
+
# which can be redeemed later.
|
234
|
+
#
|
235
|
+
# @param gameName
|
236
|
+
# - Name of the game for which reward points have to be added
|
237
|
+
# @param gameUserName
|
238
|
+
# - The user for whom reward points have to be added
|
239
|
+
# @param rewardName
|
240
|
+
# - The rewards for which reward points have to be added
|
241
|
+
# @param rewardsPoints
|
242
|
+
# - The points that have to be added
|
243
|
+
#
|
244
|
+
# @return Reward object containing the rewardpoints that has been added
|
245
|
+
#
|
246
|
+
# @raise App42Exception
|
247
|
+
#
|
248
|
+
|
249
|
+
def earn_rewards(gameName,gameUserName,rewardName,rewardPoints)
|
250
|
+
puts "Earn Rewards Called "
|
251
|
+
puts "Base url #{@base_url}"
|
252
|
+
response = nil;
|
253
|
+
rewardObj = nil;
|
254
|
+
rewardObj = Reward.new()
|
255
|
+
util = Util.new
|
256
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
257
|
+
util.throwExceptionIfNullOrBlank(gameUserName, "User Name");
|
258
|
+
util.throwExceptionIfNullOrBlank(rewardName, "Reward Name");
|
259
|
+
|
260
|
+
begin
|
261
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
262
|
+
body = {'app42' => {"rewards"=> { "reward"=> {
|
263
|
+
"gameName" => gameName,
|
264
|
+
"userName" => gameUserName,
|
265
|
+
"name" => rewardName,
|
266
|
+
"points" => rewardPoints
|
267
|
+
}}}}.to_json
|
268
|
+
puts "Body #{body}"
|
269
|
+
query_params = Hash.new
|
270
|
+
params = {
|
271
|
+
'apiKey'=> @api_key,
|
272
|
+
'version' => @version,
|
273
|
+
'timeStamp' => util.get_timestamp_utc,
|
274
|
+
}
|
275
|
+
query_params = params.clone
|
276
|
+
params.store("body", body)
|
277
|
+
puts query_params
|
278
|
+
signature = util.sign(@secret_key, params)
|
279
|
+
resource_url = "#{@version}/#{@resource}/earn"
|
280
|
+
response = connection.post(signature, resource_url, query_params, body)
|
281
|
+
puts "Response is #{response}"
|
282
|
+
reward = RewardResponseBuilder.new()
|
283
|
+
rewardObj = reward.buildResponse(response)
|
284
|
+
rescue App42Exception =>e
|
285
|
+
raise e
|
286
|
+
rescue Exception => e
|
287
|
+
raise App42Exception.new(e)
|
288
|
+
end
|
289
|
+
return rewardObj
|
290
|
+
end
|
291
|
+
|
292
|
+
#
|
293
|
+
# Deducts the rewardpoints from the earned rewards by a user.
|
294
|
+
#
|
295
|
+
# @param gameName
|
296
|
+
# - Name of the game for which reward points have to be deducted
|
297
|
+
# @param gameUserName
|
298
|
+
# - The user for whom reward points have to be deducted
|
299
|
+
# @param rewardName
|
300
|
+
# - The rewards for which reward points have to be deducted
|
301
|
+
# @param rewardsPoints
|
302
|
+
# - The points that have to be deducted
|
303
|
+
#
|
304
|
+
# @return Reward object containing the rewardpoints that has been deducted
|
305
|
+
#
|
306
|
+
# @raise App42Exception
|
307
|
+
#
|
308
|
+
|
309
|
+
def redeem_rewards(gameName,gameUserName,rewardName,rewardPoints)
|
310
|
+
puts "Redeem Rewards Called "
|
311
|
+
puts "Base url #{@base_url}"
|
312
|
+
response = nil;
|
313
|
+
rewardObj = nil;
|
314
|
+
rewardObj = Reward.new()
|
315
|
+
util = Util.new
|
316
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
317
|
+
util.throwExceptionIfNullOrBlank(gameUserName, "Game User Name");
|
318
|
+
util.throwExceptionIfNullOrBlank(rewardName, "Reward Name");
|
319
|
+
begin
|
320
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
321
|
+
body = {'app42' => {"rewards"=> { "reward"=> {
|
322
|
+
"gameName" => gameName,
|
323
|
+
"userName" => gameUserName,
|
324
|
+
"name" => rewardName,
|
325
|
+
"points" => rewardPoints
|
326
|
+
}}}}.to_json
|
327
|
+
puts "Body #{body}"
|
328
|
+
query_params = Hash.new
|
329
|
+
params = {
|
330
|
+
'apiKey'=> @api_key,
|
331
|
+
'version' => @version,
|
332
|
+
'timeStamp' => util.get_timestamp_utc,
|
333
|
+
}
|
334
|
+
query_params = params.clone
|
335
|
+
puts query_params
|
336
|
+
params.store("body", body)
|
337
|
+
signature = util.sign(@secret_key, params)
|
338
|
+
resource_url = "#{@version}/#{@resource}/redeem"
|
339
|
+
response = connection.post(signature, resource_url, query_params, body)
|
340
|
+
puts "Response is #{response}"
|
341
|
+
reward = RewardResponseBuilder.new()
|
342
|
+
rewardObj = reward.buildResponse(response)
|
343
|
+
rescue App42Exception =>e
|
344
|
+
raise e
|
345
|
+
rescue Exception => e
|
346
|
+
raise App42Exception.new(e)
|
347
|
+
end
|
348
|
+
return rewardObj
|
349
|
+
end
|
350
|
+
|
351
|
+
#
|
352
|
+
# Fetches the reward points for a particular user
|
353
|
+
#
|
354
|
+
# @param gameName
|
355
|
+
# - Name of the game for which reward points have to be fetched
|
356
|
+
# @param userName
|
357
|
+
# - The user for whom reward points have to be fetched
|
358
|
+
#
|
359
|
+
# @return Reward object containing the reward points for the specified user
|
360
|
+
#
|
361
|
+
# @raise App42Exception
|
362
|
+
#
|
363
|
+
|
364
|
+
def get_game_reward_points_for_user(gameName, userName)
|
365
|
+
puts "Get Game Reward Points For User Called "
|
366
|
+
puts "Base url #{@base_url}"
|
367
|
+
response = nil;
|
368
|
+
rewardObj = nil;
|
369
|
+
rewardObj = Reward.new()
|
370
|
+
util = Util.new
|
371
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
372
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
373
|
+
begin
|
374
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
375
|
+
query_params = Hash.new
|
376
|
+
params = {
|
377
|
+
'apiKey'=> @api_key,
|
378
|
+
'version' => @version,
|
379
|
+
'timeStamp' => util.get_timestamp_utc,
|
380
|
+
}
|
381
|
+
query_params = params.clone
|
382
|
+
params.store("gameName", gameName)
|
383
|
+
params.store("userName", userName)
|
384
|
+
puts query_params
|
385
|
+
signature = util.sign(@secret_key, params)
|
386
|
+
resource_url = "#{@version}/#{@resource}/#{gameName}/#{userName}"
|
387
|
+
response = connection.get(signature, resource_url, query_params)
|
388
|
+
puts "Response is #{response}"
|
389
|
+
reward = RewardResponseBuilder.new()
|
390
|
+
rewardObj = reward.buildResponse(response)
|
391
|
+
rescue App42Exception =>e
|
392
|
+
raise e
|
393
|
+
rescue Exception => e
|
394
|
+
raise App42Exception.new(e)
|
395
|
+
end
|
396
|
+
return rewardObj
|
397
|
+
end
|
398
|
+
|
399
|
+
#
|
400
|
+
# Fetches all the Rewards
|
401
|
+
#
|
402
|
+
# @return ArrayList of Reward objects containing all the rewards of the App
|
403
|
+
#
|
404
|
+
# @raise App42Exception
|
405
|
+
#
|
406
|
+
|
407
|
+
def get_all_rewards_count()
|
408
|
+
puts "get_all_rewards_count Called "
|
409
|
+
puts "Base url #{@base_url}"
|
410
|
+
response = nil;
|
411
|
+
responseObj = App42Response.new
|
412
|
+
util = Util.new
|
413
|
+
begin
|
414
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
415
|
+
query_params = Hash.new
|
416
|
+
params = {
|
417
|
+
'apiKey'=> @api_key,
|
418
|
+
'version' => @version,
|
419
|
+
'timeStamp' => util.get_timestamp_utc,
|
420
|
+
}
|
421
|
+
query_params = params.clone
|
422
|
+
puts query_params
|
423
|
+
signature = util.sign(@secret_key, params)
|
424
|
+
resource_url = "#{@version}/#{@resource}/count"
|
425
|
+
response = connection.get(signature, resource_url, query_params)
|
426
|
+
responseObj.strResponse=(response)
|
427
|
+
responseObj.isResponseSuccess=(true)
|
428
|
+
responseObj = RewardResponseBuilder.new()
|
429
|
+
responseObj.getTotalRecords(response);
|
430
|
+
rescue App42Exception =>e
|
431
|
+
raise e
|
432
|
+
rescue Exception => e
|
433
|
+
raise App42Exception.new(e)
|
434
|
+
end
|
435
|
+
return responseObj
|
436
|
+
end
|
437
|
+
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
@@ -0,0 +1,433 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'connection/RESTConnection'
|
6
|
+
require 'util/util'
|
7
|
+
require 'json/pure'
|
8
|
+
|
9
|
+
module App42
|
10
|
+
module Game
|
11
|
+
#
|
12
|
+
# ScoreBoard allows storing, retrieving, querying and ranking scores for users and Games across
|
13
|
+
# Game Session.
|
14
|
+
#
|
15
|
+
# The Game service allows Game, User, Score and ScoreBoard Management on the Cloud.
|
16
|
+
# The service allows Game Developer to create a Game and then do in Game Scoring using the
|
17
|
+
# Score service. It also allows to maintain a Scoreboard across game sessions using the ScoreBoard
|
18
|
+
# service. One can query for average or highest score for user for a Game and highest and average score across users
|
19
|
+
# for a Game. It also gives ranking of the user against other users for a particular game.
|
20
|
+
# The Reward and RewardPoints allows the Game Developer to assign rewards to a user and redeem the rewards.
|
21
|
+
#
|
22
|
+
# E.g. One can give Swords or Energy etc.
|
23
|
+
# The services Game, Score, ScoreBoard, Reward, RewardPoints can be used in Conjunction for complete Game Scoring and Reward
|
24
|
+
# Management.
|
25
|
+
#
|
26
|
+
# @see Game, RewardPoint, RewardPoint, Score
|
27
|
+
#
|
28
|
+
class ScoreBoardService
|
29
|
+
#
|
30
|
+
# this is a constructor that takes
|
31
|
+
#
|
32
|
+
# @param apiKey
|
33
|
+
# @param secretKey
|
34
|
+
# @param baseURL
|
35
|
+
#
|
36
|
+
def initialize(api_key, secret_key, base_url)
|
37
|
+
puts "Game->initialize"
|
38
|
+
@api_key = api_key
|
39
|
+
@secret_key = secret_key
|
40
|
+
@base_url = base_url
|
41
|
+
@resource = "game/scoreboard"
|
42
|
+
@version = "1.0"
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Saves the User score for a game
|
47
|
+
#
|
48
|
+
# @param gameName
|
49
|
+
# - Name of the game for which score has to be saved
|
50
|
+
# @param gameUserName
|
51
|
+
# - The user for which score has to be saved
|
52
|
+
# @param gameScore
|
53
|
+
# - The sore that has to be saved
|
54
|
+
#
|
55
|
+
# @return Returns the saved score for a game
|
56
|
+
#
|
57
|
+
# @raise App42Exception
|
58
|
+
#
|
59
|
+
|
60
|
+
def save_user_score(gameName, gameUserName, gameScore)
|
61
|
+
puts "Save User Score Called "
|
62
|
+
puts "Base url #{@base_url}"
|
63
|
+
response = nil;
|
64
|
+
scoreboardObj = nil;
|
65
|
+
scoreboardObj = Game.new
|
66
|
+
util = Util.new
|
67
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
68
|
+
util.throwExceptionIfNullOrBlank(gameUserName, "User Name");
|
69
|
+
begin
|
70
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
71
|
+
body = {'app42' => {"game"=> {
|
72
|
+
"name" => gameName,"scores" => { "score" => {
|
73
|
+
"value" => gameScore,
|
74
|
+
"userName" => gameUserName
|
75
|
+
}}}}}.to_json
|
76
|
+
puts "Body #{body}"
|
77
|
+
query_params = Hash.new
|
78
|
+
params = {
|
79
|
+
'apiKey'=> @api_key,
|
80
|
+
'version' => @version,
|
81
|
+
'timeStamp' => util.get_timestamp_utc,
|
82
|
+
}
|
83
|
+
query_params = params.clone
|
84
|
+
params.store("body", body)
|
85
|
+
puts query_params
|
86
|
+
signature = util.sign(@secret_key, params)
|
87
|
+
resource_url = "#{@version}/#{@resource}"
|
88
|
+
response = connection.post(signature, resource_url, query_params, body)
|
89
|
+
puts "Response is #{response}"
|
90
|
+
game = GameResponseBuilder.new()
|
91
|
+
scoreboardObj = game.buildResponse(response)
|
92
|
+
rescue App42Exception =>e
|
93
|
+
raise e
|
94
|
+
rescue Exception => e
|
95
|
+
raise App42Exception.new(e)
|
96
|
+
end
|
97
|
+
return scoreboardObj
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Retrieves the scores for a game for the specified name
|
102
|
+
#
|
103
|
+
# @param gameName
|
104
|
+
# - Name of the game for which score has to be fetched
|
105
|
+
# @param userName
|
106
|
+
# - The user for which score has to be fetched
|
107
|
+
#
|
108
|
+
# @return Returns the game score for the specified user
|
109
|
+
#
|
110
|
+
# @raise App42Exception
|
111
|
+
#
|
112
|
+
|
113
|
+
def get_scores_by_user(gameName, userName)
|
114
|
+
puts "Get Score By User Called "
|
115
|
+
puts "Base url #{@base_url}"
|
116
|
+
response = nil;
|
117
|
+
scoreboardObj = nil;
|
118
|
+
scoreboardObj = Game.new
|
119
|
+
util = Util.new
|
120
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
121
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
122
|
+
begin
|
123
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
124
|
+
query_params = Hash.new
|
125
|
+
params = {
|
126
|
+
'apiKey'=> @api_key,
|
127
|
+
'version' => @version,
|
128
|
+
'timeStamp' => util.get_timestamp_utc,
|
129
|
+
}
|
130
|
+
query_params = params.clone
|
131
|
+
params.store("name", gameName)
|
132
|
+
params.store("userName", userName)
|
133
|
+
puts query_params
|
134
|
+
signature = util.sign(@secret_key, params)
|
135
|
+
resource_url = "#{@version}/#{@resource}/#{gameName}/#{userName}"
|
136
|
+
response = connection.get(signature, resource_url, query_params)
|
137
|
+
puts "Response is #{response}"
|
138
|
+
game = GameResponseBuilder.new()
|
139
|
+
scoreboardObj = game.buildResponse(response)
|
140
|
+
rescue App42Exception =>e
|
141
|
+
raise e
|
142
|
+
rescue Exception => e
|
143
|
+
raise App42Exception.new(e)
|
144
|
+
end
|
145
|
+
return scoreboardObj
|
146
|
+
end
|
147
|
+
|
148
|
+
#
|
149
|
+
# Retrieves the highest game score for the specified user
|
150
|
+
#
|
151
|
+
# @param gameName
|
152
|
+
# - Name of the game for which highest score has to be fetched
|
153
|
+
# @param userName
|
154
|
+
# - The user for which highest score has to be fetched
|
155
|
+
#
|
156
|
+
# @return Returns the highest game score for the specified user
|
157
|
+
#
|
158
|
+
# @raise App42Exception
|
159
|
+
#
|
160
|
+
|
161
|
+
def get_highest_score_by_user(gameName, userName)
|
162
|
+
puts "Get Highest Score By User Called "
|
163
|
+
puts "Base url #{@base_url}"
|
164
|
+
response = nil;
|
165
|
+
scoreboardObj = nil;
|
166
|
+
scoreboardObj = Game.new
|
167
|
+
util = Util.new
|
168
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
169
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
170
|
+
begin
|
171
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
172
|
+
query_params = Hash.new
|
173
|
+
params = {
|
174
|
+
'apiKey'=> @api_key,
|
175
|
+
'version' => @version,
|
176
|
+
'timeStamp' => util.get_timestamp_utc,
|
177
|
+
}
|
178
|
+
query_params = params.clone
|
179
|
+
params.store("name", gameName)
|
180
|
+
params.store("userName", userName)
|
181
|
+
puts query_params
|
182
|
+
signature = util.sign(@secret_key, params)
|
183
|
+
resource_url = "#{@version}/#{@resource}/#{gameName}/#{userName}/highest"
|
184
|
+
response = connection.get(signature, resource_url, query_params)
|
185
|
+
puts "Response is #{response}"
|
186
|
+
game = GameResponseBuilder.new()
|
187
|
+
scoreboardObj = game.buildResponse(response)
|
188
|
+
rescue App42Exception =>e
|
189
|
+
raise e
|
190
|
+
rescue Exception => e
|
191
|
+
raise App42Exception.new(e)
|
192
|
+
end
|
193
|
+
return scoreboardObj
|
194
|
+
end
|
195
|
+
|
196
|
+
#
|
197
|
+
# Retrieves the lowest game score for the specified user
|
198
|
+
#
|
199
|
+
# @param gameName
|
200
|
+
# - Name of the game for which lowest score has to be fetched
|
201
|
+
# @param userName
|
202
|
+
# - The user for which lowest score has to be fetched
|
203
|
+
#
|
204
|
+
# @return Returns the lowest game score for the specified user
|
205
|
+
#
|
206
|
+
# @raise App42Exception
|
207
|
+
#
|
208
|
+
|
209
|
+
def get_lowest_score_by_user(gameName, userName)
|
210
|
+
puts "Get Lowest Score By User Called "
|
211
|
+
puts "Base url #{@base_url}"
|
212
|
+
response = nil;
|
213
|
+
scoreboardObj = nil;
|
214
|
+
scoreboardObj = Game.new
|
215
|
+
util = Util.new
|
216
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
217
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
218
|
+
begin
|
219
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
220
|
+
query_params = Hash.new
|
221
|
+
params = {
|
222
|
+
'apiKey'=> @api_key,
|
223
|
+
'version' => @version,
|
224
|
+
'timeStamp' => util.get_timestamp_utc,
|
225
|
+
}
|
226
|
+
query_params = params.clone
|
227
|
+
params.store("name", gameName)
|
228
|
+
params.store("userName", userName)
|
229
|
+
puts query_params
|
230
|
+
signature = util.sign(@secret_key, params)
|
231
|
+
resource_url = "#{@version}/#{@resource}/#{gameName}/#{userName}/lowest"
|
232
|
+
response = connection.get(signature, resource_url, query_params)
|
233
|
+
puts "Response is #{response}"
|
234
|
+
game = GameResponseBuilder.new()
|
235
|
+
scoreboardObj = game.buildResponse(response)
|
236
|
+
rescue App42Exception =>e
|
237
|
+
raise e
|
238
|
+
rescue Exception => e
|
239
|
+
raise App42Exception.new(e)
|
240
|
+
end
|
241
|
+
return scoreboardObj
|
242
|
+
end
|
243
|
+
|
244
|
+
#
|
245
|
+
# Retrieves the Top Rankings for the specified game
|
246
|
+
#
|
247
|
+
# @param gameName
|
248
|
+
# - Name of the game for which ranks have to be fetched
|
249
|
+
#
|
250
|
+
# @return Returns the Top rankings for a game
|
251
|
+
#
|
252
|
+
# @raise App42Exception
|
253
|
+
#
|
254
|
+
|
255
|
+
def get_top_rankings(gameName)
|
256
|
+
puts "Get Top Rankings Called "
|
257
|
+
puts "Base url #{@base_url}"
|
258
|
+
response = nil;
|
259
|
+
scoreboardObj = nil;
|
260
|
+
scoreboardObj = Game.new
|
261
|
+
util = Util.new
|
262
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
263
|
+
begin
|
264
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
265
|
+
query_params = Hash.new
|
266
|
+
params = {
|
267
|
+
'apiKey'=> @api_key,
|
268
|
+
'version' => @version,
|
269
|
+
'timeStamp' => util.get_timestamp_utc,
|
270
|
+
}
|
271
|
+
query_params = params.clone
|
272
|
+
params.store("name", gameName)
|
273
|
+
puts query_params
|
274
|
+
signature = util.sign(@secret_key, params)
|
275
|
+
resource_url = "#{@version}/#{@resource}/#{gameName}/ranking"
|
276
|
+
response = connection.get(signature, resource_url, query_params)
|
277
|
+
puts "Response is #{response}"
|
278
|
+
game = GameResponseBuilder.new()
|
279
|
+
scoreboardObj = game.buildResponse(response)
|
280
|
+
rescue App42Exception =>e
|
281
|
+
raise e
|
282
|
+
rescue Exception => e
|
283
|
+
raise App42Exception.new(e)
|
284
|
+
end
|
285
|
+
return scoreboardObj
|
286
|
+
end
|
287
|
+
|
288
|
+
#
|
289
|
+
# Retrieves the average game score for the specified user
|
290
|
+
#
|
291
|
+
# @param gameName
|
292
|
+
# - Name of the game for which average score has to be fetched
|
293
|
+
# @param userName
|
294
|
+
# - The user for which average score has to be fetched
|
295
|
+
#
|
296
|
+
# @return Returns the average game score for the specified user
|
297
|
+
#
|
298
|
+
# @raise App42Exception
|
299
|
+
#
|
300
|
+
|
301
|
+
def get_average_score_by_user(gameName, userName)
|
302
|
+
puts "Get Top Rankings Called "
|
303
|
+
puts "Base url #{@base_url}"
|
304
|
+
response = nil;
|
305
|
+
scoreboardObj = nil;
|
306
|
+
scoreboardObj = Game.new
|
307
|
+
util = Util.new
|
308
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
309
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
310
|
+
begin
|
311
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
312
|
+
query_params = Hash.new
|
313
|
+
params = {
|
314
|
+
'apiKey'=> @api_key,
|
315
|
+
'version' => @version,
|
316
|
+
'timeStamp' => util.get_timestamp_utc,
|
317
|
+
}
|
318
|
+
query_params = params.clone
|
319
|
+
params.store("name", gameName)
|
320
|
+
params.store("userName", userName);
|
321
|
+
puts query_params
|
322
|
+
signature = util.sign(@secret_key, params)
|
323
|
+
resource_url = "#{@version}/#{@resource}/#{gameName}/#{userName}/average"
|
324
|
+
response = connection.get(signature, resource_url, query_params)
|
325
|
+
puts "Response is #{response}"
|
326
|
+
game = GameResponseBuilder.new()
|
327
|
+
scoreboardObj = game.buildResponse(response)
|
328
|
+
rescue App42Exception =>e
|
329
|
+
raise e
|
330
|
+
rescue Exception => e
|
331
|
+
raise App42Exception.new(e)
|
332
|
+
end
|
333
|
+
return scoreboardObj
|
334
|
+
end
|
335
|
+
|
336
|
+
#
|
337
|
+
# Retrieves the Top N Rankings for the specified game
|
338
|
+
#
|
339
|
+
# @param gameName
|
340
|
+
# - Name of the game for which ranks have to be fetched
|
341
|
+
#
|
342
|
+
# @return Returns the Top rankings for a game
|
343
|
+
#
|
344
|
+
# @raise App42Exception
|
345
|
+
#
|
346
|
+
|
347
|
+
def get_top_n_rankings(gameName, max)
|
348
|
+
puts "Get Top N Rankings Called "
|
349
|
+
puts "Base url #{@base_url}"
|
350
|
+
response = nil;
|
351
|
+
scoreboardObj = nil;
|
352
|
+
scoreboardObj = Game.new
|
353
|
+
util = Util.new
|
354
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
355
|
+
util.throwExceptionIfNullOrBlank(max, "Max");
|
356
|
+
util.validateMax(max);
|
357
|
+
begin
|
358
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
359
|
+
query_params = Hash.new
|
360
|
+
params = {
|
361
|
+
'apiKey'=> @api_key,
|
362
|
+
'version' => @version,
|
363
|
+
'timeStamp' => util.get_timestamp_utc,
|
364
|
+
}
|
365
|
+
query_params = params.clone
|
366
|
+
params.store("name", gameName);
|
367
|
+
params.store("max", ""+ max.to_s);
|
368
|
+
puts query_params
|
369
|
+
signature = util.sign(@secret_key, params)
|
370
|
+
resource_url = "#{@version}/#{@resource}/#{gameName}/ranking/#{max.to_s}"
|
371
|
+
response = connection.get(signature, resource_url, query_params)
|
372
|
+
puts "Response is #{response}"
|
373
|
+
game = GameResponseBuilder.new()
|
374
|
+
scoreboardObj = game.buildResponse(response)
|
375
|
+
rescue App42Exception =>e
|
376
|
+
raise e
|
377
|
+
rescue Exception => e
|
378
|
+
raise App42Exception.new(e)
|
379
|
+
end
|
380
|
+
return scoreboardObj
|
381
|
+
end
|
382
|
+
|
383
|
+
#
|
384
|
+
# Retrieves the User Ranking for the specified game
|
385
|
+
#
|
386
|
+
# @param gameName
|
387
|
+
# - Name of the game for which ranks have to be fetched
|
388
|
+
# @param userName
|
389
|
+
# - Name of the user for which ranks have to be fetched
|
390
|
+
#
|
391
|
+
# @return Returns the rank of the User
|
392
|
+
#
|
393
|
+
# @raise App42Exception
|
394
|
+
#
|
395
|
+
|
396
|
+
def get_user_ranking(gameName, userName)
|
397
|
+
puts "get_user_ranking Called "
|
398
|
+
puts "Base url #{@base_url}"
|
399
|
+
response = nil;
|
400
|
+
scoreboardObj = nil;
|
401
|
+
scoreboardObj = Game.new
|
402
|
+
util = Util.new
|
403
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
404
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
405
|
+
begin
|
406
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
407
|
+
query_params = Hash.new
|
408
|
+
params = {
|
409
|
+
'apiKey'=> @api_key,
|
410
|
+
'version' => @version,
|
411
|
+
'timeStamp' => util.get_timestamp_utc,
|
412
|
+
}
|
413
|
+
query_params = params.clone
|
414
|
+
params.store("name", gameName);
|
415
|
+
params.store("userName", ""+userName);
|
416
|
+
puts query_params
|
417
|
+
signature = util.sign(@secret_key, params)
|
418
|
+
resource_url = "#{@version}/#{@resource}/#{gameName}/#{userName}/ranking"
|
419
|
+
response = connection.get(signature, resource_url, query_params)
|
420
|
+
puts "Response is #{response}"
|
421
|
+
game = GameResponseBuilder.new()
|
422
|
+
scoreboardObj = game.buildResponse(response)
|
423
|
+
rescue App42Exception =>e
|
424
|
+
raise e
|
425
|
+
rescue Exception => e
|
426
|
+
raise App42Exception.new(e)
|
427
|
+
end
|
428
|
+
return scoreboardObj
|
429
|
+
end
|
430
|
+
|
431
|
+
end
|
432
|
+
end
|
433
|
+
end
|