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
data/lib/game/Game.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'App42_Ruby_API/App42Response'
|
6
|
+
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# This Game object is the value object which contains the properties of Game.
|
10
|
+
#
|
11
|
+
#
|
12
|
+
|
13
|
+
module App42
|
14
|
+
module Game
|
15
|
+
class Game < App42Response
|
16
|
+
attr_accessor :name, :scoreList
|
17
|
+
|
18
|
+
@name
|
19
|
+
@scoreList = Array.new
|
20
|
+
end
|
21
|
+
|
22
|
+
class Score
|
23
|
+
attr_accessor :userName, :rank, :value, :createdOn
|
24
|
+
|
25
|
+
@userName
|
26
|
+
@rank
|
27
|
+
@value
|
28
|
+
@createdOn
|
29
|
+
|
30
|
+
#
|
31
|
+
# This is a constructor that takes no parameter
|
32
|
+
#
|
33
|
+
def initialize(game)
|
34
|
+
game.scoreList.push(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'json/pure'
|
6
|
+
require 'App42_Ruby_API/App42ResponseBuilder'
|
7
|
+
require 'game/Game'
|
8
|
+
|
9
|
+
module App42
|
10
|
+
module Game
|
11
|
+
#
|
12
|
+
#
|
13
|
+
# GameResponseBuilder class converts the JSON response retrieved from the
|
14
|
+
# server to the value object i.e Game
|
15
|
+
#
|
16
|
+
#
|
17
|
+
class GameResponseBuilder < App42ResponseBuilder
|
18
|
+
#
|
19
|
+
# Converts the response in JSON format to the value object i.e Game
|
20
|
+
#
|
21
|
+
# @param json
|
22
|
+
# - response in JSON format
|
23
|
+
#
|
24
|
+
# @return Game object filled with json data
|
25
|
+
#
|
26
|
+
#
|
27
|
+
def buildResponse(json)
|
28
|
+
gamesJSONObj = getServiceJSONObject("games", json)
|
29
|
+
gameJSONObj = gamesJSONObj["game"]
|
30
|
+
game = buildGameObject(gameJSONObj);
|
31
|
+
game.isResponseSuccess = isResponseSuccess(json)
|
32
|
+
game.strResponse=json
|
33
|
+
return game
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Converts the response in JSON format to the list of value objects i.e
|
38
|
+
# Game
|
39
|
+
#
|
40
|
+
# @param json
|
41
|
+
# - response in JSON format
|
42
|
+
#
|
43
|
+
# @return List of Game object filled with json data
|
44
|
+
#
|
45
|
+
#
|
46
|
+
|
47
|
+
def buildArrayResponse(json)
|
48
|
+
gamesJSONObj = getServiceJSONObject("games", json)
|
49
|
+
gameList = Array.new
|
50
|
+
|
51
|
+
if gamesJSONObj["game"].instance_of?(Array)
|
52
|
+
gameJSONArray = gamesJSONObj["game"]
|
53
|
+
gameJSONArray.length.times do |i|
|
54
|
+
gameJSONObj = gameJSONArray[i]
|
55
|
+
game = buildGameObject(gameJSONObj);
|
56
|
+
game.isResponseSuccess = isResponseSuccess(json)
|
57
|
+
game.strResponse=json
|
58
|
+
gameList.push(game)
|
59
|
+
end
|
60
|
+
else
|
61
|
+
gameJSONObject = gamesJSONObj["game"]
|
62
|
+
game = buildGameObject(gameJSONObject);
|
63
|
+
game.isResponseSuccess = isResponseSuccess(json)
|
64
|
+
game.strResponse=json
|
65
|
+
gameList.push(game)
|
66
|
+
end
|
67
|
+
return gameList
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Converts the Game JSON object to the value object i.e Game
|
72
|
+
#
|
73
|
+
# @param gameJSONObject
|
74
|
+
# - Game data as JSONObject
|
75
|
+
#
|
76
|
+
# @return Game object filled with json data
|
77
|
+
#
|
78
|
+
|
79
|
+
def buildGameObject(gameJSONObject)
|
80
|
+
game = Game.new()
|
81
|
+
scoreList = Array.new
|
82
|
+
game.scoreList=(scoreList)
|
83
|
+
buildObjectFromJSONTree(game, gameJSONObject);
|
84
|
+
|
85
|
+
if gameJSONObject.key?("scores") && gameJSONObject.fetch("scores").key?("score")
|
86
|
+
if gameJSONObject.fetch("scores").fetch("score").instance_of?(Hash)
|
87
|
+
scoreJSONObj = gameJSONObject.fetch("scores").fetch("score");
|
88
|
+
score = App42::Game::Score.new(game)
|
89
|
+
|
90
|
+
buildObjectFromJSONTree(score, scoreJSONObj);
|
91
|
+
else
|
92
|
+
scoreJSONArray= gameJSONObject.fetch("scores").fetch("score");
|
93
|
+
scoreJSONArray.length.times do |i|
|
94
|
+
scoreJSONObj = scoreJSONArray[i]
|
95
|
+
score = App42::Game::Score.new(game)
|
96
|
+
|
97
|
+
buildObjectFromJSONTree(score, scoreJSONObj);
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
return game
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,268 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'connection/RESTConnection'
|
7
|
+
require 'util/util'
|
8
|
+
require 'json/pure'
|
9
|
+
require 'App42_Ruby_API/App42Response'
|
10
|
+
require 'game/GameResponseBuilder'
|
11
|
+
require 'game/Game'
|
12
|
+
|
13
|
+
module App42
|
14
|
+
module Game
|
15
|
+
#
|
16
|
+
# The Game service allows Game, User, Score and ScoreBoard Management on the Cloud.
|
17
|
+
# The service allows Game Developer to create a Game and then do in Game Scoring using the
|
18
|
+
# Score service. It also allows to maintain a Scoreboard across game sessions using the ScoreBoard
|
19
|
+
# service. One can query for average or highest score for user for a Game and highest and average score across users
|
20
|
+
# for a Game. It also gives ranking of the user against other users for a particular game.
|
21
|
+
# The Reward and RewardPoints allows the Game Developer to assign rewards to a user and redeem the rewards.
|
22
|
+
#
|
23
|
+
# E.g. One can give Swords or Energy etc.
|
24
|
+
# The services Game, Score, ScoreBoard, Reward, RewardPoints can be used in Conjunction for complete Game Scoring and Reward
|
25
|
+
# Management.
|
26
|
+
#
|
27
|
+
# @see Reward, RewardPoint, Score, ScoreBoard
|
28
|
+
#
|
29
|
+
class GameService
|
30
|
+
#
|
31
|
+
# this is a constructor that takes
|
32
|
+
#
|
33
|
+
# @param apiKey
|
34
|
+
# @param secretKey
|
35
|
+
# @param baseURL
|
36
|
+
#
|
37
|
+
def initialize(api_key, secret_key, base_url)
|
38
|
+
puts "Game->initialize"
|
39
|
+
@api_key = api_key
|
40
|
+
@secret_key = secret_key
|
41
|
+
@base_url = base_url
|
42
|
+
@resource = "game"
|
43
|
+
@version = "1.0"
|
44
|
+
end
|
45
|
+
|
46
|
+
# Creates game on the cloud
|
47
|
+
#
|
48
|
+
# @param gameName
|
49
|
+
# - Name of the game that has to be created
|
50
|
+
# @param gameDescription
|
51
|
+
# - Description of the game to be created
|
52
|
+
#
|
53
|
+
# @return Game object containing the game which has been created
|
54
|
+
#
|
55
|
+
# @raise App42Exception
|
56
|
+
#
|
57
|
+
|
58
|
+
def create_game(gameName, gameDescription)
|
59
|
+
puts "Create Game Called "
|
60
|
+
puts "Base url #{@base_url}"
|
61
|
+
response = nil;
|
62
|
+
gameObj = nil;
|
63
|
+
gameObj = Game.new
|
64
|
+
util = Util.new
|
65
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
66
|
+
util.throwExceptionIfNullOrBlank(gameDescription, "Game Description");
|
67
|
+
begin
|
68
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
69
|
+
body = {'app42' => {"game"=> {
|
70
|
+
"name" => gameName,
|
71
|
+
"description" => gameDescription
|
72
|
+
}}}.to_json
|
73
|
+
puts "Body #{body}"
|
74
|
+
query_params = Hash.new
|
75
|
+
params = {
|
76
|
+
'apiKey'=> @api_key,
|
77
|
+
'version' => @version,
|
78
|
+
'timeStamp' => util.get_timestamp_utc,
|
79
|
+
}
|
80
|
+
query_params = params.clone
|
81
|
+
params.store("body", body)
|
82
|
+
puts query_params
|
83
|
+
signature = util.sign(@secret_key, params)
|
84
|
+
resource_url = "#{@version}/#{@resource}"
|
85
|
+
response = connection.post(signature, resource_url, query_params, body)
|
86
|
+
puts "Response is #{response}"
|
87
|
+
game = GameResponseBuilder.new()
|
88
|
+
gameObj = game.buildResponse(response)
|
89
|
+
rescue App42Exception =>e
|
90
|
+
raise e
|
91
|
+
rescue Exception => e
|
92
|
+
raise App42Exception.new(e)
|
93
|
+
end
|
94
|
+
return gameObj
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Fetches all games for the App
|
99
|
+
#
|
100
|
+
# @return ArrayList of Game object containing all the games for the App
|
101
|
+
#
|
102
|
+
# @raise App42Exception
|
103
|
+
#
|
104
|
+
|
105
|
+
def get_all_games()
|
106
|
+
puts "Get All Games Called "
|
107
|
+
puts "Base url #{@base_url}"
|
108
|
+
response = nil;
|
109
|
+
gameList = nil;
|
110
|
+
gameList = Array.new
|
111
|
+
util = Util.new
|
112
|
+
begin
|
113
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
114
|
+
query_params = Hash.new
|
115
|
+
params = {
|
116
|
+
'apiKey'=> @api_key,
|
117
|
+
'version' => @version,
|
118
|
+
'timeStamp' => util.get_timestamp_utc,
|
119
|
+
}
|
120
|
+
query_params = params.clone
|
121
|
+
signature = util.sign(@secret_key, params)
|
122
|
+
resource_url = "#{@version}/#{@resource}"
|
123
|
+
response = connection.get(signature, resource_url, query_params)
|
124
|
+
puts "Response is #{response}"
|
125
|
+
game = GameResponseBuilder.new
|
126
|
+
gameList = game.buildArrayResponse(response)
|
127
|
+
rescue App42Exception =>e
|
128
|
+
raise e
|
129
|
+
rescue Exception => e
|
130
|
+
raise App42Exception.new(e)
|
131
|
+
end
|
132
|
+
return gameList
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
# Fetches all games for the App by paging. * @param max Maximum number of
|
137
|
+
# records to be fetched
|
138
|
+
#
|
139
|
+
# @param offset
|
140
|
+
# - From where the records are to be fetched
|
141
|
+
#
|
142
|
+
# @return ArrayList of Game object containing all the games for the App
|
143
|
+
#
|
144
|
+
# @raise App42Exception
|
145
|
+
#
|
146
|
+
|
147
|
+
def get_all_games_by_paging(max, offset)
|
148
|
+
puts "get_all_games_by_paging Called "
|
149
|
+
puts "Base url #{@base_url}"
|
150
|
+
response = nil;
|
151
|
+
gameList = nil;
|
152
|
+
gameList = Array.new
|
153
|
+
util = Util.new
|
154
|
+
util.validateMax(max);
|
155
|
+
util.throwExceptionIfNullOrBlank(max, "Max");
|
156
|
+
util.throwExceptionIfNullOrBlank(offset, "Offset");
|
157
|
+
begin
|
158
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
159
|
+
query_params = Hash.new
|
160
|
+
params = {
|
161
|
+
'apiKey'=> @api_key,
|
162
|
+
'version' => @version,
|
163
|
+
'timeStamp' => util.get_timestamp_utc,
|
164
|
+
}
|
165
|
+
query_params = params.clone
|
166
|
+
params.store("max", "" + (max.to_i).to_s)
|
167
|
+
params.store("offset", "" + (offset.to_i).to_s)
|
168
|
+
signature = util.sign(@secret_key, params)
|
169
|
+
resource_url = "#{@version}/#{@resource}/paging/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
|
170
|
+
response = connection.get(signature, resource_url, query_params)
|
171
|
+
puts "Response is #{response}"
|
172
|
+
game = GameResponseBuilder.new
|
173
|
+
gameList = game.buildArrayResponse(response)
|
174
|
+
rescue App42Exception =>e
|
175
|
+
raise e
|
176
|
+
rescue Exception => e
|
177
|
+
raise App42Exception.new(e)
|
178
|
+
end
|
179
|
+
return gameList
|
180
|
+
end
|
181
|
+
|
182
|
+
#
|
183
|
+
# Retrieves the game by the specified name
|
184
|
+
#
|
185
|
+
# @param gameName
|
186
|
+
# - Name of the game that has to be fetched
|
187
|
+
#
|
188
|
+
# @return Game object containing the game which has been created
|
189
|
+
#
|
190
|
+
# @raise App42Exception
|
191
|
+
#
|
192
|
+
|
193
|
+
def get_game_by_name(gameName)
|
194
|
+
puts "Get Games By Name Called "
|
195
|
+
puts "Base url #{@base_url}"
|
196
|
+
response = nil;
|
197
|
+
gameObj = nil;
|
198
|
+
gameObj = Game.new
|
199
|
+
util = Util.new
|
200
|
+
util.throwExceptionIfNullOrBlank(gameName, "Game Name");
|
201
|
+
begin
|
202
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
203
|
+
query_params = Hash.new
|
204
|
+
params = {
|
205
|
+
'apiKey'=> @api_key,
|
206
|
+
'version' => @version,
|
207
|
+
'timeStamp' => util.get_timestamp_utc,
|
208
|
+
}
|
209
|
+
query_params = params.clone
|
210
|
+
puts params
|
211
|
+
params.store("name", gameName)
|
212
|
+
puts query_params
|
213
|
+
signature = util.sign(@secret_key, params)
|
214
|
+
resource_url = "#{@version}/#{@resource}/#{gameName}"
|
215
|
+
response = connection.get(signature, resource_url, query_params)
|
216
|
+
puts "Response is #{response}"
|
217
|
+
game = GameResponseBuilder.new()
|
218
|
+
gameObj = game.buildResponse(response)
|
219
|
+
rescue App42Exception =>e
|
220
|
+
raise e
|
221
|
+
rescue Exception => e
|
222
|
+
raise App42Exception.new(e)
|
223
|
+
end
|
224
|
+
return gameObj
|
225
|
+
end
|
226
|
+
|
227
|
+
#
|
228
|
+
# Fetches the count of all games for the App
|
229
|
+
#
|
230
|
+
# @return App42Response object containing count of all the Game for the App
|
231
|
+
#
|
232
|
+
# @raise App42Exception
|
233
|
+
#
|
234
|
+
|
235
|
+
def get_all_games_count()
|
236
|
+
puts "get_all_games_count Called "
|
237
|
+
puts "Base url #{@base_url}"
|
238
|
+
response = nil;
|
239
|
+
responseObj = App42Response.new
|
240
|
+
util = Util.new
|
241
|
+
begin
|
242
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
243
|
+
query_params = Hash.new
|
244
|
+
params = {
|
245
|
+
'apiKey'=> @api_key,
|
246
|
+
'version' => @version,
|
247
|
+
'timeStamp' => util.get_timestamp_utc,
|
248
|
+
}
|
249
|
+
query_params = params.clone
|
250
|
+
puts query_params
|
251
|
+
signature = util.sign(@secret_key, params)
|
252
|
+
resource_url = "#{@version}/#{@resource}/count"
|
253
|
+
response = connection.get(signature, resource_url, query_params)
|
254
|
+
responseObj.strResponse=(response)
|
255
|
+
responseObj.isResponseSuccess=(true)
|
256
|
+
responseObj = GameResponseBuilder.new()
|
257
|
+
responseObj.getTotalRecords(response);
|
258
|
+
rescue App42Exception =>e
|
259
|
+
raise e
|
260
|
+
rescue Exception => e
|
261
|
+
raise App42Exception.new(e)
|
262
|
+
end
|
263
|
+
return responseObj
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
data/lib/game/Reward.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'App42_Ruby_API/App42Response'
|
6
|
+
|
7
|
+
#
|
8
|
+
# This Reward object is the value object which contains the properties of
|
9
|
+
# Reward along with the setter & getter for those properties.
|
10
|
+
#
|
11
|
+
|
12
|
+
module App42
|
13
|
+
module Game
|
14
|
+
class Reward < App42Response
|
15
|
+
attr_accessor :gameName, :userName, :name, :points
|
16
|
+
|
17
|
+
@gameName
|
18
|
+
@userName
|
19
|
+
@name
|
20
|
+
@points
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'json/pure'
|
6
|
+
require 'App42_Ruby_API/App42ResponseBuilder'
|
7
|
+
require 'game/Reward'
|
8
|
+
|
9
|
+
module App42
|
10
|
+
module Game
|
11
|
+
#
|
12
|
+
# RewardResponseBuilder class converts the JSON response retrieved from the
|
13
|
+
# server to the value object i.e Reward
|
14
|
+
#
|
15
|
+
class RewardResponseBuilder < App42ResponseBuilder
|
16
|
+
#
|
17
|
+
# Converts the response in JSON format to the value object i.e Reward
|
18
|
+
#
|
19
|
+
# @param json
|
20
|
+
# - response in JSON format
|
21
|
+
#
|
22
|
+
# @return Reward object filled with json data
|
23
|
+
#
|
24
|
+
#
|
25
|
+
def buildResponse(json)
|
26
|
+
rewardsJSONObj = getServiceJSONObject("rewards", json)
|
27
|
+
rewardJSONObj = rewardsJSONObj["reward"]
|
28
|
+
reward = buildRewardObject(rewardJSONObj);
|
29
|
+
reward.isResponseSuccess = isResponseSuccess(json)
|
30
|
+
reward.strResponse=json
|
31
|
+
return reward
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Converts the Reward JSON object to the value object i.e Reward
|
36
|
+
#
|
37
|
+
# @param rewardJSONObj
|
38
|
+
# - Reward data as JSONObject
|
39
|
+
#
|
40
|
+
# @return Reward object filled with json data
|
41
|
+
#
|
42
|
+
#
|
43
|
+
|
44
|
+
def buildRewardObject(rewardJSONObj)
|
45
|
+
reward = Reward.new()
|
46
|
+
buildObjectFromJSONTree(reward, rewardJSONObj);
|
47
|
+
return reward
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Converts the response in JSON format to the list of value objects i.e
|
52
|
+
# Reward
|
53
|
+
#
|
54
|
+
# @param json
|
55
|
+
# - response in JSON format
|
56
|
+
#
|
57
|
+
# @return List of Reward object filled with json data
|
58
|
+
#
|
59
|
+
#
|
60
|
+
|
61
|
+
def buildArrayRewards(json)
|
62
|
+
rewardList = Array.new
|
63
|
+
rewardsJSONObj = getServiceJSONObject("rewards", json)
|
64
|
+
rewardsJSONArray = rewardsJSONObj.fetch("reward");
|
65
|
+
|
66
|
+
if rewardsJSONObj["reward"].instance_of?(Array)
|
67
|
+
rewardsJSONArray.length.times do |i|
|
68
|
+
rewardJSONObj = rewardsJSONArray[i]
|
69
|
+
reward = buildRewardObject(rewardJSONObj);
|
70
|
+
reward.isResponseSuccess = isResponseSuccess(json)
|
71
|
+
reward.strResponse=json
|
72
|
+
rewardList.push(reward);
|
73
|
+
end
|
74
|
+
else
|
75
|
+
rewardJSONObj = rewardsJSONObj["reward"]
|
76
|
+
reward = buildRewardObject(rewardJSONObj);
|
77
|
+
reward.strResponse=json
|
78
|
+
reward.isResponseSuccess = isResponseSuccess(json)
|
79
|
+
rewardList.push(reward);
|
80
|
+
end
|
81
|
+
return rewardList
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|