Class: App42::Game::RewardService
- Inherits:
-
Object
- Object
- App42::Game::RewardService
- Defined in:
- lib/game/RewardService.rb
Overview
Define a Reward e.g. Sword, Energy etc. Is needed for Reward Points The Game service allows Game, User, Score and ScoreBoard Management on the Cloud. The service allows Game Developer to create a Game and then do in Game Scoring using the Score service. It also allows to maintain a Scoreboard across game sessions using the ScoreBoard service. One can query for average or highest score for user for a Game and highest and average score across users for a Game. It also gives ranking of the user against other users for a particular game. The Reward and RewardPoints allows the Game Developer to assign rewards to a user and redeem the rewards.
E.g. One can give Swords or Energy etc. The services Game, Score, ScoreBoard, Reward, RewardPoints can be used in Conjunction for complete Game Scoring and Reward Management.
Instance Method Summary collapse
-
#create_reward(rewardName, rewardDescription) ⇒ Object
Creates Reward.
-
#earn_rewards(gameName, gameUserName, rewardName, rewardPoints) ⇒ Object
Adds the reward points to an users account.
-
#get_all_rewards ⇒ Object
Fetches all the Rewards.
-
#get_all_rewards_by_paging(max, offset) ⇒ Object
Fetches all the Rewards by paging.
-
#get_all_rewards_count ⇒ Object
Fetches all the Rewards.
-
#get_game_reward_points_for_user(gameName, userName) ⇒ Object
Fetches the reward points for a particular user.
-
#get_reward_by_name(rewardName) ⇒ Object
Retrieves the reward for the specified name.
-
#initialize(api_key, secret_key, base_url) ⇒ RewardService
constructor
this is a constructor that takes.
-
#redeem_rewards(gameName, gameUserName, rewardName, rewardPoints) ⇒ Object
Deducts the rewardpoints from the earned rewards by a user.
Constructor Details
#initialize(api_key, secret_key, base_url) ⇒ RewardService
this is a constructor that takes
38 39 40 41 42 43 44 45 |
# File 'lib/game/RewardService.rb', line 38 def initialize(api_key, secret_key, base_url) puts "Reward->initialize" @api_key = api_key @secret_key = secret_key @base_url = base_url @resource = "game/reward" @version = "1.0" end |
Instance Method Details
#create_reward(rewardName, rewardDescription) ⇒ Object
Creates Reward. Reward can be Sword, Energy etc. When Reward Points have to be added the Reward name created using this method has to be specified.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/game/RewardService.rb', line 61 def create_reward(rewardName, rewardDescription) puts "Create Reward Called " puts "Base url #{@base_url}" response = nil; rewardObj = nil; rewardObj = Reward.new() util = Util.new util.throwExceptionIfNullOrBlank(rewardName, "Reward Name"); util.throwExceptionIfNullOrBlank(rewardDescription, "Reward Description"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"rewards"=> { "reward"=> { "name" => rewardName, "description" => rewardDescription }}}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util., } query_params = params.clone params.store("body", body) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}" response = connection.post(signature, resource_url, query_params, body) puts "Response is #{response}" reward = RewardResponseBuilder.new() rewardObj = reward.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return rewardObj end |
#earn_rewards(gameName, gameUserName, rewardName, rewardPoints) ⇒ Object
Adds the reward points to an users account. Reward Points can be earned by the user which can be redeemed later.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/game/RewardService.rb', line 249 def earn_rewards(gameName,gameUserName,rewardName,rewardPoints) puts "Earn Rewards Called " puts "Base url #{@base_url}" response = nil; rewardObj = nil; rewardObj = Reward.new() util = Util.new util.throwExceptionIfNullOrBlank(gameName, "Game Name"); util.throwExceptionIfNullOrBlank(gameUserName, "User Name"); util.throwExceptionIfNullOrBlank(rewardName, "Reward Name"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"rewards"=> { "reward"=> { "gameName" => gameName, "userName" => gameUserName, "name" => rewardName, "points" => rewardPoints }}}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util., } query_params = params.clone params.store("body", body) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/earn" response = connection.post(signature, resource_url, query_params, body) puts "Response is #{response}" reward = RewardResponseBuilder.new() rewardObj = reward.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return rewardObj end |
#get_all_rewards ⇒ Object
Fetches all the Rewards
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/game/RewardService.rb', line 109 def get_all_rewards() puts "Get All Rewards Called " puts "Base url #{@base_url}" response = nil; rewardList = nil; rewardList = Array.new util = Util.new begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util., } query_params = params.clone signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}" response = connection.get(signature, resource_url, query_params) puts "Response is #{response}" reward = RewardResponseBuilder.new() rewardList = reward.buildArrayRewards(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return rewardList end |
#get_all_rewards_by_paging(max, offset) ⇒ Object
Fetches all the Rewards by paging.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/game/RewardService.rb', line 152 def get_all_rewards_by_paging(max, offset) puts "get_all_rewards_by_paging Called " puts "Base url #{@base_url}" response = nil; rewardList = nil; rewardList = Array.new util = Util.new util.validateMax(max); util.throwExceptionIfNullOrBlank(max, "Max"); util.throwExceptionIfNullOrBlank(offset, "Offset"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util., } query_params = params.clone params.store("max", "" + (max.to_i).to_s) params.store("offset", "" + (offset.to_i).to_s) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/paging/#{(max.to_i).to_s}/#{(offset.to_i).to_s}" response = connection.get(signature, resource_url, query_params) puts "Response is #{response}" reward = RewardResponseBuilder.new() rewardList = reward.buildArrayRewards(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return rewardList end |
#get_all_rewards_count ⇒ Object
Fetches all the Rewards
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/game/RewardService.rb', line 407 def get_all_rewards_count() puts "get_all_rewards_count Called " puts "Base url #{@base_url}" response = nil; responseObj = App42Response.new util = Util.new begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util., } query_params = params.clone puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/count" response = connection.get(signature, resource_url, query_params) responseObj.strResponse=(response) responseObj.isResponseSuccess=(true) responseObj = RewardResponseBuilder.new() responseObj.getTotalRecords(response); rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return responseObj end |
#get_game_reward_points_for_user(gameName, userName) ⇒ Object
Fetches the reward points for a particular user
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/game/RewardService.rb', line 364 def get_game_reward_points_for_user(gameName, userName) puts "Get Game Reward Points For User Called " puts "Base url #{@base_url}" response = nil; rewardObj = nil; rewardObj = Reward.new() util = Util.new util.throwExceptionIfNullOrBlank(gameName, "Game Name"); util.throwExceptionIfNullOrBlank(userName, "User Name"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util., } query_params = params.clone params.store("gameName", gameName) params.store("userName", userName) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{gameName}/#{userName}" response = connection.get(signature, resource_url, query_params) puts "Response is #{response}" reward = RewardResponseBuilder.new() rewardObj = reward.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return rewardObj end |
#get_reward_by_name(rewardName) ⇒ Object
Retrieves the reward for the specified name
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/game/RewardService.rb', line 198 def get_reward_by_name(rewardName) puts "Get reward By Name Called " puts "Base url #{@base_url}" response = nil; rewardObj = nil; rewardObj = Reward.new() util = Util.new util.throwExceptionIfNullOrBlank(rewardName, "Reward Name"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util., } query_params = params.clone params.store("name", rewardName) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{rewardName}" response = connection.get(signature, resource_url, query_params) puts "Response is #{response}" reward = RewardResponseBuilder.new() rewardObj = reward.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return rewardObj end |
#redeem_rewards(gameName, gameUserName, rewardName, rewardPoints) ⇒ Object
Deducts the rewardpoints from the earned rewards by a user.
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/game/RewardService.rb', line 309 def redeem_rewards(gameName,gameUserName,rewardName,rewardPoints) puts "Redeem Rewards Called " puts "Base url #{@base_url}" response = nil; rewardObj = nil; rewardObj = Reward.new() util = Util.new util.throwExceptionIfNullOrBlank(gameName, "Game Name"); util.throwExceptionIfNullOrBlank(gameUserName, "Game User Name"); util.throwExceptionIfNullOrBlank(rewardName, "Reward Name"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"rewards"=> { "reward"=> { "gameName" => gameName, "userName" => gameUserName, "name" => rewardName, "points" => rewardPoints }}}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util., } query_params = params.clone puts query_params params.store("body", body) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/redeem" response = connection.post(signature, resource_url, query_params, body) puts "Response is #{response}" reward = RewardResponseBuilder.new() rewardObj = reward.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return rewardObj end |