App42_Ruby_API 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,591 @@
|
|
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 'gallery/AlbumResponseBuilder'
|
11
|
+
require 'gallery/Album'
|
12
|
+
|
13
|
+
module App42
|
14
|
+
module Gallery
|
15
|
+
#
|
16
|
+
# Adds Photo to the created Album on the Cloud
|
17
|
+
# All photos for a given Album can be managed through this service. Photos can be uploaded
|
18
|
+
# to the cloud. Uploaded photos are accessible through the generated URL.
|
19
|
+
# The service also creates a thumbnail for the Photo which has been uploaded.
|
20
|
+
#
|
21
|
+
# @see Album
|
22
|
+
# @see Photo
|
23
|
+
#
|
24
|
+
class PhotoService
|
25
|
+
#
|
26
|
+
# this is a constructor that takes
|
27
|
+
#
|
28
|
+
# @param apiKey
|
29
|
+
# @param secretKey
|
30
|
+
# @param baseURL
|
31
|
+
#
|
32
|
+
def initialize(api_key, secret_key, base_url)
|
33
|
+
puts "Photo Gallery->initialize"
|
34
|
+
@api_key = api_key
|
35
|
+
@secret_key = secret_key
|
36
|
+
@base_url = base_url
|
37
|
+
@resource = "gallery"
|
38
|
+
@version = "1.0"
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Adds Photo for a particular user and album. The Photo is uploaded on the cloud
|
43
|
+
#
|
44
|
+
# @param userName
|
45
|
+
# - Name of the User whose photo has to be added
|
46
|
+
# @param albumName
|
47
|
+
# - Name of the Album in which photo has to be added
|
48
|
+
# @param photoName
|
49
|
+
# - Name of the Photo that has to be added
|
50
|
+
# @param photoDescription
|
51
|
+
# - Description of the Photo that has to be added
|
52
|
+
# @param path
|
53
|
+
# - Path from where Photo has to be picked for addition
|
54
|
+
#
|
55
|
+
# @return Album object containing the Photo which has been added
|
56
|
+
#
|
57
|
+
# @raise App42Exception
|
58
|
+
#
|
59
|
+
|
60
|
+
def add_photo(userName, albumName, photoName, photoDescription, path)
|
61
|
+
puts "Add photo called "
|
62
|
+
puts "Base url #{@base_url}"
|
63
|
+
response = nil;
|
64
|
+
photoObj = nil;
|
65
|
+
photoObj = Album.new
|
66
|
+
util = Util.new
|
67
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
68
|
+
util.throwExceptionIfNullOrBlank(albumName, "Album Name");
|
69
|
+
util.throwExceptionIfNullOrBlank(photoName, "Photo Name");
|
70
|
+
util.throwExceptionIfNullOrBlank(photoDescription, "Description");
|
71
|
+
util.throwExceptionIfNullOrBlank(path, "Path");
|
72
|
+
if (FileTest.exists?(path) == false)
|
73
|
+
raise App42Exception.new("The file with the name #{path} not found")
|
74
|
+
end
|
75
|
+
begin
|
76
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
77
|
+
params = Hash.new
|
78
|
+
query_params = Hash.new
|
79
|
+
query_params = {
|
80
|
+
'apiKey'=> @api_key,
|
81
|
+
'version' => @version,
|
82
|
+
'timeStamp' => util.get_timestamp_utc,
|
83
|
+
}
|
84
|
+
params = query_params.clone
|
85
|
+
post_params = Hash.new
|
86
|
+
post_params.store("userName", userName);
|
87
|
+
post_params.store("albumName", albumName);
|
88
|
+
post_params.store("name", photoName);
|
89
|
+
post_params.store("description", photoDescription);
|
90
|
+
params = params.merge(post_params)
|
91
|
+
signature = util.sign(@secret_key, params)
|
92
|
+
resource_url = "#{@version}/#{@resource}/#{userName}"
|
93
|
+
response = connection.photoMultipart(signature, resource_url, query_params, params, path)
|
94
|
+
puts "Response is #{response}"
|
95
|
+
album = AlbumResponseBuilder.new()
|
96
|
+
photoObj = album.buildResponse(response)
|
97
|
+
rescue App42Exception =>e
|
98
|
+
raise e
|
99
|
+
rescue Exception => e
|
100
|
+
raise App42Exception.new(e)
|
101
|
+
end
|
102
|
+
return photoObj
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# Adds Photo for a particular user and album via Stream. The Photo is uploaded on the cloud
|
107
|
+
#
|
108
|
+
# @param userName
|
109
|
+
# - Name of the User whose photo has to be added
|
110
|
+
# @param albumName
|
111
|
+
# - Name of the Album in which photo has to be added
|
112
|
+
# @param photoName
|
113
|
+
# - Name of the Photo that has to be added
|
114
|
+
# @param photoDescription
|
115
|
+
# - Description of the Photo that has to be added
|
116
|
+
# @param spath
|
117
|
+
# - Input Stream for the Photo that has to be added
|
118
|
+
#
|
119
|
+
# @return Album object containing the Photo which has been added
|
120
|
+
#
|
121
|
+
# @raise App42Exception
|
122
|
+
#
|
123
|
+
|
124
|
+
def add_photo_with_stream(userName, albumName, photoName, photoDescription, spath)
|
125
|
+
puts "Add photo with Stream called "
|
126
|
+
puts "Base url #{@base_url}"
|
127
|
+
response = nil;
|
128
|
+
photoObj = nil;
|
129
|
+
photoObj = Album.new
|
130
|
+
util = Util.new
|
131
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
132
|
+
util.throwExceptionIfNullOrBlank(albumName, "Album Name");
|
133
|
+
util.throwExceptionIfNullOrBlank(photoName, "Photo Name");
|
134
|
+
util.throwExceptionIfNullOrBlank(photoDescription, "Description");
|
135
|
+
util.throwExceptionIfNullOrBlank(spath, "Path");
|
136
|
+
if (FileTest.exists?(spath) == false)
|
137
|
+
raise App42Exception.new("The file with the name #{spath} not found")
|
138
|
+
end
|
139
|
+
begin
|
140
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
141
|
+
params = Hash.new
|
142
|
+
query_params = Hash.new
|
143
|
+
query_params = {
|
144
|
+
'apiKey'=> @api_key,
|
145
|
+
'version' => @version,
|
146
|
+
'timeStamp' => util.get_timestamp_utc,
|
147
|
+
}
|
148
|
+
params = query_params.clone
|
149
|
+
post_params = Hash.new
|
150
|
+
post_params.store("userName", userName);
|
151
|
+
post_params.store("albumName", albumName);
|
152
|
+
post_params.store("name", photoName);
|
153
|
+
post_params.store("description", photoDescription);
|
154
|
+
params = params.merge(post_params)
|
155
|
+
signature = util.sign(@secret_key, params)
|
156
|
+
resource_url = "#{@version}/#{@resource}/#{userName}"
|
157
|
+
response = connection.photoMultipartStream(signature, resource_url, query_params, params, spath)
|
158
|
+
puts "Response is #{response}"
|
159
|
+
album = AlbumResponseBuilder.new()
|
160
|
+
photoObj = album.buildResponse(response)
|
161
|
+
rescue App42Exception =>e
|
162
|
+
raise e
|
163
|
+
rescue Exception => e
|
164
|
+
raise App42Exception.new(e)
|
165
|
+
end
|
166
|
+
return photoObj
|
167
|
+
end
|
168
|
+
|
169
|
+
#
|
170
|
+
# Fetch all the Photos based on the userName
|
171
|
+
#
|
172
|
+
# @param userName
|
173
|
+
# - Name of the User whose photos have to be fetched
|
174
|
+
#
|
175
|
+
# @return ArrayList of Album object containing all the Photos for the given userName
|
176
|
+
#
|
177
|
+
# @raise App42Exception
|
178
|
+
#
|
179
|
+
|
180
|
+
def get_photos(userName)
|
181
|
+
puts "Get Photos Called "
|
182
|
+
puts "Base url #{@base_url}"
|
183
|
+
response = nil;
|
184
|
+
albumList = nil;
|
185
|
+
albumList = Array.new
|
186
|
+
util = Util.new
|
187
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
188
|
+
begin
|
189
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
190
|
+
query_params = Hash.new
|
191
|
+
params = {
|
192
|
+
'apiKey'=> @api_key,
|
193
|
+
'version' => @version,
|
194
|
+
'timeStamp' => util.get_timestamp_utc,
|
195
|
+
}
|
196
|
+
query_params = params.clone
|
197
|
+
params.store("userName", userName)
|
198
|
+
puts query_params
|
199
|
+
signature = util.sign(@secret_key, params)
|
200
|
+
resource_url = "#{@version}/#{@resource}/#{userName}"
|
201
|
+
response = connection.get(signature, resource_url, query_params)
|
202
|
+
photo = AlbumResponseBuilder.new()
|
203
|
+
albumList = photo.buildArrayResponse(response)
|
204
|
+
rescue App42Exception =>e
|
205
|
+
raise e
|
206
|
+
rescue Exception => e
|
207
|
+
raise App42Exception.new(e)
|
208
|
+
end
|
209
|
+
return albumList
|
210
|
+
end
|
211
|
+
|
212
|
+
#
|
213
|
+
# Fetch all Photos based on the userName and album name
|
214
|
+
#
|
215
|
+
# @param userName
|
216
|
+
# - Name of the User whose photos have to be fetched
|
217
|
+
# @param albumName
|
218
|
+
# - Name of the Album from which photos have to be fetched
|
219
|
+
#
|
220
|
+
# @return Album object containing all the Photos for the given userName and albumName
|
221
|
+
#
|
222
|
+
# @raise App42Exception
|
223
|
+
#
|
224
|
+
|
225
|
+
def get_photos_by_album_name(userName, albumName)
|
226
|
+
puts "Get Photos Called "
|
227
|
+
puts "Base url #{@base_url}"
|
228
|
+
response = nil;
|
229
|
+
photoObj = nil;
|
230
|
+
photoObj = Album.new
|
231
|
+
util = Util.new
|
232
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
233
|
+
util.throwExceptionIfNullOrBlank(albumName, "Album Name");
|
234
|
+
begin
|
235
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
236
|
+
query_params = Hash.new
|
237
|
+
params = {
|
238
|
+
'apiKey'=> @api_key,
|
239
|
+
'version' => @version,
|
240
|
+
'timeStamp' => util.get_timestamp_utc,
|
241
|
+
}
|
242
|
+
query_params = params.clone
|
243
|
+
params.store("userName", userName)
|
244
|
+
params.store("albumName", albumName)
|
245
|
+
puts query_params
|
246
|
+
signature = util.sign(@secret_key, params)
|
247
|
+
resource_url = "#{@version}/#{@resource}/#{userName}/#{albumName}"
|
248
|
+
response = connection.get(signature, resource_url, query_params)
|
249
|
+
puts "Response is #{response}"
|
250
|
+
photo = AlbumResponseBuilder.new()
|
251
|
+
photoObj = photo.buildResponse(response)
|
252
|
+
rescue App42Exception =>e
|
253
|
+
raise e
|
254
|
+
rescue Exception => e
|
255
|
+
raise App42Exception.new(e)
|
256
|
+
end
|
257
|
+
return photoObj
|
258
|
+
end
|
259
|
+
|
260
|
+
#
|
261
|
+
# Fetch all Photos based on the userName and album name by paging.
|
262
|
+
#
|
263
|
+
# @param userName
|
264
|
+
# - Name of the User whose photos have to be fetched
|
265
|
+
# @param albumName
|
266
|
+
# - Name of the Album from which photos have to be fetched
|
267
|
+
# @param max
|
268
|
+
# - Maximum number of records to be fetched
|
269
|
+
# @param offset
|
270
|
+
# - From where the records are to be fetched
|
271
|
+
#
|
272
|
+
# @return Album object containing all the Photos for the given userName and
|
273
|
+
# albumName
|
274
|
+
#
|
275
|
+
# @raise App42Exception
|
276
|
+
#
|
277
|
+
|
278
|
+
def get_photos_by_album_name_by_paging(userName, albumName, max, offset)
|
279
|
+
puts "getPhotosByAlbumNameByPaging Called "
|
280
|
+
puts "Base url #{@base_url}"
|
281
|
+
response = nil;
|
282
|
+
photoObj = nil;
|
283
|
+
photoObj = Album.new
|
284
|
+
util = Util.new
|
285
|
+
util.validateMax(max);
|
286
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
287
|
+
util.throwExceptionIfNullOrBlank(albumName, "Album Name");
|
288
|
+
util.throwExceptionIfNullOrBlank(max, "Max");
|
289
|
+
util.throwExceptionIfNullOrBlank(offset, "Offset");
|
290
|
+
begin
|
291
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
292
|
+
query_params = Hash.new
|
293
|
+
params = {
|
294
|
+
'apiKey'=> @api_key,
|
295
|
+
'version' => @version,
|
296
|
+
'timeStamp' => util.get_timestamp_utc,
|
297
|
+
}
|
298
|
+
query_params = params.clone
|
299
|
+
params.store("userName", userName)
|
300
|
+
params.store("albumName", albumName)
|
301
|
+
params.store("max", "" + (max.to_i).to_s);
|
302
|
+
params.store("offset", "" + (offset.to_i).to_s);
|
303
|
+
puts query_params
|
304
|
+
signature = util.sign(@secret_key, params)
|
305
|
+
resource_url = "#{@version}/#{@resource}/album/#{userName}/#{albumName}/paging/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
|
306
|
+
response = connection.get(signature, resource_url, query_params)
|
307
|
+
puts "Response is #{response}"
|
308
|
+
photo = AlbumResponseBuilder.new()
|
309
|
+
photoObj = photo.buildResponse(response)
|
310
|
+
rescue App42Exception =>e
|
311
|
+
raise e
|
312
|
+
rescue Exception => e
|
313
|
+
raise App42Exception.new(e)
|
314
|
+
end
|
315
|
+
return photoObj
|
316
|
+
end
|
317
|
+
|
318
|
+
#
|
319
|
+
# Fetch the particular photo based on the userName, album name and photo name
|
320
|
+
#
|
321
|
+
# @param userName
|
322
|
+
# - Name of the User whose photo has to be fetched
|
323
|
+
# @param albumName
|
324
|
+
# - Name of the Album from which photo has to be fetched
|
325
|
+
# @param photoName
|
326
|
+
# - Name of the Photo that has to be fetched
|
327
|
+
#
|
328
|
+
# @return Album object containing the Photo for the given userName, albumName and photoName
|
329
|
+
#
|
330
|
+
# @raise App42Exception
|
331
|
+
#
|
332
|
+
|
333
|
+
def get_photos_by_album_and_photo_name(userName, albumName, photoName)
|
334
|
+
puts "Get Photos Called "
|
335
|
+
puts "Base url #{@base_url}"
|
336
|
+
response = nil;
|
337
|
+
photoObj = nil;
|
338
|
+
photoObj = Album.new
|
339
|
+
util = Util.new
|
340
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
341
|
+
util.throwExceptionIfNullOrBlank(albumName, "Album Name");
|
342
|
+
util.throwExceptionIfNullOrBlank(photoName, "Photo Name");
|
343
|
+
begin
|
344
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
345
|
+
query_params = Hash.new
|
346
|
+
params = {
|
347
|
+
'apiKey'=> @api_key,
|
348
|
+
'version' => @version,
|
349
|
+
'timeStamp' => util.get_timestamp_utc,
|
350
|
+
}
|
351
|
+
query_params = params.clone
|
352
|
+
params.store("userName", userName)
|
353
|
+
params.store("albumName", albumName)
|
354
|
+
params.store("name", photoName)
|
355
|
+
puts query_params
|
356
|
+
signature = util.sign(@secret_key, params)
|
357
|
+
resource_url = "#{@version}/#{@resource}/#{userName}/#{albumName}/#{photoName}"
|
358
|
+
response = connection.get(signature, resource_url, query_params)
|
359
|
+
puts "Response is #{response}"
|
360
|
+
photo = AlbumResponseBuilder.new()
|
361
|
+
photoObj = photo.buildResponse(response)
|
362
|
+
rescue App42Exception =>e
|
363
|
+
raise e
|
364
|
+
rescue Exception => e
|
365
|
+
raise App42Exception.new(e)
|
366
|
+
end
|
367
|
+
return photoObj
|
368
|
+
end
|
369
|
+
|
370
|
+
#
|
371
|
+
# Removes the particular Photo from the specified Album for a particular user.
|
372
|
+
# Note: The Photo is removed from the cloud and wont be accessible in future
|
373
|
+
#
|
374
|
+
# @param userName
|
375
|
+
# - Name of the User whose photo has to be removed
|
376
|
+
# @param albumName
|
377
|
+
# - Name of the Album in which photo has to be removed
|
378
|
+
# @param photoName
|
379
|
+
# - Name of the Photo that has to be removed
|
380
|
+
#
|
381
|
+
# @return App42Response if removed successfully
|
382
|
+
#
|
383
|
+
# @raise App42Exception
|
384
|
+
#
|
385
|
+
|
386
|
+
def remove_photo(userName, albumName, photoName)
|
387
|
+
puts "Delete Photo Called "
|
388
|
+
puts "Base url #{@base_url}"
|
389
|
+
response = nil;
|
390
|
+
responseObj = App42Response.new();
|
391
|
+
util = Util.new
|
392
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
393
|
+
util.throwExceptionIfNullOrBlank(albumName, "Album Name");
|
394
|
+
util.throwExceptionIfNullOrBlank(photoName, "Photo Name");
|
395
|
+
begin
|
396
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
397
|
+
query_params = Hash.new
|
398
|
+
params = {
|
399
|
+
'apiKey'=> @api_key,
|
400
|
+
'version' => @version,
|
401
|
+
'timeStamp' => util.get_timestamp_utc,
|
402
|
+
}
|
403
|
+
query_params = params.clone
|
404
|
+
params.store("userName", userName)
|
405
|
+
params.store("albumName", albumName)
|
406
|
+
params.store("name", photoName)
|
407
|
+
puts query_params
|
408
|
+
signature = util.sign(@secret_key, params)
|
409
|
+
resource_url = "#{@version}/#{@resource}/#{userName}/#{albumName}/#{photoName}"
|
410
|
+
response = connection.delete(signature, resource_url, query_params)
|
411
|
+
responseObj.strResponse=(response)
|
412
|
+
responseObj.isResponseSuccess=(true)
|
413
|
+
rescue App42Exception =>e
|
414
|
+
raise e
|
415
|
+
rescue Exception => e
|
416
|
+
raise App42Exception.new(e)
|
417
|
+
end
|
418
|
+
return responseObj
|
419
|
+
end
|
420
|
+
|
421
|
+
#
|
422
|
+
# Fetch the count of all Photos based on the userName and album name
|
423
|
+
#
|
424
|
+
# @param userName
|
425
|
+
# - Name of the User whose count of photos have to be fetched
|
426
|
+
# @param albumName
|
427
|
+
# - Name of the Album from which count of photos have to be fetched
|
428
|
+
#
|
429
|
+
# @return App42Response object containing the count of all the Photos for the given userName and
|
430
|
+
# albumName
|
431
|
+
#
|
432
|
+
# @raise App42Exception
|
433
|
+
#
|
434
|
+
|
435
|
+
def get_photos_count_by_album_name(userName, albumName)
|
436
|
+
puts "getPhotosCountByAlbumName Called "
|
437
|
+
puts "Base url #{@base_url}"
|
438
|
+
response = nil;
|
439
|
+
responseObj = App42Response.new
|
440
|
+
util = Util.new
|
441
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
442
|
+
util.throwExceptionIfNullOrBlank(albumName, "Album Name");
|
443
|
+
begin
|
444
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
445
|
+
query_params = Hash.new
|
446
|
+
params = {
|
447
|
+
'apiKey'=> @api_key,
|
448
|
+
'version' => @version,
|
449
|
+
'timeStamp' => util.get_timestamp_utc,
|
450
|
+
}
|
451
|
+
query_params = params.clone
|
452
|
+
params.store("userName", userName);
|
453
|
+
params.store("albumName", albumName);
|
454
|
+
puts query_params
|
455
|
+
signature = util.sign(@secret_key, params)
|
456
|
+
resource_url = "#{@version}/#{@resource}/#{userName}/#{albumName}/count"
|
457
|
+
response = connection.get(signature, resource_url, query_params)
|
458
|
+
responseObj.strResponse=(response)
|
459
|
+
responseObj.isResponseSuccess=(true)
|
460
|
+
responseObj = AlbumResponseBuilder.new()
|
461
|
+
responseObj.getTotalRecords(response);
|
462
|
+
rescue App42Exception =>e
|
463
|
+
raise e
|
464
|
+
rescue Exception => e
|
465
|
+
raise App42Exception.new(e)
|
466
|
+
end
|
467
|
+
return responseObj
|
468
|
+
end
|
469
|
+
|
470
|
+
#
|
471
|
+
# Adds tag to the Photo of the user in the album.
|
472
|
+
#
|
473
|
+
# @param userName
|
474
|
+
# - Name of the User whose name has to be tagged to photo
|
475
|
+
# @param albumName
|
476
|
+
# - Album name whose photo is to be tagged
|
477
|
+
# @param photoName
|
478
|
+
# - Photo name to be tagged
|
479
|
+
# @param tagList
|
480
|
+
# - list of tages in Photo
|
481
|
+
#
|
482
|
+
# @return Album object containing the Photo which has been added
|
483
|
+
#
|
484
|
+
# @raise App42Exception
|
485
|
+
#
|
486
|
+
|
487
|
+
def add_tag_to_photo(userName, albumName, photoName, tagList)
|
488
|
+
puts "addTagToPhoto called "
|
489
|
+
puts "Base url #{@base_url}"
|
490
|
+
response = nil;
|
491
|
+
photoObj = nil;
|
492
|
+
photoObj = Album.new
|
493
|
+
util = Util.new
|
494
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
495
|
+
util.throwExceptionIfNullOrBlank(albumName, "Album Name");
|
496
|
+
util.throwExceptionIfNullOrBlank(photoName, "Photo Name");
|
497
|
+
util.throwExceptionIfNullOrBlank(tagList, "TagList");
|
498
|
+
if tagList.size() == 0
|
499
|
+
raise App42Exception.new("TagList cannot be empty. Please add the name to be tagged");
|
500
|
+
end
|
501
|
+
begin
|
502
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
503
|
+
tagArray = Array.new()
|
504
|
+
for tag in tagList do
|
505
|
+
tagArray.push(tag)
|
506
|
+
end
|
507
|
+
body = {'app42' => {"photo"=> {
|
508
|
+
"userName" => userName,
|
509
|
+
"albumName" => albumName,
|
510
|
+
"photoName" => photoName, "tags" => {
|
511
|
+
"tag" => tagArray
|
512
|
+
}}}}.to_json
|
513
|
+
puts "Body #{body}"
|
514
|
+
params = Hash.new
|
515
|
+
query_params = Hash.new
|
516
|
+
query_params = {
|
517
|
+
'apiKey'=> @api_key,
|
518
|
+
'version' => @version,
|
519
|
+
'timeStamp' => util.get_timestamp_utc,
|
520
|
+
}
|
521
|
+
params = query_params.clone
|
522
|
+
post_params = Hash.new
|
523
|
+
post_params.store("body", body);
|
524
|
+
params = params.merge(post_params)
|
525
|
+
signature = util.sign(@secret_key, params)
|
526
|
+
resource_url = "#{@version}/#{@resource}/tag"
|
527
|
+
response = connection.post(signature, resource_url, query_params, body)
|
528
|
+
puts "Response is #{response}"
|
529
|
+
album = AlbumResponseBuilder.new()
|
530
|
+
photoObj = album.buildResponse(response)
|
531
|
+
rescue App42Exception =>e
|
532
|
+
raise e
|
533
|
+
rescue Exception => e
|
534
|
+
raise App42Exception.new(e)
|
535
|
+
end
|
536
|
+
return photoObj
|
537
|
+
end
|
538
|
+
|
539
|
+
#
|
540
|
+
# Fetch all the Photos based on the userName and tag
|
541
|
+
#
|
542
|
+
# @param userName
|
543
|
+
# - Name of the User whose photos have to be fetched
|
544
|
+
# @param tag
|
545
|
+
# - tag on which basis photos have to be fetched
|
546
|
+
#
|
547
|
+
# @return ArrayList of Album object containing all the Photos for the given
|
548
|
+
# userName
|
549
|
+
#
|
550
|
+
# @raise App42Exception
|
551
|
+
#
|
552
|
+
|
553
|
+
def get_tagged_photos(userName, tag)
|
554
|
+
puts "getTaggedPhoto called "
|
555
|
+
puts "Base url #{@base_url}"
|
556
|
+
response = nil;
|
557
|
+
albumList = nil;
|
558
|
+
albumList = Array.new
|
559
|
+
util = Util.new
|
560
|
+
util.throwExceptionIfNullOrBlank(userName, "User Name");
|
561
|
+
util.throwExceptionIfNullOrBlank(tag, "Tag");
|
562
|
+
begin
|
563
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
564
|
+
params = Hash.new
|
565
|
+
query_params = Hash.new
|
566
|
+
params = {
|
567
|
+
'apiKey'=> @api_key,
|
568
|
+
'version' => @version,
|
569
|
+
'timeStamp' => util.get_timestamp_utc,
|
570
|
+
}
|
571
|
+
query_params = params.clone
|
572
|
+
params.store("userName", userName);
|
573
|
+
params.store("tag", tag)
|
574
|
+
puts query_params
|
575
|
+
signature = util.sign(@secret_key, params)
|
576
|
+
resource_url = "#{@version}/#{@resource}/tag/#{tag}/userName/#{userName}"
|
577
|
+
response = connection.get(signature, resource_url, query_params)
|
578
|
+
puts "Response is #{response}"
|
579
|
+
album = AlbumResponseBuilder.new()
|
580
|
+
albumList = album.buildArrayResponse(response)
|
581
|
+
rescue App42Exception =>e
|
582
|
+
raise e
|
583
|
+
rescue Exception => e
|
584
|
+
raise App42Exception.new(e)
|
585
|
+
end
|
586
|
+
return albumList
|
587
|
+
end
|
588
|
+
|
589
|
+
end
|
590
|
+
end
|
591
|
+
end
|