Class: App42::Game::ScoreService
- Inherits:
-
Object
- Object
- App42::Game::ScoreService
- Defined in:
- lib/game/ScoreService.rb
Overview
Allows ingame scoring. It has to be used for scoring for a parituclar Game Session. If scores have to be stored across Game sessions then the service ScoreBoard has to be used. It is especially useful for Multiplayer online or mobile games. 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
-
#addScore(gameName, gameUserName, gameScore) ⇒ Object
Adds game score for the specified user.
-
#deductScore(gameName, gameUserName, gameScore) ⇒ Object
Deducts the score from users account for a particular Game.
-
#initialize(api_key, secret_key, base_url) ⇒ ScoreService
constructor
this is a constructor that takes.
Constructor Details
#initialize(api_key, secret_key, base_url) ⇒ ScoreService
this is a constructor that takes
37 38 39 40 41 42 43 44 |
# File 'lib/game/ScoreService.rb', line 37 def initialize(api_key, secret_key, base_url) puts "Game->initialize" @api_key = api_key @secret_key = secret_key @base_url = base_url @resource = "game/score" @version = "1.0" end |
Instance Method Details
#addScore(gameName, gameUserName, gameScore) ⇒ Object
Adds game score for the specified user.
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 99 |
# File 'lib/game/ScoreService.rb', line 61 def addScore(gameName, gameUserName, gameScore) puts "Add score Called " puts "Base url #{@base_url}" response = nil; scoreObj = nil; scoreObj = Game.new util = Util.new util.throwExceptionIfNullOrBlank(gameName, "Game Name"); util.throwExceptionIfNullOrBlank(gameUserName, "User Name"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"game"=> { "name" => gameName,"scores" => { "score" => { "value" => gameScore, "userName" => gameUserName }}}}}.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}/add" response = connection.post(signature, resource_url, query_params, body) puts "Response is #{response}" game = GameResponseBuilder.new() scoreObj = game.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return scoreObj end |
#deductScore(gameName, gameUserName, gameScore) ⇒ Object
Deducts the score from users account for a particular Game
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/game/ScoreService.rb', line 116 def deductScore(gameName, gameUserName, gameScore) puts "Deduct Score Called " puts "Base url #{@base_url}" response = nil; scoreObj = nil; scoreObj = Game.new util = Util.new util.throwExceptionIfNullOrBlank(gameName, "Game Name"); util.throwExceptionIfNullOrBlank(gameUserName, "User Name"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"game"=> { "name" => gameName,"scores" => { "score" => { "value" => gameScore, "userName" => gameUserName }}}}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util., } query_params = params.clone query_params = params.clone params.store("body", body) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/deduct" response = connection.post(signature, resource_url, query_params,body) puts "Response is #{response}" game = GameResponseBuilder.new() scoreObj = game.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return scoreObj end |