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,77 @@
1
+ # -----------------------------------------------------------------------
2
+ # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
3
+ # -----------------------------------------------------------------------
4
+
5
+ require 'App42_Ruby_API/App42Response'
6
+
7
+ #
8
+ #
9
+ # This Cart object is the value object which contains the properties of Cart
10
+ # along with the setter & getter for those properties.
11
+ #
12
+ #
13
+
14
+ module App42
15
+ module Shopping
16
+ class Cart < App42Response
17
+ attr_accessor :userName, :cartId, :creationTime, :checkOutTime, :state, :isEmpty, :cartSession, :totalAmount, :itemList, :payment
18
+
19
+ @userName
20
+ @cartId
21
+ @creationTime
22
+ @checkOutTime
23
+ @state
24
+ @isEmpty
25
+ @cartSession
26
+ @totalAmount
27
+ @itemList = Array.new
28
+ @payment
29
+ end
30
+
31
+ class Item
32
+ attr_accessor :itemId, :name, :quantity, :image, :price, :totalAmount
33
+
34
+ @itemId
35
+ @name
36
+ @quantity
37
+ @image
38
+ @price
39
+ @totalAmount
40
+
41
+ #
42
+ # This is a constructor that takes no parameter
43
+ #
44
+ #
45
+ def initialize(cart)
46
+ cart.itemList.push(self)
47
+ end
48
+
49
+ #
50
+ # Returns the Cart Response in JSON format.
51
+ #
52
+ # @return the response in JSON format.
53
+ #
54
+
55
+ def to_s
56
+ return "name : #{@name}" + "itemId : #{@itemId}" + "price : #{@price}" + "quantity : #{@quantity}";
57
+ end
58
+ end
59
+
60
+ class Payment
61
+ attr_accessor :transactionId, :totalAmount, :date, :status
62
+
63
+ @transactionId
64
+ @totalAmount
65
+ @date
66
+ @status
67
+
68
+ #
69
+ # This is a constructor that takes no parameter
70
+ #
71
+ #
72
+ def initialize(cart)
73
+ cart.payment = self
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,118 @@
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 'shopping/Cart'
8
+
9
+ module App42
10
+ module Shopping
11
+
12
+ #
13
+ #
14
+ # CartResponseBuilder class converts the JSON response retrieved from the
15
+ # server to the value object i.e Cart
16
+ #
17
+ #
18
+ class CartResponseBuilder < App42ResponseBuilder
19
+
20
+ #
21
+ # Converts the response in JSON format to the value object i.e Cart
22
+ #
23
+ # @param json
24
+ # - response in JSON format
25
+ #
26
+ # @return Cart object filled with json data
27
+ #
28
+ def buildResponse(json)
29
+ cartsJSONObj = getServiceJSONObject("carts", json)
30
+ cartJSONObj = cartsJSONObj.fetch("cart")
31
+ cart = buildCartObject(cartJSONObj);
32
+ cart.strResponse=json
33
+ cart.isResponseSuccess = isResponseSuccess(json)
34
+ return cart
35
+ end
36
+
37
+ #
38
+ # Converts the Cart JSON object to the value object i.e Cart
39
+ #
40
+ # @param cartJSONObj
41
+ # - cart data as JSONObject
42
+ #
43
+ # @return Cart object filled with json data
44
+ #
45
+ #
46
+
47
+ def buildCartObject(cartJSONObj)
48
+ cart = Cart.new();
49
+
50
+ itemList = Array.new()
51
+ cart.itemList = itemList
52
+
53
+ buildObjectFromJSONTree(cart, cartJSONObj);
54
+
55
+ if cartJSONObj.key?("items") && cartJSONObj.fetch("items").key?("item")
56
+
57
+ if cartJSONObj.fetch("items").fetch("item").instance_of?(Hash)
58
+ #Single Item
59
+ itemJSONObj = cartJSONObj.fetch("items").fetch("item")
60
+ item = App42::Shopping::Item.new(cart)
61
+
62
+ buildObjectFromJSONTree(item, itemJSONObj);
63
+ else
64
+ # Multiple Items
65
+ itemJSONArray = cartJSONObj.fetch("items").fetch("item");
66
+ itemJSONArray.length.times do |i|
67
+ itemJSONObj = itemJSONArray[i]
68
+ item = App42::Shopping::Item.new(cart)
69
+ buildObjectFromJSONTree(item, itemJSONObj);
70
+ end
71
+ end
72
+ end
73
+
74
+ if cartJSONObj.key?("payments") && cartJSONObj.fetch("payments").key?("payment")
75
+ # Fetch Payment
76
+ paymentJSONObj = cartJSONObj.fetch("payments").fetch("payment");
77
+ puts paymentJSONObj
78
+ payment = App42::Shopping::Payment.new(cart)
79
+ buildObjectFromJSONTree(payment, paymentJSONObj);
80
+ end
81
+ return cart;
82
+ end
83
+
84
+ #
85
+ # Converts the response in JSON format to the list of value objects i.e
86
+ # Cart
87
+ #
88
+ # @param json
89
+ # - response in JSON format
90
+ #
91
+ # @return List of Cart object filled with json data
92
+ #
93
+ #
94
+
95
+ def buildArrayResponse(json)
96
+ cartsJSONObj = getServiceJSONObject("carts", json);
97
+ cartList = Array.new
98
+ if cartsJSONObj.fetch("cart").instance_of?(Array)
99
+ cartJSONArray = cartsJSONObj.fetch("cart")
100
+ cartJSONArray.length.times do |i|
101
+ cartJSONObj = cartJSONArray[i]
102
+ cart = buildCartObject(cartJSONObj);
103
+ cart.strResponse=json
104
+ cart.isResponseSuccess = isResponseSuccess(json)
105
+ cartList.push(cart)
106
+ end
107
+ else
108
+ cartJSONObj = cartsJSONObj.fetch("cart");
109
+ cart = buildCartObject(cartJSONObj);
110
+ cart.strResponse=json
111
+ cart.isResponseSuccess = isResponseSuccess(json)
112
+ cartList.push(cart)
113
+ end
114
+ return cartList
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,902 @@
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 'shopping/CartResponseBuilder'
11
+ require 'shopping/Cart'
12
+ require 'shopping/PaymentStatus'
13
+ require 'shopping/ItemData'
14
+
15
+ module App42
16
+ module Shopping
17
+ #
18
+ # This is Cloud Persistent Shopping Cart Service. App Developers can use this to
19
+ # create a Shopping Cart. Add Items and Check Out items. It also maintains the transactions
20
+ # and the corresponding Payment Status.
21
+ #
22
+ # The Payment Gateway interface is not provided by the Platform. It is left to the App developer
23
+ # how he wants to do the Payment Integration. This can be used along with Catalogue or used independently
24
+ #
25
+ # @see Catalgoue
26
+ # @see Cart
27
+ # @see App42Response
28
+ # @see ItemData
29
+ # @see PaymentStatus
30
+ #
31
+ class CartService
32
+ #
33
+ # this is a constructor that takes
34
+ #
35
+ # @param apiKey
36
+ # @param secretKey
37
+ # @param baseURL
38
+ #
39
+ def initialize(api_key, secret_key, base_url)
40
+ puts "Shopping ->initialize"
41
+ @api_key = api_key
42
+ @secret_key = secret_key
43
+ @base_url = base_url
44
+ @resource = "cart"
45
+ @version = "1.0"
46
+ end
47
+
48
+ #
49
+ # Creates a Cart Session for the specified User
50
+ #
51
+ # @param user
52
+ # - User for whom Cart Session has to be created
53
+ #
54
+ # @return Cart Object containing Cart Id with Creation Time. The id has to be used in subsequent calls for
55
+ # adding and checking out
56
+ #
57
+ # @raise App42Exception
58
+ #
59
+
60
+ def create_cart(user)
61
+ puts "Create Cart Called "
62
+ puts "Base url #{@base_url}"
63
+ response = nil;
64
+ cartObj = nil;
65
+ cartObj = Cart.new
66
+ util = Util.new
67
+ util.throwExceptionIfNullOrBlank(user, "User");
68
+ begin
69
+ connection = App42::Connection::RESTConnection.new(@base_url)
70
+ body = {'app42' => {"cart"=> {
71
+ "userName" => user,
72
+ }}}.to_json
73
+ puts "Body #{body}"
74
+ query_params = Hash.new
75
+ params = {
76
+ 'apiKey'=> @api_key,
77
+ 'version' => @version,
78
+ 'timeStamp' => util.get_timestamp_utc,
79
+ }
80
+ query_params = params.clone
81
+ params.store("body", body)
82
+ puts params
83
+ puts query_params
84
+ signature = util.sign(@secret_key, params)
85
+ resource_url = "#{@version}/#{@resource}"
86
+ response = connection.post(signature, resource_url, query_params, body)
87
+ cart = CartResponseBuilder.new
88
+ cartObj = cart.buildResponse(response)
89
+ rescue App42Exception =>e
90
+ raise e
91
+ rescue Exception => e
92
+ raise App42Exception.new(e)
93
+ end
94
+ return cartObj
95
+ end
96
+
97
+ #
98
+ # Fetch Cart details. Can be used by the App developer to display Cart Details i.e. Items in a Cart.
99
+ #
100
+ # @param cartId
101
+ # - The Cart Id that has to be fetched
102
+ #
103
+ # @return Cart object containing cart details with all the items which are in it. It also tells the state of
104
+ # the Cart
105
+ #
106
+ # @raise App42Exception
107
+ #
108
+
109
+ def get_cart_details(cartId)
110
+ puts "Get Cart Details Called "
111
+ puts "Base url #{@base_url}"
112
+ response = nil;
113
+ cartObj = nil;
114
+ cartObj = Cart.new
115
+ util = Util.new
116
+ util.throwExceptionIfNullOrBlank(cartId, "CartId");
117
+ begin
118
+ connection = App42::Connection::RESTConnection.new(@base_url)
119
+ query_params = Hash.new
120
+ params = {
121
+ 'apiKey'=> @api_key,
122
+ 'version' => @version,
123
+ 'timeStamp' => util.get_timestamp_utc,
124
+ }
125
+ query_params = params.clone
126
+ puts params
127
+ params.store("cartId", cartId)
128
+ puts query_params
129
+ signature = util.sign(@secret_key, params)
130
+ resource_url = "#{@version}/#{@resource}/#{cartId}/details"
131
+ response = connection.get(signature, resource_url, query_params)
132
+ puts "Response is #{response}"
133
+ cart = CartResponseBuilder.new
134
+ cartObj = cart.buildResponse(response)
135
+ rescue App42Exception =>e
136
+ raise e
137
+ rescue Exception => e
138
+ raise App42Exception.new(e)
139
+ end
140
+ return cartObj
141
+ end
142
+
143
+ #
144
+ # Adds an Item in the Cart with quantity and price. This method does not take currency. Its the
145
+ # bonus of the App developer to maintain the currency. It takes only the price.
146
+ #
147
+ # @param cartID
148
+ # - The Cart Id into which item has to be added
149
+ # @param itemID
150
+ # - The Item id which has to be added in the cart. If the Catalogue Service is used along
151
+ # with the Cart Service then the Item ids should be same.
152
+ # @param itemQuantity
153
+ # - Quantity of the Item to be purchased
154
+ # @param price
155
+ # - Price of the item
156
+ #
157
+ # @return Cart object containing added item.
158
+ #
159
+ # @raise App42Exception
160
+ #
161
+
162
+ def add_item(cartID, itemID, itemQuantity, price)
163
+ puts "Add Item Called "
164
+ puts "Base url #{@base_url}"
165
+ response = nil;
166
+ cartObj = nil;
167
+ cartObj = Cart.new
168
+ util = Util.new
169
+ util.throwExceptionIfNullOrBlank(cartID, "CartID");
170
+ util.throwExceptionIfNullOrBlank(itemID, "ItemID");
171
+ util.throwExceptionIfNullOrBlank(itemQuantity, "ItemQuantity");
172
+ util.throwExceptionIfNullOrBlank(price, "Price");
173
+ begin
174
+ connection = App42::Connection::RESTConnection.new(@base_url)
175
+ body = {'app42'=>{
176
+ "cart"=>{
177
+ "cartId"=>cartID,
178
+ "item"=>{
179
+ "quantity"=>itemQuantity,
180
+ "amount"=>price
181
+ }
182
+ }
183
+ }}.to_json
184
+ puts "Body #{body}"
185
+ query_params = Hash.new
186
+ params = {
187
+ 'apiKey'=> @api_key,
188
+ 'version' => @version,
189
+ 'timeStamp' => util.get_timestamp_utc,
190
+ }
191
+ query_params = params.clone
192
+ puts params
193
+ params.store("body", body)
194
+ params.store("itemId", itemID)
195
+ puts query_params
196
+ signature = util.sign(@secret_key, params)
197
+ resource_url = "#{@version}/#{@resource}/item/#{itemID}"
198
+ response = connection.post(signature, resource_url, query_params, body)
199
+ cart = CartResponseBuilder.new
200
+ cartObj = cart.buildResponse(response)
201
+ rescue App42Exception =>e
202
+ raise e
203
+ rescue Exception => e
204
+ raise App42Exception.new(e)
205
+ end
206
+ return cartObj
207
+ end
208
+
209
+ #
210
+ # Fetches the Items from the specified Cart
211
+ #
212
+ # @param cartId
213
+ # - The cart id from which items have to be fetched
214
+ #
215
+ # @return Cart object which contains all items in the cart
216
+ #
217
+ # @raise App42Exception
218
+ #
219
+
220
+ def get_items(cartId)
221
+ puts "Get Items Called "
222
+ puts "Base url #{@base_url}"
223
+ response = nil;
224
+ cartObj = nil;
225
+ cartObj = Cart.new
226
+ util = Util.new
227
+ util.throwExceptionIfNullOrBlank(cartId, "CartId");
228
+ begin
229
+ connection = App42::Connection::RESTConnection.new(@base_url)
230
+ query_params = Hash.new
231
+ params = {
232
+ 'apiKey'=> @api_key,
233
+ 'version' => @version,
234
+ 'timeStamp' => util.get_timestamp_utc,
235
+ }
236
+ query_params = params.clone
237
+ params.store("cartId", cartId)
238
+ puts query_params
239
+ signature = util.sign(@secret_key, params)
240
+ resource_url = "#{@version}/#{@resource}/#{cartId}"
241
+ response = connection.get(signature, resource_url, query_params)
242
+ cart = CartResponseBuilder.new
243
+ cartObj = cart.buildResponse(response)
244
+ rescue App42Exception =>e
245
+ raise e
246
+ rescue Exception => e
247
+ raise App42Exception.new(e)
248
+ end
249
+ return cartObj
250
+ end
251
+
252
+ #
253
+ # Fetches the specified Item from the specified Cart
254
+ #
255
+ # @param cartId
256
+ # - The cart id from which item has to be fetched
257
+ # @param itemId
258
+ # - The item for which the information has to be fetched
259
+ #
260
+ # @return Cart Object
261
+ #
262
+ # @raise App42Exception
263
+ #
264
+
265
+ def get_item(cartId, itemId)
266
+ puts "Get Item Called "
267
+ puts "Base url #{@base_url}"
268
+ response = nil;
269
+ cartObj = nil;
270
+ cartObj = Cart.new
271
+ util = Util.new
272
+ util.throwExceptionIfNullOrBlank(cartId, "CartId");
273
+ util.throwExceptionIfNullOrBlank(itemId, "ItemId");
274
+ begin
275
+ connection = App42::Connection::RESTConnection.new(@base_url)
276
+ query_params = Hash.new
277
+ params = {
278
+ 'apiKey'=> @api_key,
279
+ 'version' => @version,
280
+ 'timeStamp' => util.get_timestamp_utc,
281
+ }
282
+ query_params = params.clone
283
+ params.store("cartId", cartId)
284
+ params.store("itemId", itemId)
285
+ puts query_params
286
+ signature = util.sign(@secret_key, params)
287
+ resource_url = "#{@version}/#{@resource}/#{cartId}/#{itemId}"
288
+ response = connection.get(signature, resource_url, query_params)
289
+ cart = CartResponseBuilder.new
290
+ cartObj = cart.buildResponse(response)
291
+ rescue App42Exception =>e
292
+ raise e
293
+ rescue Exception => e
294
+ raise App42Exception.new(e)
295
+ end
296
+ return cartObj
297
+ end
298
+
299
+ #
300
+ # Removes the specified item from the specified Cart
301
+ #
302
+ # @param cartId
303
+ # - The cart id from which the item has to be removed
304
+ # @param itemId
305
+ # - Id of the Item which has to be removed
306
+ #
307
+ # @return App42Response if removed successfully
308
+ #
309
+ # @raise App42Exception
310
+ #
311
+
312
+ def remove_item(cartId, itemId)
313
+ puts "Remove Item Called "
314
+ puts "Base url #{@base_url}"
315
+ response = nil;
316
+ responseObj = App42Response.new();
317
+ util = Util.new
318
+ util.throwExceptionIfNullOrBlank(cartId, "CartId");
319
+ util.throwExceptionIfNullOrBlank(itemId, "ItemId");
320
+ begin
321
+ connection = App42::Connection::RESTConnection.new(@base_url)
322
+ query_params = Hash.new
323
+ params = {
324
+ 'apiKey'=> @api_key,
325
+ 'version' => @version,
326
+ 'timeStamp' => util.get_timestamp_utc,
327
+ }
328
+ query_params = params.clone
329
+ params.store("cartId", cartId)
330
+ params.store("itemId", itemId)
331
+ puts query_params
332
+ signature = util.sign(@secret_key, params)
333
+ resource_url = "#{@version}/#{@resource}/#{cartId}/#{itemId}"
334
+ response = connection.delete(signature, resource_url, query_params)
335
+ responseObj.strResponse=(response)
336
+ responseObj.isResponseSuccess=(true)
337
+ rescue App42Exception =>e
338
+ raise e
339
+ rescue Exception => e
340
+ raise App42Exception.new(e)
341
+ end
342
+ return responseObj
343
+ end
344
+
345
+ #
346
+ # Removes all Items from the specified Cart
347
+ #
348
+ # @param cartId
349
+ # - The cart id from which items have to be removed
350
+ #
351
+ # @return App42Response if removed successfully
352
+ #
353
+ # @raise App42Exception
354
+ #
355
+
356
+ def remove_all_items(cartId)
357
+ puts "Remove All Item Called "
358
+ puts "Base url #{@base_url}"
359
+ response = nil;
360
+ responseObj = App42Response.new();
361
+ util = Util.new
362
+ util.throwExceptionIfNullOrBlank(cartId, "CartId");
363
+ begin
364
+ connection = App42::Connection::RESTConnection.new(@base_url)
365
+ query_params = Hash.new
366
+ params = {
367
+ 'apiKey'=> @api_key,
368
+ 'version' => @version,
369
+ 'timeStamp' => util.get_timestamp_utc,
370
+ }
371
+ query_params = params.clone
372
+ params.store("cartId", cartId)
373
+ puts query_params
374
+ signature = util.sign(@secret_key, params)
375
+ resource_url = "#{@version}/#{@resource}/#{cartId}"
376
+ response = connection.delete(signature, resource_url, query_params)
377
+ responseObj.strResponse=(response)
378
+ responseObj.isResponseSuccess=(true)
379
+ rescue App42Exception =>e
380
+ raise e
381
+ rescue Exception => e
382
+ raise App42Exception.new(e)
383
+ end
384
+ return responseObj
385
+ end
386
+
387
+ #
388
+ # Checks whether the Cart is Empty or not
389
+ #
390
+ # @param cartId
391
+ # - The cart id to check for empty
392
+ #
393
+ # @return Cart object (isEmpty method on Cart object can be used to check status)
394
+ #
395
+ # @raise App42Exception
396
+ #
397
+
398
+ def is_empty(cartId)
399
+ puts "Is Empty Called "
400
+ puts "Base url #{@base_url}"
401
+ response = nil;
402
+ cartObj = nil;
403
+ cartObj = Cart.new
404
+ util = Util.new
405
+ cartStatus = false;
406
+ util.throwExceptionIfNullOrBlank(cartId, "cartId");
407
+ begin
408
+ connection = App42::Connection::RESTConnection.new(@base_url)
409
+ query_params = Hash.new
410
+ params = {
411
+ 'apiKey'=> @api_key,
412
+ 'version' => @version,
413
+ 'timeStamp' => util.get_timestamp_utc,
414
+ }
415
+ query_params = params.clone
416
+ params.store("cartId", cartId)
417
+ puts query_params
418
+ signature = util.sign(@secret_key, params)
419
+ resource_url = "#{@version}/#{@resource}/#{cartId}/isEmpty"
420
+ response = connection.get(signature, resource_url, query_params)
421
+ puts "Response is #{response}"
422
+ cart = CartResponseBuilder.new
423
+ cartObj = cart.buildResponse(response)
424
+ cartStatus = cartObj.isEmpty()
425
+ rescue App42Exception =>e
426
+ raise e
427
+ rescue Exception => e
428
+ raise App42Exception.new(e)
429
+ end
430
+ return cartStatus
431
+ end
432
+
433
+ #
434
+ # Checks out the Cart and put it in CheckOut Stage and returns the Transaction Id
435
+ # The transaction id has to be used in future to update the Payment Status.
436
+ #
437
+ # @param cartID
438
+ # - The cart id that has to be checkedout
439
+ #
440
+ # @return Cart object containing Checked Out Cart Information with the Transaction Id
441
+ #
442
+ # @raise App42Exception
443
+ #
444
+
445
+ def check_out(cartId)
446
+ puts "Check Out Called "
447
+ puts "Base url #{@base_url}"
448
+ response = nil;
449
+ cartObj = nil;
450
+ cartObj = Cart.new
451
+ util = Util.new
452
+ util.throwExceptionIfNullOrBlank(cartId, "CartId");
453
+ begin
454
+ connection = App42::Connection::RESTConnection.new(@base_url)
455
+ body = {'app42' => {"cart"=> {
456
+ "cartId" => cartId,
457
+ }}}.to_json
458
+ puts "Body #{body}"
459
+ query_params = Hash.new
460
+ params = {
461
+ 'apiKey'=> @api_key,
462
+ 'version' => @version,
463
+ 'timeStamp' => util.get_timestamp_utc,
464
+ }
465
+ query_params = params.clone
466
+ params.store("body", body)
467
+ signature = util.sign(@secret_key, params)
468
+ resource_url = "#{@version}/#{@resource}/checkOut"
469
+ response = connection.put(signature, resource_url, query_params, body)
470
+ cart = CartResponseBuilder.new
471
+ cartObj = cart.buildResponse(response)
472
+ rescue App42Exception =>e
473
+ raise e
474
+ rescue Exception => e
475
+ raise App42Exception.new(e)
476
+ end
477
+ return cartObj
478
+ end
479
+
480
+ #
481
+ # Update Payment Status of the Cart. When a Cart is checkout, it is in Checkout state. The payment
482
+ # status has to be updated based on the Payment Gateway interaction
483
+ #
484
+ # @param cartID
485
+ # - The cart id for which the payment status has to be updated
486
+ # @param transactionID
487
+ # - Transaction id for which the payment status has to be updated
488
+ # @param paymentStatus
489
+ # - Payment Status to be updated. The probable values are PaymentStatus.DECLINED, PaymentStatus.AUTHORIZED, PaymentStatus.PENDING
490
+ #
491
+ # @return Cart object which contains Payment Status
492
+ #
493
+ # @raise App42Exception
494
+ #
495
+
496
+ def payment(cartId, transactionID, paymentStatus)
497
+ puts "Is Empty Called "
498
+ puts "Base url #{@base_url}"
499
+ response = nil;
500
+ cartObj = nil;
501
+ cartObj = Cart.new
502
+ util = Util.new
503
+ util.throwExceptionIfNullOrBlank(cartId, "CartId");
504
+ util.throwExceptionIfNullOrBlank(transactionID, "TransactionID");
505
+ util.throwExceptionIfNullOrBlank(paymentStatus, "paymentStatus");
506
+ begin
507
+ if (PaymentStatus.new.isAvailable(paymentStatus) == nil)
508
+ raise App42NotFoundException.new("Payment Status #{paymentStatus} does not Exist ");
509
+ end
510
+ connection = App42::Connection::RESTConnection.new(@base_url)
511
+ body = {'app42' => {"cart"=> {
512
+ "cartId" => cartId,
513
+ "transactionId" => transactionID,
514
+ "status" => paymentStatus,
515
+ }}}.to_json
516
+ puts "Body #{body}"
517
+ query_params = Hash.new
518
+ params = {
519
+ 'apiKey'=> @api_key,
520
+ 'version' => @version,
521
+ 'timeStamp' => util.get_timestamp_utc,
522
+ }
523
+ query_params = params.clone
524
+ params.store("body", body)
525
+ puts query_params
526
+ signature = util.sign(@secret_key, params)
527
+ resource_url = "#{@version}/#{@resource}/payment"
528
+ response = connection.put(signature, resource_url, query_params, body)
529
+ cart = CartResponseBuilder.new
530
+ cartObj = cart.buildResponse(response)
531
+ rescue App42Exception =>e
532
+ raise e
533
+ rescue Exception => e
534
+ raise App42Exception.new(e)
535
+ end
536
+ return cartObj
537
+ end
538
+
539
+ #
540
+ # Fetches Payment information for a User. This can be used to display Order and Payment History
541
+ #
542
+ # @param userId
543
+ # - User Id for whom payment information has to be fetched
544
+ #
545
+ # @return ArrayList containing Cart objects. Payment history can be retrieved from individual Cart object.
546
+ #
547
+ # @raise App42Exception
548
+ #
549
+
550
+ def get_payments_by_user(userId)
551
+ puts "Is Empty Called "
552
+ puts "Base url #{@base_url}"
553
+ response = nil;
554
+ cartList = nil;
555
+ cartList = Array.new
556
+ util = Util.new
557
+ util.throwExceptionIfNullOrBlank(userId, "UserId");
558
+ begin
559
+ connection = App42::Connection::RESTConnection.new(@base_url)
560
+ query_params = Hash.new
561
+ params = {
562
+ 'apiKey'=> @api_key,
563
+ 'version' => @version,
564
+ 'timeStamp' => util.get_timestamp_utc,
565
+ 'userId' => userId
566
+ }
567
+ query_params = params.clone
568
+ params.store("userId", userId)
569
+ puts query_params
570
+ signature = util.sign(@secret_key, params)
571
+ resource_url = "#{@version}/#{@resource}/payments/user/#{userId}"
572
+ response = connection.get(signature, resource_url, query_params)
573
+ cart = CartResponseBuilder.new
574
+ cartList = cart.buildResponse(response)
575
+ rescue App42Exception =>e
576
+ raise e
577
+ rescue Exception => e
578
+ raise App42Exception.new(e)
579
+ end
580
+ return cartList
581
+ end
582
+
583
+ #
584
+ # Fetches Payment information for the specified Cart Id
585
+ #
586
+ # @param cartID
587
+ # - Cart Id for which the payment information has to be fetched
588
+ #
589
+ # @return Cart object which contains Payment History for the specified Cart
590
+ #
591
+ # @raise App42Exception
592
+ #
593
+
594
+ def get_payment_by_cart(cartId)
595
+ puts "Get Payments By Cart Called "
596
+ puts "Base url #{@base_url}"
597
+ response = nil;
598
+ cartObj = nil;
599
+ cartObj = Cart.new
600
+ util = Util.new
601
+ util.throwExceptionIfNullOrBlank(cartId, "CartId");
602
+ begin
603
+ connection = App42::Connection::RESTConnection.new(@base_url)
604
+ query_params = Hash.new
605
+ params = {
606
+ 'apiKey'=> @api_key,
607
+ 'version' => @version,
608
+ 'timeStamp' => util.get_timestamp_utc,
609
+ }
610
+ query_params = params.clone
611
+ params.store("cartId", cartId)
612
+ puts query_params
613
+ signature = util.sign(@secret_key, params)
614
+ resource_url = "#{@version}/#{@resource}/payments/cart/#{cartId}"
615
+ response = connection.get(signature, resource_url, query_params)
616
+ cart = CartResponseBuilder.new
617
+ cartObj = cart.buildResponse(response)
618
+ rescue App42Exception =>e
619
+ raise e
620
+ rescue Exception => e
621
+ raise App42Exception.new(e)
622
+ end
623
+ return cartObj
624
+ end
625
+
626
+ #
627
+ # Fetches Payment information based on User Id and Status
628
+ #
629
+ # @param userId
630
+ # - User Id for whom payment information has to be fetched
631
+ #
632
+ # @return ArrayList containing Cart objects. Payment history can be retrieved from individual Cart object.
633
+ # @return Payment History
634
+ #
635
+ # @raise App42Exception
636
+ #
637
+
638
+ def get_payments_by_user_and_status(userId, paymentStatus)
639
+ puts "Get Payments By User and Status Called "
640
+ puts "Base url #{@base_url}"
641
+ response = nil;
642
+ cartList = nil;
643
+ cartList = Array.new
644
+ util = Util.new
645
+ util.throwExceptionIfNullOrBlank(userId, "UserId");
646
+ util.throwExceptionIfNullOrBlank(paymentStatus, "paymentStatus");
647
+ begin
648
+ if (PaymentStatus.new.isAvailable(paymentStatus) == nil)
649
+ raise App42NotFoundException.new("Payment Status #{paymentStatus} does not Exist ");
650
+ end
651
+ connection = App42::Connection::RESTConnection.new(@base_url)
652
+ query_params = Hash.new
653
+ params = {
654
+ 'apiKey'=> @api_key,
655
+ 'version' => @version,
656
+ 'timeStamp' => util.get_timestamp_utc,
657
+ }
658
+ query_params = params.clone
659
+ params.store("userId", userId)
660
+ params.store("status", paymentStatus)
661
+ puts query_params
662
+ signature = util.sign(@secret_key, params)
663
+ resource_url = "#{@version}/#{@resource}/payments/user/#{userId}/#{paymentStatus}"
664
+ response = connection.get(signature, resource_url, query_params)
665
+ cart = CartResponseBuilder.new
666
+ cartList = cart.buildResponse(response)
667
+ rescue App42Exception =>e
668
+ raise e
669
+ rescue Exception => e
670
+ raise App42Exception.new(e)
671
+ end
672
+ return cartList
673
+ end
674
+
675
+ #
676
+ # Fetches Payment information based on Status
677
+ #
678
+ # @param paymentStatus
679
+ # - Status of type which payment information has to be fetched
680
+ #
681
+ # @return ArrayList containing Cart objects. Payment history can be retrieved from individual Cart object.
682
+ #
683
+ # @raise App42Exception
684
+ #
685
+
686
+ def get_payments_by_status(paymentStatus)
687
+ puts "Get Payments By Status Called "
688
+ puts "Base url #{@base_url}"
689
+ response = nil;
690
+ cartList = nil;
691
+ cartList = Array.new
692
+ util = Util.new
693
+ util.throwExceptionIfNullOrBlank(paymentStatus, "paymentStatus");
694
+ begin
695
+ if (PaymentStatus.new.isAvailable(paymentStatus) == nil)
696
+ raise App42NotFoundException.new("Payment Status #{paymentStatus} does not Exist ");
697
+ end
698
+ connection = App42::Connection::RESTConnection.new(@base_url)
699
+ query_params = Hash.new
700
+
701
+ params = {
702
+ 'apiKey'=> @api_key,
703
+ 'version' => @version,
704
+ 'timeStamp' => util.get_timestamp_utc,
705
+ }
706
+ query_params = params.clone
707
+ params.store("status", paymentStatus)
708
+ puts query_params
709
+ signature = util.sign(@secret_key, params)
710
+ resource_url = "#{@version}/#{@resource}/payments/status/#{paymentStatus}"
711
+ response = connection.get(signature, resource_url, query_params)
712
+ cart = CartResponseBuilder.new
713
+ cartList = cart.buildArrayResponse(response)
714
+ rescue App42Exception =>e
715
+ raise e
716
+ rescue Exception => e
717
+ raise App42Exception.new(e)
718
+ end
719
+ return cartList
720
+ end
721
+
722
+ #
723
+ # History of Carts and Payments for a User. It gives all the carts which are in AUTHORIZED, DECLINED, PENDING state.
724
+ #
725
+ # @param userId
726
+ # - User Id for whom payment history has to be fetched
727
+ #
728
+ # @return ArrayList containing Cart objects. Payment history can be retrieved from individual Cart object.
729
+ #
730
+ # @raise App42Exception
731
+ #
732
+
733
+ def get_payment_history_by_user(userId)
734
+ puts "Get Payment History By User Called "
735
+ puts "Base url #{@base_url}"
736
+ response = nil;
737
+ cartList = nil;
738
+ cartList = Array.new
739
+ util = Util.new
740
+ util.throwExceptionIfNullOrBlank(userId, "UserId");
741
+ begin
742
+ connection = App42::Connection::RESTConnection.new(@base_url)
743
+ query_params = Hash.new
744
+ params = {
745
+ 'apiKey'=> @api_key,
746
+ 'version' => @version,
747
+ 'timeStamp' => util.get_timestamp_utc,
748
+ }
749
+ query_params = params.clone
750
+ params.store("userId", userId)
751
+ puts query_params
752
+ signature = util.sign(@secret_key, params)
753
+ resource_url = "#{@version}/#{@resource}/payment/history/#{userId}"
754
+ response = connection.get(signature, resource_url, query_params)
755
+ cart = CartResponseBuilder.new
756
+ cartList = cart.buildResponse(response)
757
+ rescue App42Exception =>e
758
+ raise e
759
+ rescue Exception => e
760
+ raise App42Exception.new(e)
761
+ end
762
+ return cartList
763
+ end
764
+
765
+ #
766
+ # History of all carts. It gives all the carts which are in AUTHORIZED, DECLINED, PENDING state.
767
+ #
768
+ # @return ArrayList containing Cart objects. Payment history can be retrieved from individual Cart object.
769
+ #
770
+ # @raise App42Exception
771
+ #
772
+
773
+ def get_payment_history_all()
774
+ puts "Get Payment History By User Called "
775
+ puts "Base url #{@base_url}"
776
+ response = nil;
777
+ cartList = nil;
778
+ cartList = Array.new
779
+ util = Util.new
780
+ begin
781
+ connection = App42::Connection::RESTConnection.new(@base_url)
782
+ query_params = Hash.new
783
+ params = {
784
+ 'apiKey'=> @api_key,
785
+ 'version' => @version,
786
+ 'timeStamp' => util.get_timestamp_utc,
787
+ }
788
+ query_params = params.clone
789
+ puts query_params
790
+ signature = util.sign(@secret_key, params)
791
+ resource_url = "#{@version}/#{@resource}/payment/history"
792
+ response = connection.get(signature, resource_url, query_params)
793
+ cart = CartResponseBuilder.new
794
+ cartList = cart.buildArrayResponse(response)
795
+ rescue App42Exception =>e
796
+ raise e
797
+ rescue Exception => e
798
+ raise App42Exception.new(e)
799
+ end
800
+ return cartList
801
+ end
802
+
803
+ #
804
+ # To increase quantity of existing item in the cart.
805
+ #
806
+ # @return Cart object containing updated item.
807
+ #
808
+ # @raise App42Exception
809
+ #
810
+
811
+ def increase_quantity(cartID, itemID, itemQuantity)
812
+ puts "Increase Quantity Called "
813
+ puts "Base url #{@base_url}"
814
+ response = nil;
815
+ cartObj = nil;
816
+ cartObj = Cart.new
817
+ util = Util.new
818
+ util.throwExceptionIfNullOrBlank(cartID, "Cart Id");
819
+ util.throwExceptionIfNullOrBlank(itemID, "Item Id");
820
+ util.throwExceptionIfNullOrBlank(itemQuantity, "Quantity");
821
+ begin
822
+ connection = App42::Connection::RESTConnection.new(@base_url)
823
+ body = {'app42' => {"cart"=> {
824
+ "cartId" => cartID,
825
+ "itemId" => itemID,
826
+ "quantity" => itemQuantity
827
+ }}}.to_json
828
+ puts "Body #{body}"
829
+ query_params = Hash.new
830
+ params = {
831
+ 'apiKey'=> @api_key,
832
+ 'version' => @version,
833
+ 'timeStamp' => util.get_timestamp_utc,
834
+ }
835
+ query_params = params.clone
836
+ params.store("body", body)
837
+ puts query_params
838
+ signature = util.sign(@secret_key, params)
839
+ resource_url = "#{@version}/#{@resource}/increaseQuantity"
840
+ response = connection.put(signature, resource_url, query_params, body)
841
+ cart = CartResponseBuilder.new
842
+ cartObj = cart.buildResponse(response)
843
+ rescue App42Exception =>e
844
+ raise e
845
+ rescue Exception => e
846
+ raise App42Exception.new(e)
847
+ end
848
+ return cartObj
849
+ end
850
+
851
+ #
852
+ # To decrease quantity of existing item in the cart.
853
+ #
854
+ # @return Cart object containing updated item.
855
+ #
856
+ # @raise App42Exception
857
+ #
858
+
859
+ def decrease_quantity(cartId, itemId, itemQuantity)
860
+ puts "Decrease Quantity Called "
861
+ puts "Base url #{@base_url}"
862
+ response = nil;
863
+ cartObj = nil;
864
+ cartObj = Cart.new
865
+ util = Util.new
866
+ util.throwExceptionIfNullOrBlank(cartId, "CartId");
867
+ util.throwExceptionIfNullOrBlank(itemId, "ItemId");
868
+ util.throwExceptionIfNullOrBlank(itemQuantity, "ItemQuantity");
869
+ begin
870
+ connection = App42::Connection::RESTConnection.new(@base_url)
871
+ body = {'app42' => {"cart"=> {
872
+ "cartId" => cartId,
873
+ "itemId" => itemId,
874
+ "quantity" => itemQuantity
875
+ }}}.to_json
876
+ puts "Body #{body}"
877
+ query_params = Hash.new
878
+ params = {
879
+ 'apiKey'=> @api_key,
880
+ 'version' => @version,
881
+ 'timeStamp' => util.get_timestamp_utc,
882
+ }
883
+ query_params = params.clone
884
+ puts params
885
+ params.store("body", body)
886
+ puts query_params
887
+ signature = util.sign(@secret_key, params)
888
+ resource_url = "#{@version}/#{@resource}/decreaseQuantity"
889
+ response = connection.put(signature, resource_url, query_params,body)
890
+ cart = CartResponseBuilder.new
891
+ cartObj = cart.buildResponse(response)
892
+ rescue App42Exception =>e
893
+ raise e
894
+ rescue Exception => e
895
+ raise App42Exception.new(e)
896
+ end
897
+ return cartObj
898
+ end
899
+
900
+ end
901
+ end
902
+ end