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.
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,42 @@
1
+ # -----------------------------------------------------------------------
2
+ # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
3
+ # -----------------------------------------------------------------------
4
+
5
+ require 'App42_Ruby_API/App42Response'
6
+
7
+ #
8
+ #
9
+ # This Image object is the value object which contains the properties of Image.
10
+ #
11
+ #
12
+
13
+ module App42
14
+ module ImageProcessor
15
+ class Image < App42Response
16
+ attr_accessor :name, :action, :originalImage, :convertedImage, :percentage, :width, :height, :x, :y, :originalImageTinyUrl, :convertedImageTinyUrl
17
+
18
+ @name
19
+ @action
20
+ @originalImage
21
+ @convertedImage
22
+ @percentage
23
+ @width
24
+ @height
25
+ @x
26
+ @y
27
+ @convertedImageTinyUrl
28
+ @originalImageTinyUrl
29
+
30
+ #
31
+ # Returns the Image Response in JSON format.
32
+ #
33
+ # @return the response in JSON format.
34
+ #
35
+ #
36
+ def to_s
37
+ return "Name : #{@name}" + "Action : #{@action}" + "originalImage : #{@originalImage}" + "convertedImage : #{@convertedImage}" + "percentage : #{@percentage}" + "width : #{@width}" + "height : #{@height}" + "x : #{@x}" + "y : #{@y}";
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
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 'imageProcessor/Image'
8
+
9
+ module App42
10
+ module ImageProcessor
11
+
12
+ #
13
+ #
14
+ # ImageProcessResponseBuilder class converts the JSON response retrieved from
15
+ # the server to the value object i.e Image
16
+ #
17
+ #
18
+ class ImageProcessorResponseBuilder < App42ResponseBuilder
19
+
20
+ #
21
+ # Converts the response in JSON format to the value object i.e Image
22
+ #
23
+ # @param json
24
+ # - response in JSON format
25
+ #
26
+ # @return Image object filled with json data
27
+ #
28
+ #
29
+ def buildResponse(json)
30
+ imageJSONObj = getServiceJSONObject("image", json)
31
+ imageObj = Image.new
32
+ imageObj.strResponse=json
33
+ imageObj.isResponseSuccess= isResponseSuccess(json)
34
+ buildObjectFromJSONTree(imageObj, imageJSONObj);
35
+ return imageObj
36
+ end
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,1054 @@
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 'imageProcessor/ImageProcessorResponseBuilder'
11
+ require 'imageProcessor/Image'
12
+ require 'bigdecimal'
13
+
14
+ module App42
15
+ module ImageProcessor
16
+ #
17
+ # The ImageProcessor service is an Image utility service on the Cloud. Developers can
18
+ # upload files on the cloud and perform various Image Manipulation operations on the Uploaded
19
+ # Images e.g. resize, scale, thumbnail, crop etc. It is especially useful for Mobile Apps when
20
+ # they dont want to store Images locally and dont want to perform processor intensive operations.
21
+ # It is also useful for web applications who want to perform complex Image Operations
22
+ #
23
+ # @see Image
24
+ #
25
+ class ImageProcessorService
26
+ #
27
+ # this is a constructor that takes
28
+ #
29
+ # @param apiKey
30
+ # @param secretKey
31
+ # @param baseURL
32
+ #
33
+ def initialize(api_key, secret_key, base_url)
34
+ puts "Session Service->initialize"
35
+ @api_key = api_key
36
+ @secret_key = secret_key
37
+ @base_url = base_url
38
+ @resource = "image"
39
+ @version = "1.0"
40
+ end
41
+
42
+ #
43
+ # Resize image. Returns the original image url and converted image url.
44
+ # Images are stored on the cloud and can be accessed through the urls
45
+ # Resizing is done based on the width and height provided
46
+ #
47
+ # @param name
48
+ # - Name of the image to resize
49
+ # @param imagePath
50
+ # - Path of the local file to resize
51
+ # @param width
52
+ # - Width of the image to resize
53
+ # @param height
54
+ # - Height of the image to resize
55
+ #
56
+ # @return Image object containing urls for the original and converted images
57
+ #
58
+ # @raise App42Exception
59
+ #
60
+
61
+ def resize(name, imagePath, width, height)
62
+ puts "resize Called "
63
+ puts "Base url #{@base_url}"
64
+ response = nil
65
+ imageObj = nil
66
+ imageObj = Image.new()
67
+ util = Util.new
68
+ util.throwExceptionIfNullOrBlank(name, "Name");
69
+ util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
70
+ util.throwExceptionIfNullOrBlank(width, "Width");
71
+ util.throwExceptionIfNullOrBlank(height, "Height");
72
+ begin
73
+ file = File.new(imagePath,"rb")
74
+ ext = File.extname(file)
75
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
76
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
77
+ end
78
+ if File.file?(imagePath) == false
79
+ raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
80
+ end
81
+ connection = App42::Connection::RESTConnection.new(@base_url)
82
+ params = Hash.new
83
+ query_params = Hash.new
84
+ query_params = {
85
+ 'apiKey'=> @api_key,
86
+ 'version' => @version,
87
+ 'timeStamp' => util.get_timestamp_utc
88
+ }
89
+ params = query_params.clone
90
+ post_params = Hash.new
91
+ post_params.store("name", name)
92
+ post_params.store("width", width.to_s + "")
93
+ post_params.store("height", height.to_s + "")
94
+ params = params.merge(post_params)
95
+ signature = util.sign(@secret_key, params)
96
+ resource_url = "#{@version}/#{@resource}/resize"
97
+ response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
98
+ image = ImageProcessorResponseBuilder.new
99
+ imageObj = image.buildResponse(response)
100
+ rescue App42Exception =>e
101
+ raise e
102
+ rescue Exception => e
103
+ raise App42Exception.new(e)
104
+ end
105
+ return imageObj
106
+ end
107
+
108
+ #
109
+ # Resize image via Stream. Returns the original image url and converted image url.
110
+ # Images are stored on the cloud and can be accessed through the urls
111
+ # Resizing is done based on the width and height provided
112
+ #
113
+ # @param name
114
+ # - Name of the image to resize
115
+ # @param inputStream
116
+ # - InputStream of the local file to resize
117
+ # @param width
118
+ # - Width of the image to resize
119
+ # @param height
120
+ # - Height of the image to resize
121
+ #
122
+ # @return Image object containing urls for the original and converted images
123
+ #
124
+ # @raise App42Exception
125
+ #
126
+
127
+ def resize_stream(name, imagePath, width, height)
128
+ puts "resize stream Called "
129
+ puts "Base url #{@base_url}"
130
+ response = nil
131
+ imageObj = nil
132
+ imageObj = Image.new()
133
+ util = Util.new
134
+ util.throwExceptionIfNullOrBlank(name, "Name");
135
+ util.throwExceptionIfNotValidImageExtension(name, "Name");
136
+ util.throwExceptionIfNullOrBlank(width, "Width");
137
+ util.throwExceptionIfNullOrBlank(height, "Height");
138
+ begin
139
+ file = File.new(imagePath,"rb")
140
+ ext = File.extname(file)
141
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
142
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
143
+ end
144
+ if File.file?(imagePath) == false
145
+ raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
146
+ end
147
+ connection = App42::Connection::RESTConnection.new(@base_url)
148
+ query_params = Hash.new
149
+ params = {
150
+ 'apiKey'=> @api_key,
151
+ 'version' => @version,
152
+ 'timeStamp' => util.get_timestamp_utc,
153
+ }
154
+ query_params = params.clone
155
+ params.store("name", name)
156
+ params.store("width", width.to_s + "")
157
+ params.store("height", height.to_s + "")
158
+ signature = util.sign(@secret_key, params)
159
+ resource_url = "#{@version}/#{@resource}/resize"
160
+ response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
161
+ image = ImageProcessorResponseBuilder.new
162
+ imageObj = image.buildResponse(response)
163
+ rescue App42Exception =>e
164
+ raise e
165
+ rescue Exception => e
166
+ raise App42Exception.new(e)
167
+ end
168
+ return imageObj
169
+ end
170
+
171
+ #
172
+ # Creates a thumbnail of the image. There is a difference between thumbnail and resize
173
+ # The thumbnail operation is optimized for speed, it removes information of the image which is not necessary for a
174
+ # thumbnail e.g header information. Returns the original image url and converted image url.
175
+ # Images are stored on the cloud and can be accessed through the urls
176
+ # Resizing is done based on the width and height provided
177
+ #
178
+ # @param name
179
+ # - Name of the image file for which thumbnail has to be created
180
+ # @param imagePath
181
+ # - Path of the local file whose thumbnail has to be created
182
+ # @param width
183
+ # - Width of the image for thumbnail
184
+ # @param height
185
+ # - Height of the image for thumbnail
186
+ #
187
+ # @return Image object containing urls for the original and converted images
188
+ #
189
+ # @raise App42Exception
190
+ #
191
+
192
+ def thumbnail(name, imagePath, width, height)
193
+ puts "thumbnail Called "
194
+ puts "Base url #{@base_url}"
195
+ response = nil
196
+ imageObj = nil
197
+ imageObj = Image.new()
198
+ util = Util.new
199
+ util.throwExceptionIfNullOrBlank(name, "Name");
200
+ util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
201
+ util.throwExceptionIfNullOrBlank(width, "Width");
202
+ util.throwExceptionIfNullOrBlank(height, "Height");
203
+ begin
204
+ file = File.new(imagePath,"rb")
205
+ ext = File.extname(file)
206
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
207
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
208
+ end
209
+ if File.file?(imagePath) == false
210
+ raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
211
+ end
212
+ connection = App42::Connection::RESTConnection.new(@base_url)
213
+ query_params = Hash.new
214
+ params = {
215
+ 'apiKey'=> @api_key,
216
+ 'version' => @version,
217
+ 'timeStamp' => util.get_timestamp_utc,
218
+ }
219
+ query_params = params.clone
220
+ params.store("name", name)
221
+ params.store("width", width.to_s + "")
222
+ params.store("height", height.to_s + "")
223
+ signature = util.sign(@secret_key, params)
224
+ resource_url = "#{@version}/#{@resource}/thumbnail"
225
+ response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
226
+ image = ImageProcessorResponseBuilder.new
227
+ imageObj = image.buildResponse(response)
228
+ rescue App42Exception =>e
229
+ raise e
230
+ rescue Exception => e
231
+ raise App42Exception.new(e)
232
+ end
233
+ return imageObj
234
+ end
235
+
236
+ #
237
+ # Creates a thumbnail of the image via Stream. There is a difference between thumbnail and resize
238
+ # The thumbnail operation is optimized for speed, it removes information of the image which is not necessary for a
239
+ # thumbnail e.g header information. Returns the original image url and converted image url.
240
+ # Images are stored on the cloud and can be accessed through the urls
241
+ # Resizing is done based on the width and height provided
242
+ #
243
+ # @param name
244
+ # - Name of the image file for which thumbnail has to be created
245
+ # @param inputStream
246
+ # - InputStream of the local file whose thumbnail has to be created
247
+ # @param width
248
+ # - Width of the image for thumbnail
249
+ # @param height
250
+ # - Height of the image for thumbnail
251
+ #
252
+ # @return Image object containing urls for the original and converted images
253
+ #
254
+ # @raise App42Exception
255
+ #
256
+
257
+ def thumbnail_stream(name, imagePath, width, height)
258
+ puts "thumbnail Called "
259
+ puts "Base url #{@base_url}"
260
+ response = nil
261
+ imageObj = nil
262
+ imageObj = Image.new()
263
+ util = Util.new
264
+ util.throwExceptionIfNullOrBlank(name, "Name");
265
+ util.throwExceptionIfNotValidImageExtension(name, "Name");
266
+ util.throwExceptionIfNullOrBlank(width, "Width");
267
+ util.throwExceptionIfNullOrBlank(height, "Height");
268
+ begin
269
+ file = File.new(imagePath,"rb")
270
+ ext = File.extname(file)
271
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
272
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
273
+ end
274
+ if File.file?(imagePath) == false
275
+ raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
276
+ end
277
+ connection = App42::Connection::RESTConnection.new(@base_url)
278
+ query_params = Hash.new
279
+ params = {
280
+ 'apiKey'=> @api_key,
281
+ 'version' => @version,
282
+ 'timeStamp' => util.get_timestamp_utc,
283
+ }
284
+ query_params = params.clone
285
+ params.store("name", name)
286
+ params.store("width", width.to_s + "")
287
+ params.store("height", height.to_s + "")
288
+ signature = util.sign(@secret_key, params)
289
+ resource_url = "#{@version}/#{@resource}/thumbnail"
290
+ response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
291
+ image = ImageProcessorResponseBuilder.new
292
+ imageObj = image.buildResponse(response)
293
+ rescue App42Exception =>e
294
+ raise e
295
+ rescue Exception => e
296
+ raise App42Exception.new(e)
297
+ end
298
+ return imageObj
299
+ end
300
+
301
+ #
302
+ # Scales the image based on width and height. Returns the original image url and converted image url.
303
+ # Images are stored in the cloud and can be accessed through the urls
304
+ # Resizing is done based on the width and height provided
305
+ #
306
+ # @param name
307
+ # - Name of the image to scale
308
+ # @param imagePath
309
+ # - Path of the local file to scale
310
+ # @param width
311
+ # - Width of the image to scale
312
+ # @param height
313
+ # - Height of the image to scale
314
+ #
315
+ # @return Image object containing urls for the original and converted images
316
+ #
317
+ # @raise App42Exception
318
+ #
319
+
320
+ def scale(name, imagePath, width, height)
321
+ puts "scale Called "
322
+ puts "Base url #{@base_url}"
323
+ response = nil
324
+ imageObj = nil
325
+ imageObj = Image.new()
326
+ util = Util.new
327
+ util.throwExceptionIfNullOrBlank(name, "Name");
328
+ util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
329
+ util.throwExceptionIfNullOrBlank(width, "Width");
330
+ util.throwExceptionIfNullOrBlank(height, "Height");
331
+ begin
332
+ file = File.new(imagePath,"rb")
333
+ ext = File.extname(file)
334
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
335
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
336
+ end
337
+ if File.file?(imagePath) == false
338
+ raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
339
+ end
340
+ connection = App42::Connection::RESTConnection.new(@base_url)
341
+ query_params = Hash.new
342
+ params = {
343
+ 'apiKey'=> @api_key,
344
+ 'version' => @version,
345
+ 'timeStamp' => util.get_timestamp_utc,
346
+ }
347
+ query_params = params.clone
348
+ params.store("name", name)
349
+ params.store("width", (width.to_i).to_s + "")
350
+ params.store("height", (height.to_i).to_s + "")
351
+ signature = util.sign(@secret_key, params)
352
+ resource_url = "#{@version}/#{@resource}/scale"
353
+ response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
354
+ image = ImageProcessorResponseBuilder.new
355
+ imageObj = image.buildResponse(response)
356
+ rescue App42Exception =>e
357
+ raise e
358
+ rescue Exception => e
359
+ raise App42Exception.new(e)
360
+ end
361
+ return imageObj
362
+ end
363
+
364
+ #
365
+ # Scales the image based on width and height via Stream. Returns the original image url and converted image url.
366
+ # Images are stored in the cloud and can be accessed through the urls
367
+ # Resizing is done based on the width and height provided
368
+ #
369
+ # @param name
370
+ # - Name of the image to scale
371
+ # @param inputStream
372
+ # - InputStream of the local file to scale
373
+ # @param width
374
+ # - Width of the image to scale
375
+ # @param height
376
+ # - Height of the image to scale
377
+ #
378
+ # @return Image object containing urls for the original and converted images
379
+ #
380
+ # @raise App42Exception
381
+ #
382
+
383
+ def scale_stream(name, imagePath, width, height)
384
+ puts "scale Called "
385
+ puts "Base url #{@base_url}"
386
+ response = nil
387
+ imageObj = nil
388
+ imageObj = Image.new()
389
+ util = Util.new
390
+ util.throwExceptionIfNullOrBlank(name, "Name");
391
+ util.throwExceptionIfNotValidImageExtension(name, "Name");
392
+ util.throwExceptionIfNullOrBlank(width, "Width");
393
+ util.throwExceptionIfNullOrBlank(height, "Height");
394
+ begin
395
+ file = File.new(imagePath,"rb")
396
+ ext = File.extname(file)
397
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
398
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
399
+ end
400
+ if File.file?(imagePath) == false
401
+ raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
402
+ end
403
+ connection = App42::Connection::RESTConnection.new(@base_url)
404
+ query_params = Hash.new
405
+ params = {
406
+ 'apiKey'=> @api_key,
407
+ 'version' => @version,
408
+ 'timeStamp' => util.get_timestamp_utc,
409
+ }
410
+ query_params = params.clone
411
+ params.store("name", name)
412
+ params.store("width", (width.to_i).to_s + "")
413
+ params.store("height", (height.to_i).to_s + "")
414
+ signature = util.sign(@secret_key, params)
415
+ resource_url = "#{@version}/#{@resource}/scale"
416
+ response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
417
+ image = ImageProcessorResponseBuilder.new
418
+ imageObj = image.buildResponse(response)
419
+ rescue App42Exception =>e
420
+ raise e
421
+ rescue Exception => e
422
+ raise App42Exception.new(e)
423
+ end
424
+ return imageObj
425
+ end
426
+
427
+ #
428
+ # Crops image based on width, height and x, y coordinates. Returns the original image url and converted image url.
429
+ # Images are stored in the cloud and can be accessed through the urls
430
+ # Resizing is done based on the width and height provided
431
+ #
432
+ # @param name
433
+ # - Name of the image to crop
434
+ # @param imagePath
435
+ # - Path of the local file to crop
436
+ # @param width
437
+ # - Width of the image to crop
438
+ # @param height
439
+ # - Height of the image to crop
440
+ # @param x
441
+ # - Coordinate X
442
+ # @param y
443
+ # - Coordinate Y
444
+ #
445
+ # @return Image object containing urls for the original and converted images
446
+ #
447
+ # @raise App42Exception
448
+ #
449
+
450
+ def crop(name, imagePath, width, height, x, y)
451
+ puts "crop Called "
452
+ puts "Base url #{@base_url}"
453
+ response = nil
454
+ imageObj = nil
455
+ imageObj = Image.new()
456
+ util = Util.new
457
+ util.throwExceptionIfNullOrBlank(name, "Name");
458
+ util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
459
+ util.throwExceptionIfNullOrBlank(width, "Width");
460
+ util.throwExceptionIfNullOrBlank(height, "Height");
461
+ util.throwExceptionIfNullOrBlank(x, "x");
462
+ util.throwExceptionIfNullOrBlank(y, "y");
463
+ begin
464
+ file = File.new(imagePath,"rb")
465
+ ext = File.extname(file)
466
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
467
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
468
+ end
469
+ if File.file?(imagePath) == false
470
+ raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
471
+ end
472
+ connection = App42::Connection::RESTConnection.new(@base_url)
473
+ query_params = Hash.new
474
+ params = {
475
+ 'apiKey'=> @api_key,
476
+ 'version' => @version,
477
+ 'timeStamp' => util.get_timestamp_utc,
478
+ }
479
+ query_params = params.clone
480
+ params.store("name", name)
481
+ params.store("width", (width.to_i).to_s + "")
482
+ params.store("height", (height.to_i).to_s + "")
483
+ params.store("x", (x.to_i).to_s + "")
484
+ params.store("y", (y.to_i).to_s + "")
485
+ signature = util.sign(@secret_key, params)
486
+ resource_url = "#{@version}/#{@resource}/crop"
487
+ response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
488
+ image = ImageProcessorResponseBuilder.new
489
+ imageObj = image.buildResponse(response)
490
+ rescue App42Exception =>e
491
+ raise e
492
+ rescue Exception => e
493
+ raise App42Exception.new(e)
494
+ end
495
+ return imageObj
496
+ end
497
+
498
+ #
499
+ # Crops image based on width, height and x, y coordinates via Stream. Returns the original image url and converted image url.
500
+ # Images are stored in the cloud and can be accessed through the urls
501
+ # Resizing is done based on the width and height provided
502
+ #
503
+ # @param name
504
+ # - Name of the image to crop
505
+ # @param inputStream
506
+ # - InputStream of the local file to crop
507
+ # @param width
508
+ # - Width of the image to crop
509
+ # @param height
510
+ # - Height of the image to crop
511
+ # @param x
512
+ # - Coordinate X
513
+ # @param y
514
+ # - Coordinate Y
515
+ #
516
+ # @return Image object containing urls for the original and converted images
517
+ #
518
+ # @raise App42Exception
519
+ #
520
+
521
+ def crop_stream(name, imagePath, width, height, x, y)
522
+ puts "crop Called "
523
+ puts "Base url #{@base_url}"
524
+ response = nil
525
+ imageObj = nil
526
+ imageObj = Image.new()
527
+ util = Util.new
528
+ util.throwExceptionIfNullOrBlank(name, "Name");
529
+ util.throwExceptionIfNotValidImageExtension(name, "Name");
530
+ util.throwExceptionIfNullOrBlank(width, "Width");
531
+ util.throwExceptionIfNullOrBlank(height, "Height");
532
+ util.throwExceptionIfNullOrBlank(x, "x");
533
+ util.throwExceptionIfNullOrBlank(y, "y");
534
+ begin
535
+ file = File.new(imagePath,"rb")
536
+ ext = File.extname(file)
537
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
538
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
539
+ end
540
+ if File.file?(imagePath) == false
541
+ raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
542
+ end
543
+ connection = App42::Connection::RESTConnection.new(@base_url)
544
+ query_params = Hash.new
545
+ params = {
546
+ 'apiKey'=> @api_key,
547
+ 'version' => @version,
548
+ 'timeStamp' => util.get_timestamp_utc,
549
+ }
550
+ query_params = params.clone
551
+ params.store("name", name)
552
+ params.store("width", (width.to_i).to_s + "")
553
+ params.store("height", (height.to_i).to_s + "")
554
+ params.store("x", (x.to_i).to_s + "")
555
+ params.store("y", (y.to_i).to_s + "")
556
+ signature = util.sign(@secret_key, params)
557
+ resource_url = "#{@version}/#{@resource}/crop"
558
+ response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
559
+ image = ImageProcessorResponseBuilder.new
560
+ imageObj = image.buildResponse(response)
561
+ rescue App42Exception =>e
562
+ raise e
563
+ rescue Exception => e
564
+ raise App42Exception.new(e)
565
+ end
566
+ return imageObj
567
+ end
568
+
569
+ #
570
+ # Resize image by Percentage. Returns the original image url and converted image url.
571
+ # Images are stored in the cloud and can be accessed through the urls
572
+ # Resizing is done based on the width and height provided
573
+ #
574
+ # @param name
575
+ # - Name of the image to resize
576
+ # @param imagePath
577
+ # - Path of the local file to resize
578
+ # @param percentage
579
+ # - Percentage to which image has to be resized
580
+ #
581
+ # @return Image object containing urls for the original and converted images
582
+ #
583
+ # @raise App42Exception
584
+ #
585
+
586
+ def resize_by_percentage(name, imagePath, percentage)
587
+ puts "resizeByPercentage Called "
588
+ puts "Base url #{@base_url}"
589
+ response = nil
590
+ imageObj = nil
591
+ imageObj = Image.new()
592
+ util = Util.new
593
+ util.throwExceptionIfNullOrBlank(name, "Name");
594
+ util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
595
+ util.throwExceptionIfNullOrBlank(percentage, "Percentage");
596
+ begin
597
+ file = File.new(imagePath,"rb")
598
+ ext = File.extname(file)
599
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
600
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
601
+ end
602
+ if File.file?(imagePath) == false
603
+ raise App42Exception.new("File " + imagePath.to_s + " does not exist");
604
+ end
605
+ connection = App42::Connection::RESTConnection.new(@base_url)
606
+ query_params = Hash.new
607
+ params = {
608
+ 'apiKey'=> @api_key,
609
+ 'version' => @version,
610
+ 'timeStamp' => util.get_timestamp_utc,
611
+ }
612
+ query_params = params.clone
613
+ params.store("name", name)
614
+ params.store("percentage", (percentage.to_f).to_s + "")
615
+ signature = util.sign(@secret_key, params)
616
+ resource_url = "#{@version}/#{@resource}/resizePercentage"
617
+ response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
618
+ image = ImageProcessorResponseBuilder.new
619
+ imageObj = image.buildResponse(response)
620
+ rescue App42Exception =>e
621
+ raise e
622
+ rescue Exception => e
623
+ raise App42Exception.new(e)
624
+ end
625
+ return imageObj
626
+ end
627
+
628
+ #
629
+ # Resize image by Percentage via Stream. Returns the original image url and converted image url.
630
+ # Images are stored in the cloud and can be accessed through the urls
631
+ # Resizing is done based on the width and height provided
632
+ #
633
+ # @param name
634
+ # - Name of the image to resize
635
+ # @param inputStream
636
+ # - InputStream of the local file to resize
637
+ # @param percentage
638
+ # - Percentage to which image has to be resized
639
+ #
640
+ # @return Image object containing urls for the original and converted images
641
+ #
642
+ # @raise App42Exception
643
+ #
644
+
645
+ def resize_by_percentage_by_stream(name, imagePath, percentage)
646
+ puts "resizeByPercentage Called "
647
+ puts "Base url #{@base_url}"
648
+ response = nil
649
+ imageObj = nil
650
+ imageObj = Image.new()
651
+ util = Util.new
652
+ util.throwExceptionIfNullOrBlank(name, "Name");
653
+ util.throwExceptionIfNotValidImageExtension(name, "Name");
654
+ util.throwExceptionIfNullOrBlank(percentage, "Percentage");
655
+ begin
656
+ file = File.new(imagePath,"rb")
657
+ ext = File.extname(file)
658
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
659
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
660
+ end
661
+ if File.file?(imagePath) == false
662
+ raise App42Exception.new("File " + imagePath.to_s + " does not exist");
663
+ end
664
+ connection = App42::Connection::RESTConnection.new(@base_url)
665
+ query_params = Hash.new
666
+ params = {
667
+ 'apiKey'=> @api_key,
668
+ 'version' => @version,
669
+ 'timeStamp' => util.get_timestamp_utc,
670
+ }
671
+ query_params = params.clone
672
+ params.store("name", name)
673
+ params.store("percentage", (percentage.to_f).to_s + "")
674
+ signature = util.sign(@secret_key, params)
675
+ resource_url = "#{@version}/#{@resource}/resizePercentage"
676
+ response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
677
+ image = ImageProcessorResponseBuilder.new
678
+ imageObj = image.buildResponse(response)
679
+ rescue App42Exception =>e
680
+ raise e
681
+ rescue Exception => e
682
+ raise App42Exception.new(e)
683
+ end
684
+ return imageObj
685
+ end
686
+
687
+ #
688
+ # Creates a thumbnail of the image by Percentage. There is a difference between thumbnail and resize
689
+ # The thumbnail operation is optimized for speed removes information of the image which is not necessary for a
690
+ # thumbnail to reduce size e.g header information. Returns the original image url and converted image url.
691
+ # Images are stored in the cloud and can be accessed through the urls
692
+ # Resizing is done based on the width and height provided
693
+ #
694
+ # @param name
695
+ # - Name of the image file for which thumbnail has to be created
696
+ # @param imagePath
697
+ # - Path of the local file whose thumbnail has to be created
698
+ # @param percentage
699
+ # - Percentage for thumbnail
700
+ #
701
+ # @return Image object containing urls for the original and converted images
702
+ #
703
+ # @raise App42Exception
704
+ #
705
+
706
+ def thumbnail_by_percentage(name, imagePath, percentage)
707
+ puts "thumbnailByPercentage Called "
708
+ puts "Base url #{@base_url}"
709
+ response = nil
710
+ imageObj = nil
711
+ imageObj = Image.new()
712
+ util = Util.new
713
+ util.throwExceptionIfNullOrBlank(name, "Name");
714
+ util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
715
+ util.throwExceptionIfNullOrBlank(percentage, "Percentage");
716
+ begin
717
+ file = File.new(imagePath,"rb")
718
+ ext = File.extname(file)
719
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
720
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
721
+ end
722
+ if File.file?(imagePath) == false
723
+ raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
724
+ end
725
+ connection = App42::Connection::RESTConnection.new(@base_url)
726
+ params = Hash.new
727
+ query_params = Hash.new
728
+ query_params = {
729
+ 'apiKey'=> @api_key,
730
+ 'version' => @version,
731
+ 'timeStamp' => util.get_timestamp_utc,
732
+ }
733
+ params = query_params.clone
734
+ post_params = Hash.new
735
+ post_params.store("name", name)
736
+ post_params.store("percentage", (percentage.to_f).to_s + "")
737
+ params = params.merge(post_params)
738
+ signature = util.sign(@secret_key, params)
739
+ resource_url = "#{@version}/#{@resource}/thumbnailPercentage"
740
+ response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
741
+ image = ImageProcessorResponseBuilder.new
742
+ imageObj = image.buildResponse(response)
743
+ rescue App42Exception =>e
744
+ raise e
745
+ rescue Exception => e
746
+ raise App42Exception.new(e)
747
+ end
748
+ return imageObj
749
+ end
750
+
751
+ #
752
+ # Creates a thumbnail of the image by Percentage via Stream. There is a difference between thumbnail and resize
753
+ # The thumbnail operation is optimized for speed removes information of the image which is not necessary for a
754
+ # thumbnail to reduce size e.g header information. Returns the original image url and converted image url.
755
+ # Images are stored in the cloud and can be accessed through the urls
756
+ # Resizing is done based on the width and height provided
757
+ #
758
+ # @param name
759
+ # - Name of the image file for which thumbnail has to be created
760
+ # @param inputStream
761
+ # - InputStream of the local file whose thumbnail has to be created
762
+ # @param percentage
763
+ # - Percentage for thumbnail
764
+ #
765
+ # @return Image object containing urls for the original and converted images
766
+ #
767
+ # @raise App42Exception
768
+ #
769
+
770
+ def thumbnail_by_percentage_stream(name, imagePath, percentage)
771
+ puts "thumbnailByPercentage Called "
772
+ puts "Base url #{@base_url}"
773
+ response = nil
774
+ imageObj = nil
775
+ imageObj = Image.new()
776
+ util = Util.new
777
+ util.throwExceptionIfNullOrBlank(name, "Name");
778
+ util.throwExceptionIfNotValidImageExtension(name, "Name");
779
+ util.throwExceptionIfNullOrBlank(percentage, "Percentage");
780
+ begin
781
+ file = File.new(imagePath,"rb")
782
+ ext = File.extname(file)
783
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
784
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
785
+ end
786
+ if File.file?(imagePath) == false
787
+ raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
788
+ end
789
+ connection = App42::Connection::RESTConnection.new(@base_url)
790
+ query_params = Hash.new
791
+ params = {
792
+ 'apiKey'=> @api_key,
793
+ 'version' => @version,
794
+ 'timeStamp' => util.get_timestamp_utc,
795
+ }
796
+ query_params = params.clone
797
+ params.store("name", name)
798
+ params.store("percentage", (percentage.to_f).to_s + "")
799
+ signature = util.sign(@secret_key, params)
800
+ resource_url = "#{@version}/#{@resource}/thumbnailPercentage"
801
+ response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
802
+ image = ImageProcessorResponseBuilder.new
803
+ imageObj = image.buildResponse(response)
804
+ rescue App42Exception =>e
805
+ raise e
806
+ rescue Exception => e
807
+ raise App42Exception.new(e)
808
+ end
809
+ return imageObj
810
+ end
811
+
812
+ #
813
+ # Scales the image by Percentage. Returns the original image url and converted image url.
814
+ # Images are stored in the cloud and can be accessed through the urls
815
+ # Resizing is done based on the width and height provided
816
+ #
817
+ # @param name
818
+ # - Name of the image file to scale
819
+ # @param imagePath
820
+ # - Path of the local file to scale
821
+ # @param percentage
822
+ # - Percentage to which image has to be scaled
823
+ #
824
+ # @return Image object containing urls for the original and converted images
825
+ #
826
+ # @raise App42Exception
827
+ #
828
+
829
+ def scale_by_percentage(name, imagePath, percentage)
830
+ puts "scaleByPercentage Called "
831
+ puts "Base url #{@base_url}"
832
+ response = nil
833
+ imageObj = nil
834
+ imageObj = Image.new()
835
+ util = Util.new
836
+ util.throwExceptionIfNullOrBlank(name, "Name");
837
+ util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
838
+ util.throwExceptionIfNullOrBlank(percentage, "Percentage");
839
+ begin
840
+ file = File.new(imagePath,"rb")
841
+ ext = File.extname(file)
842
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
843
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
844
+ end
845
+ if File.file?(imagePath) == false
846
+ raise App42Exception.new("File " + imagePath.to_s + " does not exist");
847
+ end
848
+ connection = App42::Connection::RESTConnection.new(@base_url)
849
+ query_params = Hash.new
850
+ params = {
851
+ 'apiKey'=> @api_key,
852
+ 'version' => @version,
853
+ 'timeStamp' => util.get_timestamp_utc,
854
+ }
855
+ query_params = params.clone
856
+ params.store("name", name)
857
+ params.store("percentage", (percentage.to_f).to_s + "")
858
+ signature = util.sign(@secret_key, params)
859
+ resource_url = "#{@version}/#{@resource}/scalePercentage"
860
+ response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
861
+ image = ImageProcessorResponseBuilder.new
862
+ imageObj = image.buildResponse(response)
863
+ rescue App42Exception =>e
864
+ raise e
865
+ rescue Exception => e
866
+ raise App42Exception.new(e)
867
+ end
868
+ return imageObj
869
+ end
870
+
871
+ #
872
+ # Scales the image by Percentage via Stream. Returns the original image url and converted image url.
873
+ # Images are stored in the cloud and can be accessed through the urls
874
+ # Resizing is done based on the width and height provided
875
+ #
876
+ # @param name
877
+ # - Name of the image file to scale
878
+ # @param inputStream
879
+ # - InputStream of the local file to scale
880
+ # @param percentage
881
+ # - Percentage to which image has to be scaled
882
+ #
883
+ # @return Image object containing urls for the original and converted images
884
+ #
885
+ # @raise App42Exception
886
+ #
887
+
888
+ def scale_by_percentage_stream(name, imagePath, percentage)
889
+ puts "scaleByPercentage Called "
890
+ puts "Base url #{@base_url}"
891
+ response = nil
892
+ imageObj = nil
893
+ imageObj = Image.new()
894
+ util = Util.new
895
+ util.throwExceptionIfNullOrBlank(name, "Name");
896
+ util.throwExceptionIfNotValidImageExtension(name, "Name");
897
+ util.throwExceptionIfNullOrBlank(percentage, "Percentage");
898
+ begin
899
+ file = File.new(imagePath,"rb")
900
+ ext = File.extname(file)
901
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
902
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
903
+ end
904
+ if File.file?(imagePath) == false
905
+ raise App42Exception.new("File " + imagePath.to_s + " does not exist");
906
+ end
907
+ connection = App42::Connection::RESTConnection.new(@base_url)
908
+ query_params = Hash.new
909
+ params = {
910
+ 'apiKey'=> @api_key,
911
+ 'version' => @version,
912
+ 'timeStamp' => util.get_timestamp_utc,
913
+ }
914
+ query_params = params.clone
915
+ params.store("name", name)
916
+ params.store("percentage", (percentage.to_f).to_s + "")
917
+ signature = util.sign(@secret_key, params)
918
+ resource_url = "#{@version}/#{@resource}/scalePercentage"
919
+ response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
920
+ image = ImageProcessorResponseBuilder.new
921
+ imageObj = image.buildResponse(response)
922
+ rescue App42Exception =>e
923
+ raise e
924
+ rescue Exception => e
925
+ raise App42Exception.new(e)
926
+ end
927
+ return imageObj
928
+ end
929
+
930
+ #
931
+ # Converts the format of the image. Returns the original image url and converted image url.
932
+ # Images are stored on the cloud and can be accessed through the urls
933
+ # Conversion is done based on the formatToConvert provided
934
+ #
935
+ # @param name
936
+ # - Name of the image to resize
937
+ # @param imagePath
938
+ # - Path of the local file to resize
939
+ # @param formatToConvert
940
+ # - to which file needs to be converted
941
+ # @return Image object containing urls for the original and converted
942
+ # images
943
+ #
944
+ # @throws App42Exception
945
+ #
946
+
947
+ def convert_format(name, imagePath, formatToConvert)
948
+ puts "convert_format Called "
949
+ puts "Base url #{@base_url}"
950
+ response = nil
951
+ imageObj = nil
952
+ imageObj = Image.new()
953
+ util = Util.new
954
+ util.throwExceptionIfNullOrBlank(name, "Name");
955
+ util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
956
+ util.throwExceptionIfNullOrBlank(formatToConvert, "FormatToConvert");
957
+ begin
958
+ file = File.new(imagePath,"rb")
959
+ ext = File.extname(file)
960
+ if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
961
+ raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
962
+ end
963
+ if((formatToConvert.eql?("jpg") == false) && (formatToConvert.eql?("JPG") == false) && (formatToConvert.eql?("jpeg") == false) && (formatToConvert.eql?("JPEG") == false) && (formatToConvert.eql?("gif") == false) && (formatToConvert.eql?("GIF") == false) && (formatToConvert.eql?("png") == false) && (formatToConvert.eql?("PNG") == false))
964
+ raise TypeError, "The Request parameters are invalid. Supported conversion extensions are jpg, jpeg, gif and png only"
965
+ end
966
+ if File.file?(imagePath) == false
967
+ raise App42Exception.new("File " + imagePath.to_s + " does not exist");
968
+ end
969
+ connection = App42::Connection::RESTConnection.new(@base_url)
970
+ params = Hash.new
971
+ query_params = Hash.new
972
+ query_params = {
973
+ 'apiKey'=> @api_key,
974
+ 'version' => @version,
975
+ 'timeStamp' => util.get_timestamp_utc,
976
+ }
977
+ params = query_params.clone
978
+ post_params = Hash.new
979
+ post_params.store("name", name)
980
+ post_params.store("formatToConvert", formatToConvert)
981
+ params = params.merge(post_params)
982
+ signature = util.sign(@secret_key, params)
983
+ resource_url = "#{@version}/#{@resource}/convertformat"
984
+ response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
985
+ image = ImageProcessorResponseBuilder.new
986
+ imageObj = image.buildResponse(response)
987
+ rescue App42Exception =>e
988
+ raise e
989
+ rescue Exception => e
990
+ raise App42Exception.new(e)
991
+ end
992
+ return imageObj
993
+ end
994
+
995
+ #
996
+ # Converts the format of the image. Returns the original image url and converted image url.
997
+ # Images are stored on the cloud and can be accessed through the urls
998
+ # Conversion is done based on the formatToConvert provided
999
+ #
1000
+ # @param name
1001
+ # - Name of the image to convert
1002
+ # @param imagePath
1003
+ # - imagePath of the local file to convert
1004
+ # @param formatToConvert
1005
+ # - to which file needs to be converted
1006
+ # @return Image object containing urls for the original and converted
1007
+ # images
1008
+ #
1009
+ # @throws App42Exception
1010
+ #
1011
+
1012
+ def convert_format_with_stream(name, imagePath, formatToConvert)
1013
+ puts "convert_format_with_stream Called "
1014
+ puts "Base url #{@base_url}"
1015
+ response = nil
1016
+ imageObj = nil
1017
+ imageObj = Image.new()
1018
+ util = Util.new
1019
+ util.throwExceptionIfNullOrBlank(name, "Name");
1020
+ util.throwExceptionIfNotValidImageExtension(name, "Name");
1021
+ util.throwExceptionIfNullOrBlank(formatToConvert, "FormatToConvert");
1022
+ begin
1023
+ if((formatToConvert.eql?("jpg") == false) && (formatToConvert.eql?("JPG") == false) && (formatToConvert.eql?("jpeg") == false) && (formatToConvert.eql?("JPEG") == false) && (formatToConvert.eql?("gif") == false) && (formatToConvert.eql?("GIF") == false) && (formatToConvert.eql?("png") == false) && (formatToConvert.eql?("PNG") == false))
1024
+ raise TypeError, "The Request parameters are invalid. Supported conversion extensions are jpg, jpeg, gif and png only"
1025
+ end
1026
+ if File.file?(imagePath) == false
1027
+ raise App42Exception.new("File " + imagePath.to_s + " does not exist");
1028
+ end
1029
+ connection = App42::Connection::RESTConnection.new(@base_url)
1030
+ query_params = Hash.new
1031
+ params = {
1032
+ 'apiKey'=> @api_key,
1033
+ 'version' => @version,
1034
+ 'timeStamp' => util.get_timestamp_utc,
1035
+ }
1036
+ query_params = params.clone
1037
+ params.store("name", name)
1038
+ params.store("formatToConvert", formatToConvert);
1039
+ signature = util.sign(@secret_key, params)
1040
+ resource_url = "#{@version}/#{@resource}/convertformat"
1041
+ response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
1042
+ image = ImageProcessorResponseBuilder.new
1043
+ imageObj = image.buildResponse(response)
1044
+ rescue App42Exception =>e
1045
+ raise e
1046
+ rescue Exception => e
1047
+ raise App42Exception.new(e)
1048
+ end
1049
+ return imageObj
1050
+ end
1051
+
1052
+ end
1053
+ end
1054
+ end