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,15 @@
1
+ #
2
+ # -----------------------------------------------------------------------
3
+ # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
4
+ # -----------------------------------------------------------------------
5
+
6
+ require 'App42_Ruby_API/App42Exception'
7
+
8
+ class App42NotFoundException < App42Exception
9
+
10
+ attr_accessor :http_error_code, :app_error_code, :detailMessage
11
+ def initialize(detailMessage, http_error_code, app_error_code)
12
+ super(detailMessage,http_error_code,app_error_code)
13
+ end
14
+
15
+ end
@@ -0,0 +1,13 @@
1
+ #
2
+ # -----------------------------------------------------------------------
3
+ # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
4
+ # -----------------------------------------------------------------------
5
+
6
+ class App42Response
7
+ attr_accessor :isResponseSuccess, :strResponse, :totalRecords
8
+
9
+ @isResponseSuccess
10
+ @strResponse
11
+ @totalRecords = -1
12
+
13
+ end
@@ -0,0 +1,67 @@
1
+ # -----------------------------------------------------------------------
2
+ # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
3
+ # -----------------------------------------------------------------------
4
+
5
+ require 'json'
6
+
7
+ class App42ResponseBuilder
8
+ # @param obj
9
+ # @param jsonObj
10
+ # @raise Exception
11
+ def buildObjectFromJSONTree(obj,jsonObj)
12
+ names = getNames(jsonObj)
13
+ for name in names
14
+ value = jsonObj[name]
15
+ fieldName = "@"+name
16
+ obj.instance_variable_set(:"#{fieldName}", value)
17
+ end
18
+ end
19
+
20
+ # @param serviceName
21
+ # @param json
22
+ # @return
23
+ # @raise Exception
24
+
25
+ def getServiceJSONObject(serviceName,json)
26
+ jsonObj = JSON.parse(json) rescue nil
27
+ jsonObjApp42 = jsonObj["app42"]
28
+ jsonObjResponse = jsonObjApp42["response"]
29
+ jsonObjService = jsonObjResponse["#{serviceName}"]
30
+ return jsonObjService;
31
+ end
32
+
33
+ # @param json
34
+ # @return
35
+ # @raise Exception
36
+
37
+ def isResponseSuccess(json)
38
+ jsonObj = JSON.parse(json) rescue nil
39
+ p jsonObj
40
+ jsonObjApp42 = jsonObj["app42"]
41
+ jsonObjResponse = jsonObjApp42["response"]
42
+ return jsonObjResponse["success"]
43
+ end
44
+
45
+ def getNames(obj)
46
+ names = []
47
+ obj.each do |key, value|
48
+ # puts"key is #{key}" # key holds the key, value holds the value
49
+ names.push(key)
50
+ end
51
+ return names
52
+ end
53
+
54
+ def getTotalRecords(json)
55
+ totalRecords = -1;
56
+ jsonObj = JSON.parse(json) rescue nil
57
+ jsonObjApp42 = jsonObj["app42"]
58
+ jsonObjResponse = jsonObjApp42["response"]
59
+ if jsonObjResponse != nil && jsonObjResponse.key?("totalRecords")
60
+ totalRecords = jsonObjResponse.fetch("totalRecords");
61
+ end
62
+ return totalRecords
63
+ #json_obj = JSON.parse(json) rescue nil
64
+ #totalRecords = json_obj.fetch("totalRecords") if !json_obj["app42"]["response"].nil? && json_obj["app42"]["response"].key?("totalRecords")
65
+ end
66
+
67
+ end
@@ -0,0 +1,15 @@
1
+ #
2
+ # -----------------------------------------------------------------------
3
+ # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
4
+ # -----------------------------------------------------------------------
5
+
6
+ require 'App42_Ruby_API/App42Exception'
7
+
8
+ class App42SecurityException < App42Exception
9
+
10
+ attr_accessor :http_error_code, :app_error_code, :detailMessage
11
+ def initialize(detailMessage, http_error_code, app_error_code)
12
+ super(detailMessage,http_error_code,app_error_code)
13
+ end
14
+
15
+ end
@@ -0,0 +1,3 @@
1
+ module App42RubyAPI
2
+ VERSION = "0.8.4"
3
+ end
@@ -0,0 +1,713 @@
1
+ require "rest-client"
2
+ require 'uri'
3
+
4
+ module App42
5
+ module Connection
6
+ class RESTConnection
7
+ attr_accessor :base_url
8
+ def initialize(base_url)
9
+ puts "RESTConnection->initialize"
10
+ puts "Base url 0 #{@base_url}"
11
+ @base_url = base_url
12
+ end
13
+
14
+ #
15
+ # @param signature
16
+ # @param url
17
+ # @param params
18
+ # @return
19
+ # @throws Exception
20
+ #
21
+
22
+ def get(signature, url, params)
23
+ params.store("signature", signature)
24
+ resource = ""
25
+ resource << self.base_url << url
26
+ puts "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2"
27
+ puts params
28
+ puts resource
29
+ puts signature
30
+ resource = URI.escape(resource).gsub("+", "%20")
31
+ begin
32
+ response = RestClient.get resource,:accept => JSON_MIME_TYPE, :content_type => JSON_MIME_TYPE, :params => params
33
+ puts response.headers
34
+ puts response.body
35
+ rescue => e
36
+ if e.response.code!=200
37
+ jsonObj = nil
38
+ begin
39
+ jsonObj = JSON.parse(e.response)
40
+ rescue => e
41
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
42
+ end
43
+ end
44
+ if e.response.code == 404
45
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
46
+ elsif e.response.code == 400
47
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
48
+ elsif e.response.code == 401
49
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
50
+ elsif e.response.code == 413
51
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
52
+ elsif e.response.code == 500
53
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
54
+ else
55
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
56
+ end
57
+ end
58
+ return response
59
+ end
60
+
61
+ #
62
+ # @param signature
63
+ # @param url
64
+ # @param params
65
+ # @param bodyPayload
66
+ # @return
67
+ # @throws IOException
68
+ # @throws ClientProtocolException
69
+ #
70
+
71
+ def post(signature, url, params, body)
72
+ params.store("signature", signature)
73
+ resource = ""
74
+ resource << self.base_url << url
75
+ resource = URI.escape(resource).gsub("+", "%20")
76
+ begin
77
+ response = RestClient.post resource, body, :accept => JSON_MIME_TYPE, :content_type => JSON_MIME_TYPE, :params => params
78
+ puts response.code
79
+ puts response.to_str
80
+ rescue => e
81
+ puts e
82
+ if e.response.code!=200
83
+ jsonObj = nil
84
+ begin
85
+ jsonObj = JSON.parse(e.response)
86
+ rescue => e
87
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
88
+ end
89
+ end
90
+
91
+ if e.response.code == 404
92
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
93
+ elsif e.response.code == 400
94
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
95
+ elsif e.response.code == 401
96
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
97
+ elsif e.response.code == 413
98
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
99
+ elsif e.response.code == 500
100
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
101
+ else
102
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
103
+ end
104
+ end
105
+ return response
106
+ end
107
+
108
+ #
109
+ # @param signature
110
+ # @param url
111
+ # @param params
112
+ # @param bodyPayload
113
+ # @return
114
+ # @throws IOException
115
+ # @throws ClientProtocolException
116
+ #
117
+
118
+ def put(signature, url, params, body)
119
+ params.store("signature", signature)
120
+ resource = ""
121
+ resource << self.base_url()
122
+ resource << url
123
+ resource = URI.escape(resource).gsub("+", "%20")
124
+ begin
125
+ response = RestClient.put resource, body,:accept => 'application/json', :content_type => 'application/json', :params => params
126
+ puts response.code
127
+ puts response.to_str
128
+ rescue => e
129
+ if e.response.code!=200
130
+ jsonObj = JSON.parse(e.response) rescue nil
131
+ end
132
+
133
+ if e.response.code == 404
134
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
135
+ elsif e.response.code == 400
136
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
137
+ elsif e.response.code == 401
138
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
139
+ elsif e.response.code == 413
140
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
141
+ elsif e.response.code == 500
142
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
143
+ else
144
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
145
+ end
146
+ end
147
+ return response
148
+ end
149
+
150
+ #
151
+ # @param signature
152
+ # @param url
153
+ # @param params
154
+ # @return
155
+ # @throws IOException
156
+ # @throws ClientProtocolException
157
+ #
158
+
159
+ def delete(signature, url, params)
160
+ params.store("signature", signature)
161
+ resource = ""
162
+ resource << self.base_url()
163
+ resource << url
164
+ resource = URI.escape(resource).gsub("+", "%20")
165
+ begin
166
+ response = RestClient.delete resource, :accept => 'application/json', :content_type => 'application/json', :params => params
167
+ puts response.code
168
+ puts response.to_str
169
+ rescue => e
170
+ if e.response.code!=200
171
+ jsonObj = nil
172
+ begin
173
+ jsonObj = JSON.parse(e.response)
174
+ rescue => e
175
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
176
+ end
177
+ end
178
+
179
+ if e.response.code == 404
180
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
181
+ elsif e.response.code == 400
182
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
183
+ elsif e.response.code == 401
184
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
185
+ elsif e.response.code == 413
186
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
187
+ elsif e.response.code == 500
188
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
189
+ else
190
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
191
+ end
192
+ end
193
+ return response
194
+ end
195
+
196
+ # MULTIPART for upload api
197
+ #
198
+ # @param signature
199
+ # @param url
200
+ # @param params
201
+ # @param post_params
202
+ # @ filePath
203
+ # @return
204
+ # @throws IOException
205
+ # @throws ClientProtocolException
206
+ #
207
+
208
+ def multipart(signature, url, params, post_params, filePath)
209
+ params.store("signature", signature)
210
+ resource = ""
211
+ resource << self.base_url()
212
+ resource << url
213
+ resource = URI.escape(resource).gsub("+", "%20")
214
+ puts "Connection to URL #{resource}"
215
+ begin
216
+ response = RestClient.post( resource,
217
+ {
218
+ :uploadFile => File.open(filePath, "rb"),
219
+ :name =>post_params['name'],
220
+ :type =>post_params['type'],
221
+ :userName =>post_params['userName'],
222
+ :description =>post_params['description']
223
+ },
224
+ :accept => 'application/json',
225
+ :content_type => 'application/json',
226
+ :params =>params
227
+ )
228
+ puts response.code
229
+ puts response.to_str
230
+
231
+ rescue => e
232
+ puts e
233
+ if e.response.code!=200
234
+ jsonObj = JSON.parse(e.response)
235
+ end
236
+
237
+ if e.response.code == 404
238
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
239
+ elsif e.response.code == 400
240
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
241
+ elsif e.response.code == 401
242
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
243
+ elsif e.response.code == 413
244
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
245
+ elsif e.response.code == 500
246
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
247
+ else
248
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
249
+ end
250
+
251
+ end
252
+ return response
253
+ end
254
+
255
+ # MULTIPART for upload api via Stream
256
+ #
257
+ # @param signature
258
+ # @param url
259
+ # @param params
260
+ # @param post_params
261
+ # @ filePath
262
+ # @return
263
+ # @throws IOException
264
+ # @throws ClientProtocolException
265
+ #
266
+
267
+ def multipartStream(signature, url, params, post_params, inputStream)
268
+ params.store("signature", signature)
269
+ resource = ""
270
+ resource << self.base_url()
271
+ resource << url
272
+ resource = URI.escape(resource).gsub("+", "%20")
273
+ puts "Connection to URL #{resource}"
274
+ begin
275
+ response = RestClient.post( resource,
276
+ {
277
+ :uploadFile => inputStream,
278
+ :name =>post_params['name'],
279
+ :type =>post_params['type'],
280
+ :userName =>post_params['userName'],
281
+ :description =>post_params['description']
282
+ },
283
+ :accept => 'application/json',
284
+ :content_type => 'application/json',
285
+ :params =>params
286
+ )
287
+ puts response.code
288
+ puts response.to_str
289
+ rescue => e
290
+ puts e
291
+ if e.response.code!=200
292
+ jsonObj = JSON.parse(e.response)
293
+ end
294
+ if e.response.code == 404
295
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
296
+ elsif e.response.code == 400
297
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
298
+ elsif e.response.code == 401
299
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
300
+ elsif e.response.code == 413
301
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
302
+ elsif e.response.code == 500
303
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
304
+ else
305
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
306
+ end
307
+ end
308
+ return response
309
+ end
310
+
311
+ # MULTIPART for gallery api
312
+ #
313
+ # @param signature
314
+ # @param url
315
+ # @param params
316
+ # @param post_params
317
+ # @ filePath
318
+ # @return
319
+ # @throws IOException
320
+ # @throws ClientProtocolException
321
+ #
322
+
323
+ def photoMultipart(signature, url, params, post_params, filePath)
324
+ params.store("signature", signature)
325
+ resource = ""
326
+ resource << self.base_url()
327
+ resource << url
328
+ resource = URI.escape(resource).gsub("+", "%20")
329
+ puts "Connection to URL #{resource}"
330
+ begin
331
+ response = RestClient.post( resource,
332
+ {
333
+ :imageFile => File.open(filePath, "rb"),
334
+ :albumName =>post_params['albumName'],
335
+ :name =>post_params['name'],
336
+ :description =>post_params['description']
337
+ },
338
+ :accept => 'application/json',
339
+ :content_type => 'application/json',
340
+ :params =>params
341
+ )
342
+ puts response.code
343
+ puts response.to_str
344
+ rescue => e
345
+ if e.response.code!=200
346
+ jsonObj = JSON.parse(e.response)
347
+ end
348
+ if e.response.code == 404
349
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
350
+ elsif e.response.code == 400
351
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
352
+ elsif e.response.code == 401
353
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
354
+ elsif e.response.code == 413
355
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
356
+ elsif e.response.code == 500
357
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
358
+ else
359
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
360
+ end
361
+ end
362
+ return response
363
+ end
364
+
365
+ # MULTIPART for gallery api via Stream
366
+ #
367
+ # @param signature
368
+ # @param url
369
+ # @param params
370
+ # @param post_params
371
+ # @ filePath
372
+ # @return
373
+ # @throws IOException
374
+ # @throws ClientProtocolException
375
+ #
376
+
377
+ def photoMultipartStream(signature, url, params, post_params, filePath)
378
+ params.store("signature", signature)
379
+ resource = ""
380
+ resource << self.base_url()
381
+ resource << url
382
+ resource = URI.escape(resource).gsub("+", "%20")
383
+ puts "Connection to URL #{resource}"
384
+ begin
385
+ response = RestClient.post( resource,
386
+ {
387
+ :imageFile => filePath,
388
+ :albumName =>post_params['albumName'],
389
+ :name =>post_params['name'],
390
+ :description =>post_params['description']
391
+ },
392
+ :accept => 'application/json',
393
+ :content_type => 'application/json',
394
+ :params =>params
395
+ )
396
+ puts response.code
397
+ puts response.to_str
398
+ rescue => e
399
+ if e.response.code!=200
400
+ jsonObj = JSON.parse(e.response)
401
+ end
402
+ if e.response.code == 404
403
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
404
+ elsif e.response.code == 400
405
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
406
+ elsif e.response.code == 401
407
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
408
+ elsif e.response.code == 413
409
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
410
+ elsif e.response.code == 500
411
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
412
+ else
413
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
414
+ end
415
+ end
416
+ return response
417
+ end
418
+
419
+ # MULTIPART for Image Processor api
420
+ #
421
+ # @param signature
422
+ # @param url
423
+ # @param params
424
+ # @param post_params
425
+ # @ filePath
426
+ # @return
427
+ # @throws IOException
428
+ # @throws ClientProtocolException
429
+ #
430
+
431
+ def imageMultipart(signature, url, params, post_params, imagePath)
432
+ params.store("signature", signature)
433
+ resource = ""
434
+ resource << self.base_url()
435
+ resource << url
436
+ resource = URI.escape(resource).gsub("+", "%20")
437
+ puts "Connection to URL #{resource}"
438
+ begin
439
+ response = RestClient.post( resource,
440
+ {
441
+ :imageFile => File.open(imagePath, "rb"),
442
+ :name =>post_params['name'],
443
+ :width =>post_params['width'],
444
+ :height =>post_params['height'],
445
+ :formatToConvert =>post_params['formatToConvert'],
446
+ :percentage =>post_params['percentage'],
447
+ :x =>post_params['x'],
448
+ :y =>post_params['y'],
449
+ },
450
+ :accept => 'application/json',
451
+ :content_type => 'application/json',
452
+ :params =>params
453
+ )
454
+ puts response.code
455
+ puts response.to_str
456
+ rescue => e
457
+ puts "e-----#{e}"
458
+ if e.response.code!=200
459
+ jsonObj =JSON.parse(e.response)
460
+ end
461
+ if e.response.code == 404
462
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
463
+ elsif e.response.code == 400
464
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
465
+ elsif e.response.code == 401
466
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
467
+ elsif e.response.code == 413
468
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
469
+ elsif e.response.code == 500
470
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
471
+ else
472
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
473
+ end
474
+ end
475
+ return response
476
+ end
477
+
478
+ # MULTIPART for Image Processor api
479
+ #
480
+ # @param signature
481
+ # @param url
482
+ # @param params
483
+ # @param post_params
484
+ # @ filePath
485
+ # @return
486
+ # @throws IOException
487
+ # @throws ClientProtocolException
488
+ #
489
+
490
+ def imageMultipartStream(signature, url, params, post_params, imagePath)
491
+ params.store("signature", signature)
492
+ resource = ""
493
+ resource << self.base_url()
494
+ resource << url
495
+ resource = URI.escape(resource).gsub("+", "%20")
496
+ puts "Connection to URL #{resource}"
497
+ begin
498
+ response = RestClient.post( resource,
499
+ {
500
+ :imageFile => imagePath,
501
+ :name =>post_params['name'],
502
+ :width =>post_params['width'],
503
+ :height =>post_params['height'],
504
+ :formatToConvert =>post_params['formatToConvert'],
505
+ :percentage =>post_params['percentage'],
506
+ :x =>post_params['x'],
507
+ :y =>post_params['y'],
508
+ },
509
+ :accept => 'application/json',
510
+ :content_type => 'application/json',
511
+ :params =>params
512
+ )
513
+ puts response.code
514
+ puts response.to_str
515
+
516
+ rescue => e
517
+ puts "e-----#{e}"
518
+ if e.response.code!=200
519
+ jsonObj =JSON.parse(e.response)
520
+ end
521
+
522
+ if e.response.code == 404
523
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
524
+ elsif e.response.code == 400
525
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
526
+ elsif e.response.code == 401
527
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
528
+ elsif e.response.code == 413
529
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
530
+ elsif e.response.code == 500
531
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
532
+ else
533
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
534
+ end
535
+ end
536
+ return response
537
+ end
538
+
539
+ # MULTIPART for catalogue api
540
+ #
541
+ # @param signature
542
+ # @param url
543
+ # @param params
544
+ # @param post_params
545
+ # @ filePath
546
+ # @return
547
+ # @throws IOException
548
+ # @throws ClientProtocolException
549
+ #
550
+
551
+ def shopMultipart(signature, url, params, post_params, imageFile)
552
+ params.store("signature", signature)
553
+ resource = ""
554
+ resource << self.base_url()
555
+ resource << url
556
+ resource = URI.escape(resource).gsub("+", "%20")
557
+ puts "Connection to URL #{resource}"
558
+ begin
559
+ response = RestClient.post( resource,
560
+ {
561
+ :imageFile => imageFile,
562
+ :itemId =>post_params['itemId'],
563
+ :name =>post_params['name'],
564
+ :description =>post_params['description'],
565
+ :price =>post_params['price'],
566
+ },
567
+ :accept => 'application/json',
568
+ :content_type => 'application/json',
569
+ :params =>params
570
+ )
571
+ puts response.code
572
+ puts response.to_str
573
+
574
+ rescue => e
575
+ puts "e-----#{e}"
576
+ if e.response.code!=200
577
+ jsonObj =JSON.parse(e.response)
578
+ end
579
+
580
+ if e.response.code == 404
581
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
582
+ elsif e.response.code == 400
583
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
584
+ elsif e.response.code == 401
585
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
586
+ elsif e.response.code == 413
587
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
588
+ elsif e.response.code == 500
589
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
590
+ else
591
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
592
+ end
593
+ end
594
+ return response
595
+ end
596
+
597
+ # MULTIPART for Recommended api
598
+ #
599
+ # @param signature
600
+ # @param url
601
+ # @param params
602
+ # @param post_params
603
+ # @ filePath
604
+ # @return
605
+ # @throws IOException
606
+ # @throws ClientProtocolException
607
+ #
608
+
609
+ def recommendMultipart(signature, url, params, post_params, preferenceFile)
610
+ params.store("signature", signature)
611
+ resource = ""
612
+ resource << self.base_url()
613
+ resource << url
614
+ resource = URI.escape(resource).gsub("+", "%20")
615
+ puts "Connection to URL #{resource}"
616
+ begin
617
+ response = RestClient.post( resource,
618
+ {
619
+ :preferenceFile => File.open(preferenceFile, "rb"),
620
+ :name =>post_params['name'],
621
+ :preferenceFilePath =>post_params['preferenceFilePath'],
622
+ :description =>post_params['description']
623
+ },
624
+ :accept => 'application/json',
625
+ :content_type => 'application/json',
626
+ :params =>params
627
+ )
628
+ puts response.code
629
+ puts response.to_str
630
+
631
+ rescue => e
632
+ puts "e-----#{e}"
633
+ if e.response.code!=200
634
+ jsonObj =JSON.parse(e.response)
635
+ end
636
+
637
+ if e.response.code == 404
638
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
639
+ elsif e.response.code == 400
640
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
641
+ elsif e.response.code == 401
642
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
643
+ elsif e.response.code == 413
644
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
645
+ elsif e.response.code == 500
646
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
647
+ else
648
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
649
+ end
650
+ end
651
+ return response
652
+ end
653
+
654
+ # MULTIPART for Recommended api via Stream
655
+ #
656
+ # @param signature
657
+ # @param url
658
+ # @param params
659
+ # @param post_params
660
+ # @ filePath
661
+ # @return
662
+ # @throws IOException
663
+ # @throws ClientProtocolException
664
+ #
665
+
666
+ def recommendMultipartStream(signature, url, params, post_params, inputStream)
667
+ params.store("signature", signature)
668
+ resource = ""
669
+ resource << self.base_url()
670
+ resource << url
671
+ resource = URI.escape(resource).gsub("+", "%20")
672
+ puts "Connection to URL #{resource}"
673
+ begin
674
+ response = RestClient.post( resource,
675
+ {
676
+ :preferenceFile => inputStream,
677
+ :name =>post_params['name'],
678
+ :preferenceFilePath =>post_params['preferenceFilePath'],
679
+ :description =>post_params['description']
680
+ },
681
+ :accept => 'application/json',
682
+ :content_type => 'application/json',
683
+ :params =>params
684
+ )
685
+ puts response.code
686
+ puts response.to_str
687
+
688
+ rescue => e
689
+ puts "e-----#{e}"
690
+ if e.response.code!=200
691
+ jsonObj =JSON.parse(e.response)
692
+ end
693
+
694
+ if e.response.code == 404
695
+ raise App42NotFoundException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
696
+ elsif e.response.code == 400
697
+ raise App42BadParameterException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
698
+ elsif e.response.code == 401
699
+ raise App42SecurityException.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
700
+ elsif e.response.code == 413
701
+ raise App42LimitException.new(jsonObj['app42Fault']['details'], e.response.code,1413)
702
+ elsif e.response.code == 500
703
+ raise App42Exception.new(jsonObj['app42Fault']['details'], e.response.code,jsonObj['app42Fault']['appErrorCode'])
704
+ else
705
+ raise App42Exception.new("We are sorry something has gone wrong on our side", 500, 1500);
706
+ end
707
+ end
708
+ return response
709
+ end
710
+
711
+ end
712
+ end
713
+ end