App42_Ruby_API 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/App42_Ruby_API.gemspec +33 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +29 -0
  7. data/Rakefile +1 -0
  8. data/TODO.rb +3 -0
  9. data/lib/App42_Ruby_API.rb +232 -0
  10. data/lib/App42_Ruby_API/App42BadParameterException.rb +31 -0
  11. data/lib/App42_Ruby_API/App42Exception.rb +39 -0
  12. data/lib/App42_Ruby_API/App42LimitException.rb +15 -0
  13. data/lib/App42_Ruby_API/App42NotFoundException.rb +15 -0
  14. data/lib/App42_Ruby_API/App42Response.rb +13 -0
  15. data/lib/App42_Ruby_API/App42ResponseBuilder.rb +67 -0
  16. data/lib/App42_Ruby_API/App42SecurityException.rb +15 -0
  17. data/lib/App42_Ruby_API/version.rb +3 -0
  18. data/lib/connection/RESTConnection.rb +713 -0
  19. data/lib/email/Email.rb +51 -0
  20. data/lib/email/EmailMIME.rb +51 -0
  21. data/lib/email/EmailResponseBuilder.rb +76 -0
  22. data/lib/email/EmailService.rb +244 -0
  23. data/lib/gallery/Album.rb +56 -0
  24. data/lib/gallery/AlbumResponseBuilder.rb +168 -0
  25. data/lib/gallery/AlbumService.rb +337 -0
  26. data/lib/gallery/PhotoService.rb +591 -0
  27. data/lib/game/Game.rb +39 -0
  28. data/lib/game/GameResponseBuilder.rb +106 -0
  29. data/lib/game/GameService.rb +268 -0
  30. data/lib/game/Reward.rb +24 -0
  31. data/lib/game/RewardResponseBuilder.rb +85 -0
  32. data/lib/game/RewardService.rb +440 -0
  33. data/lib/game/ScoreBoardService.rb +433 -0
  34. data/lib/game/ScoreService.rb +157 -0
  35. data/lib/geo/Geo.rb +51 -0
  36. data/lib/geo/GeoPoint.rb +43 -0
  37. data/lib/geo/GeoResponseBuilder.rb +145 -0
  38. data/lib/geo/GeoService.rb +505 -0
  39. data/lib/imageProcessor/Image.rb +42 -0
  40. data/lib/imageProcessor/ImageProcessorResponseBuilder.rb +40 -0
  41. data/lib/imageProcessor/ImageProcessorService.rb +1054 -0
  42. data/lib/log/Log.rb +49 -0
  43. data/lib/log/LogResponseBuilder.rb +61 -0
  44. data/lib/log/LogService.rb +920 -0
  45. data/lib/message/Queue.rb +50 -0
  46. data/lib/message/QueueResponseBuilder.rb +64 -0
  47. data/lib/message/QueueService.rb +469 -0
  48. data/lib/push/DeviceType.rb +56 -0
  49. data/lib/push/PushNotification.rb +38 -0
  50. data/lib/push/PushNotificationResposneBuilder.rb +74 -0
  51. data/lib/push/PushNotificationService.rb +458 -0
  52. data/lib/recommend/PreferenceData.rb +25 -0
  53. data/lib/recommend/Recommender.rb +48 -0
  54. data/lib/recommend/RecommenderResponseBuilder.rb +70 -0
  55. data/lib/recommend/RecommenderService.rb +1092 -0
  56. data/lib/recommend/RecommenderSimilarity.rb +52 -0
  57. data/lib/review/Review.rb +38 -0
  58. data/lib/review/ReviewResponseBuilder.rb +76 -0
  59. data/lib/review/ReviewService.rb +590 -0
  60. data/lib/session/Session.rb +43 -0
  61. data/lib/session/SessionResponseBuilder.rb +70 -0
  62. data/lib/session/SessionService.rb +427 -0
  63. data/lib/shopping/Cart.rb +77 -0
  64. data/lib/shopping/CartResponseBuilder.rb +118 -0
  65. data/lib/shopping/CartService.rb +902 -0
  66. data/lib/shopping/Catalogue.rb +79 -0
  67. data/lib/shopping/CatalogueResponseBuilder.rb +170 -0
  68. data/lib/shopping/CatalogueService.rb +649 -0
  69. data/lib/shopping/ItemData.rb +29 -0
  70. data/lib/shopping/PaymentStatus.rb +60 -0
  71. data/lib/social/Social.rb +35 -0
  72. data/lib/social/SocialResponseBuilder.rb +38 -0
  73. data/lib/social/SocialService.rb +585 -0
  74. data/lib/storage/OrderByType.rb +29 -0
  75. data/lib/storage/Query.rb +39 -0
  76. data/lib/storage/QueryBuilder.rb +118 -0
  77. data/lib/storage/Storage.rb +45 -0
  78. data/lib/storage/StorageResponseBuilder.rb +86 -0
  79. data/lib/storage/StorageService.rb +775 -0
  80. data/lib/upload/Upload.rb +40 -0
  81. data/lib/upload/UploadFileType.rb +83 -0
  82. data/lib/upload/UploadResponseBuilder.rb +58 -0
  83. data/lib/upload/UploadService.rb +960 -0
  84. data/lib/user/User.rb +102 -0
  85. data/lib/user/UserResponseBuilder.rb +105 -0
  86. data/lib/user/UserService.rb +1209 -0
  87. data/lib/util/util.rb +244 -0
  88. data/question.rb +79 -0
  89. metadata +204 -0
@@ -0,0 +1,168 @@
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 'gallery/Album'
8
+
9
+ module App42
10
+ module Gallery
11
+ #
12
+ #
13
+ # AlbumResponseBuilder class converts the JSON response retrieved from the
14
+ # server to the value object i.e Album
15
+ #
16
+ #
17
+ class AlbumResponseBuilder < App42ResponseBuilder
18
+ #
19
+ # Converts the response in JSON format to the value object i.e Album
20
+ #
21
+ # @param json
22
+ # - response in JSON format
23
+ #
24
+ # @return Album object filled with json data
25
+ #
26
+ #
27
+ def buildResponse(json)
28
+ albumsJSONObj = getServiceJSONObject("albums", json)
29
+ albumJSONObj = albumsJSONObj.fetch("album")
30
+ albumObj = App42::Gallery::Album.new()
31
+
32
+ photoList = Array.new
33
+ albumObj.photoList = photoList
34
+
35
+ albumObj.strResponse=json
36
+ albumObj.isResponseSuccess= isResponseSuccess(json)
37
+ buildObjectFromJSONTree(albumObj, albumJSONObj);
38
+
39
+ if albumJSONObj.key?("photos") == false
40
+ return albumObj
41
+ end
42
+
43
+ if albumJSONObj.fetch("photos").key?("photo") == false
44
+ return albumObj
45
+ end
46
+
47
+ if albumJSONObj.fetch("photos").fetch("photo").instance_of?(Hash)
48
+ #Single Entry
49
+ photoObj = App42::Gallery::Photo.new(albumObj)
50
+ buildObjectFromJSONTree(photoObj, albumJSONObj.fetch("photos").fetch("photo"));
51
+ photoObj = setTagList(photoObj, albumJSONObj.fetch("photos").fetch("photo"));
52
+ else
53
+ # Multiple Entry
54
+ photoJSONArray = albumJSONObj.fetch("photos").fetch("photo");
55
+
56
+ photoJSONArray.length.times do |i|
57
+ photoJSONObj = photoJSONArray[i]
58
+ photoObj = App42::Gallery::Photo.new(albumObj)
59
+ buildObjectFromJSONTree(photoObj, photoJSONObj);
60
+ photoObj = setTagList(photoObj, photoJSONObj);
61
+ end
62
+ end
63
+ return albumObj
64
+ end
65
+
66
+ #
67
+ # Converts the Album JSON object to the value object i.e Album
68
+ #
69
+ # @param albumsJSONObj
70
+ # - Album data as JSONObject
71
+ #
72
+ # @return Album object filled with json data
73
+ #
74
+ #
75
+ def buildAlbumObject(albumsJSONObj)
76
+ albumObj = App42::Gallery::Album.new
77
+ buildObjectFromJSONTree(albumObj, albumsJSONObj);
78
+
79
+ photoList = Array.new
80
+ albumObj.photoList = photoList
81
+
82
+ if albumsJSONObj.key?("photos") && albumsJSONObj.fetch("photos").key?("photo")
83
+ if albumsJSONObj.fetch("photos").fetch("photo").instance_of?(Hash)
84
+ photoJsonObj = albumsJSONObj.fetch("photos").fetch("photo");
85
+
86
+ # Single Entry
87
+ photoObj = App42::Gallery::Photo.new(albumObj)
88
+ buildObjectFromJSONTree(photoObj, albumsJSONObj.fetch("photos").fetch("photo"));
89
+ photoObj = setTagList(photoObj, photoJsonObj);
90
+ else
91
+
92
+ # Multiple Entry
93
+ photoJSONArray = albumsJSONObj.fetch("photos").fetch("photo")
94
+
95
+ photoJSONArray.length.times do |j|
96
+ photoJSONObj = photoJSONArray[j]
97
+ photoObj = App42::Gallery::Photo.new(albumObj)
98
+ buildObjectFromJSONTree(photoObj, photoJSONObj);
99
+ photoObj = setTagList(photoObj, photoJSONObj);
100
+ end
101
+ end
102
+ end
103
+ return albumObj;
104
+ end
105
+
106
+ #
107
+ # Converts the response in JSON format to the list of value objects i.e
108
+ # Album
109
+ #
110
+ # @param json
111
+ # - response in JSON format
112
+ #
113
+ #@return List of Album object filled with json data
114
+ #
115
+
116
+ def buildArrayResponse(json)
117
+ albumsJSONObj = getServiceJSONObject("albums", json)
118
+ albumList = Array.new
119
+
120
+ if albumsJSONObj.fetch("album").instance_of?(Array)
121
+ albumJSONArray = albumsJSONObj.fetch("album");
122
+ albumJSONArray.length.times do |i|
123
+ albumJSONObj = albumJSONArray[i]
124
+ album = buildAlbumObject(albumJSONObj);
125
+ album.strResponse=json
126
+ album.isResponseSuccess= (isResponseSuccess(json))
127
+ albumList.push(album)
128
+ end
129
+ else
130
+ albumJSONObject = albumsJSONObj.fetch("album");
131
+ album = buildAlbumObject(albumJSONObject);
132
+ album.strResponse=json
133
+ album.isResponseSuccess= (isResponseSuccess(json))
134
+ albumList.push(album)
135
+ end
136
+ return albumList
137
+ end
138
+
139
+ #
140
+ # set tags to the list
141
+ #
142
+ # @param photoObj
143
+ # @param photoJsonObj
144
+ #
145
+ # @return photo object
146
+ #
147
+ # @raise Exception
148
+ #
149
+
150
+ def setTagList(photoObj, photoJsonObj)
151
+ if photoJsonObj.key?("tags")
152
+ tagList = Array.new
153
+ if photoJsonObj.fetch("tags").instance_of?(Array)
154
+ tagArr = photoJsonObj.fetch("tags");
155
+ tagArr.length.times do |i|
156
+ tagList.push(tagArr.fetch(i));
157
+ end
158
+ else
159
+ tagList.push(photoJsonObj.fetch("tags"));
160
+ end
161
+ photoObj.tagList = (tagList);
162
+ end
163
+ return photoObj;
164
+ end
165
+
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,337 @@
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
+ # Create Photo Gallery on the cloud. This service allows to manage i.e. create,
17
+ # retrieve and remove albums on the cloud. Its useful for Mobile/Device App and Web App developer
18
+ # who want Photo Gallery functionality. It gives them a complete Photo Gallery out of the
19
+ # box and reduces the footprint on the device. Developers can focus on how the Photo Gallery
20
+ # will be rendered and this Cloud API will manage the Gallery on the cloud thereby reducing development
21
+ # time.
22
+ #
23
+ # @see Album
24
+ # @see Photo
25
+ #
26
+ class AlbumService
27
+ #
28
+ # this is a constructor that takes
29
+ #
30
+ # @param apiKey
31
+ # @param secretKey
32
+ # @param baseURL
33
+ #
34
+ def initialize(api_key, secret_key, base_url)
35
+ puts "Photo Gallery->initialize"
36
+ @api_key = api_key
37
+ @secret_key = secret_key
38
+ @base_url = base_url
39
+ @resource = "gallery"
40
+ @version = "1.0"
41
+ end
42
+
43
+ #
44
+ # Creates Album on the cloud
45
+ #
46
+ # @param userName
47
+ # - The user to which the album belongs
48
+ # @param albumName
49
+ # - Name of the album to be created on the cloud
50
+ # @param albumDescription
51
+ # - Description of the album to be created
52
+ #
53
+ # @return Album object containing the album which has been created
54
+ #
55
+ # @raise App42Exception
56
+ #
57
+
58
+ def create_album(userName, albumName, albumDescription)
59
+ puts "Create Album Called "
60
+ puts "Base url #{@base_url}"
61
+ response = nil;
62
+ albumObj = nil;
63
+ albumObj = Album.new
64
+ util = Util.new
65
+ util.throwExceptionIfNullOrBlank(userName, "User Name");
66
+ util.throwExceptionIfNullOrBlank(albumName, "Album Name");
67
+ util.throwExceptionIfNullOrBlank(albumDescription, "Description");
68
+ begin
69
+ connection = App42::Connection::RESTConnection.new(@base_url)
70
+ body = {'app42' => {"album"=> {
71
+ "name" => albumName,
72
+ "description" => albumDescription
73
+ }}}.to_json
74
+ puts "Body #{body}"
75
+ query_params = Hash.new
76
+ params = {
77
+ 'apiKey'=> @api_key,
78
+ 'version' => @version,
79
+ 'timeStamp' => util.get_timestamp_utc,
80
+ }
81
+ query_params = params.clone
82
+ params.store("body", body)
83
+ puts query_params
84
+ signature = util.sign(@secret_key, params)
85
+ resource_url = "#{@version}/#{@resource}/album/#{userName}"
86
+ response = connection.post(signature, resource_url, query_params, body)
87
+ puts "Response is #{response}"
88
+ album = AlbumResponseBuilder.new()
89
+ albumObj = album.buildResponse(response)
90
+ rescue App42Exception =>e
91
+ raise e
92
+ rescue Exception => e
93
+ raise App42Exception.new(e)
94
+ end
95
+ return albumObj
96
+ end
97
+
98
+ #
99
+ # Fetches all the Albums based on the userName
100
+ #
101
+ # @param userName
102
+ # - The user for which the albums have to be fetched
103
+ #
104
+ # @return Album object containing all the album for the given userName
105
+ #
106
+ # @raise App42Exception
107
+ #
108
+
109
+ def get_albums(userName)
110
+ puts "Get Albums Called "
111
+ puts "Base url #{@base_url}"
112
+ response = nil;
113
+ albumList = nil;
114
+ albumList = Array.new
115
+ util = Util.new
116
+ util.throwExceptionIfNullOrBlank(userName, "User Name");
117
+ begin
118
+ connection = App42::Connection::RESTConnection.new(@base_url)
119
+ params = Hash.new
120
+ query_params = Hash.new
121
+ params = {
122
+ 'apiKey'=> @api_key,
123
+ 'version' => @version,
124
+ 'timeStamp' => util.get_timestamp_utc,
125
+ }
126
+ query_params = params.clone
127
+ params.store("userName", userName)
128
+ puts query_params
129
+ signature = util.sign(@secret_key, params)
130
+ resource_url = "#{@version}/#{@resource}/album/#{userName}"
131
+ response = connection.get(signature, resource_url, query_params)
132
+ album = AlbumResponseBuilder.new()
133
+ albumObj = album.buildArrayResponse(response)
134
+ rescue App42Exception =>e
135
+ raise e
136
+ rescue Exception => e
137
+ raise App42Exception.new(e)
138
+ end
139
+ return albumObj
140
+ end
141
+
142
+ #
143
+ # Fetches all the Albums based on the userName by Paging.
144
+ #
145
+ # @param userName
146
+ # - The user for which the albums have to be fetched
147
+ # @param max
148
+ # - Maximum number of records to be fetched
149
+ # @param offset
150
+ # - From where the records are to be fetched
151
+ #
152
+ # @return Album object containing all the album for the given userName
153
+ #
154
+ # @raise App42Exception
155
+ #
156
+
157
+ def get_albums_by_paging(userName, max, offset)
158
+ puts "getAlbumsByPaging Called "
159
+ puts "Base url #{@base_url}"
160
+ response = nil;
161
+ albumList = nil;
162
+ albumList = Array.new
163
+ util = Util.new
164
+ util.validateMax(max);
165
+ util.throwExceptionIfNullOrBlank(userName, "User Name");
166
+ util.throwExceptionIfNullOrBlank(max, "Max");
167
+ util.throwExceptionIfNullOrBlank(offset, "Offset");
168
+ begin
169
+ connection = App42::Connection::RESTConnection.new(@base_url)
170
+ params = Hash.new
171
+ query_params = Hash.new
172
+ params = {
173
+ 'apiKey'=> @api_key,
174
+ 'version' => @version,
175
+ 'timeStamp' => util.get_timestamp_utc,
176
+ }
177
+ query_params = params.clone
178
+ params.store("userName", userName)
179
+ params.store("max", "" + (max.to_i).to_s)
180
+ params.store("offset", "" + (offset.to_i).to_s)
181
+ puts query_params
182
+ signature = util.sign(@secret_key, params)
183
+ resource_url = "#{@version}/#{@resource}/album/#{userName}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
184
+ response = connection.get(signature, resource_url, query_params)
185
+ album = AlbumResponseBuilder.new()
186
+ albumObj = album.buildArrayResponse(response)
187
+ rescue App42Exception =>e
188
+ raise e
189
+ rescue Exception => e
190
+ raise App42Exception.new(e)
191
+ end
192
+ return albumObj
193
+ end
194
+
195
+ #
196
+ # Fetch all Album based on the userName and albumName
197
+ #
198
+ # @param userName
199
+ # - The user for which the album has to be fetched
200
+ # @param albumName
201
+ # - Name of the album that has to be fetched
202
+ #
203
+ # @return Album object containing album for the given userName and albumName
204
+ #
205
+ # @raise App42Exception
206
+ #
207
+
208
+ def get_album_by_name(userName, albumName)
209
+ puts "getAlbumByName Called "
210
+ puts "Base url #{@base_url}"
211
+ response = nil;
212
+ albumObj = nil;
213
+ albumObj = Album.new
214
+ util = Util.new
215
+ util.throwExceptionIfNullOrBlank(userName, "User Name");
216
+ util.throwExceptionIfNullOrBlank(albumName, "Album Name");
217
+ begin
218
+ connection = App42::Connection::RESTConnection.new(@base_url)
219
+ params = Hash.new
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("userName", userName)
228
+ params.store("albumName", albumName)
229
+ puts query_params
230
+ signature = util.sign(@secret_key, params)
231
+ resource_url = "#{@version}/#{@resource}/album/#{userName}/#{albumName}"
232
+ response = connection.get(signature, resource_url, query_params)
233
+ puts "Response is #{response}"
234
+ album = AlbumResponseBuilder.new()
235
+ albumObj = album.buildResponse(response)
236
+ rescue App42Exception =>e
237
+ raise e
238
+ rescue Exception => e
239
+ raise App42Exception.new(e)
240
+ end
241
+ return albumObj
242
+ end
243
+
244
+ #
245
+ # Removes the album based on the userName and albumName. Note: All photos added to this Album will also be removed
246
+ #
247
+ # @param userName
248
+ # - The user for which the album has to be removed
249
+ # @param albumName
250
+ # - Name of the album that has to be removed
251
+ #
252
+ # @return App42Response if removed successfully
253
+ #
254
+ # @raise App42Exception
255
+ #
256
+
257
+ def remove_album(userName, albumName)
258
+ puts "Delete Album Called "
259
+ puts "Base url #{@base_url}"
260
+ response = nil;
261
+ responseObj = App42Response.new();
262
+ util = Util.new
263
+ util.throwExceptionIfNullOrBlank(userName, "User Name");
264
+ util.throwExceptionIfNullOrBlank(albumName, "Album Name");
265
+ begin
266
+ connection = App42::Connection::RESTConnection.new(@base_url)
267
+ params = Hash.new
268
+ query_params = Hash.new
269
+ params = {
270
+ 'apiKey'=> @api_key,
271
+ 'version' => @version,
272
+ 'timeStamp' => util.get_timestamp_utc,
273
+ }
274
+ query_params = params.clone
275
+ params.store("userName", userName)
276
+ params.store("albumName", albumName)
277
+ puts query_params
278
+ signature = util.sign(@secret_key, params)
279
+ resource_url = "#{@version}/#{@resource}/#{userName}/#{albumName}"
280
+ response = connection.delete(signature, resource_url, query_params)
281
+ responseObj.strResponse=(response)
282
+ responseObj.isResponseSuccess=(true)
283
+ rescue App42Exception =>e
284
+ raise e
285
+ rescue Exception => e
286
+ raise App42Exception.new(e)
287
+ end
288
+ return responseObj
289
+ end
290
+
291
+ #
292
+ # Fetches the count of all the Albums based on the userName
293
+ #
294
+ # @param userName
295
+ # - The user for which the count of albums have to be fetched
296
+ #
297
+ # @return App42Response object containing the count of all the album for the given userName
298
+ #
299
+ # @raise App42Exception
300
+ #
301
+
302
+ def get_albums_count(userName)
303
+ puts "getAlbumsCount Called "
304
+ puts "Base url #{@base_url}"
305
+ response = nil;
306
+ responseObj = App42Response.new
307
+ util = Util.new
308
+ util.throwExceptionIfNullOrBlank(userName, "User Name");
309
+ begin
310
+ connection = App42::Connection::RESTConnection.new(@base_url)
311
+ query_params = Hash.new
312
+ params = {
313
+ 'apiKey'=> @api_key,
314
+ 'version' => @version,
315
+ 'timeStamp' => util.get_timestamp_utc,
316
+ }
317
+ query_params = params.clone
318
+ params.store("userName", userName);
319
+ puts query_params
320
+ signature = util.sign(@secret_key, params)
321
+ resource_url = "#{@version}/#{@resource}/album/#{userName}/count"
322
+ response = connection.get(signature, resource_url, query_params)
323
+ responseObj.strResponse=(response)
324
+ responseObj.isResponseSuccess=(true)
325
+ responseObj = AlbumResponseBuilder.new()
326
+ responseObj.getTotalRecords(response);
327
+ rescue App42Exception =>e
328
+ raise e
329
+ rescue Exception => e
330
+ raise App42Exception.new(e)
331
+ end
332
+ return responseObj
333
+ end
334
+
335
+ end
336
+ end
337
+ end