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,56 @@
1
+ # -----------------------------------------------------------------------
2
+ # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
3
+ # -----------------------------------------------------------------------
4
+
5
+ require 'App42_Ruby_API/App42Response'
6
+
7
+ #
8
+ # An enum that defines the type of the device to be uploaded on cloud.
9
+ #
10
+
11
+ module App42
12
+ module Push
13
+ class DeviceType < App42Response
14
+ unless (const_defined?(:ANDROID))
15
+ ANDROID = "ANDROID"
16
+ end
17
+ unless (const_defined?(:IOS))
18
+ IOS = "iOS"
19
+ end
20
+ unless (const_defined?(:WP7))
21
+ WP7 = "WP7"
22
+ end
23
+
24
+ #
25
+ # Sets the value of the DeviceType.
26
+ #
27
+ # @param string
28
+ # - the string of DeviceType.
29
+ #
30
+ def enum(string)
31
+ return DeviceType.const_get(string)
32
+ end
33
+
34
+ #
35
+ # Returns the value of the DeviceType.
36
+ #
37
+ # @return the value of DeviceType.
38
+ #
39
+
40
+ def isAvailable(string)
41
+ if(string == "ANDROID")
42
+ return "ANDROID"
43
+ elsif(string == "iOS")
44
+ return "iOS"
45
+ elsif(string == "WP7")
46
+ return "WP7"
47
+ elsif(string == "OTHER")
48
+ return "OTHER";
49
+ else
50
+ return nil
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,38 @@
1
+ # -----------------------------------------------------------------------
2
+ # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
3
+ # -----------------------------------------------------------------------
4
+
5
+ require 'App42_Ruby_API/App42Response'
6
+
7
+ #
8
+ #
9
+ # This Push Notification object is the value object which contains the properties of
10
+ # Push Notification.
11
+ #
12
+ #
13
+
14
+ module App42
15
+ module Push
16
+ class PushNotification < App42Response
17
+ attr_accessor :message, :userName, :deviceToken, :channelList ,:type
18
+ @channelList = Array.new
19
+ @message
20
+ @userName
21
+ @deviceToken
22
+ @type
23
+ end
24
+
25
+ class Channel
26
+ attr_accessor :channelName, :description
27
+ @channelName
28
+ @description
29
+
30
+ #
31
+ # This is a constructor that takes no parameter
32
+ #
33
+ def initialize(pushNotification)
34
+ pushNotification.channelList.push(self)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,74 @@
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 'push/PushNotification'
8
+ require 'push/DeviceType'
9
+
10
+ module App42
11
+ module Push
12
+ #
13
+ #
14
+ # PushNotificationResponseBuilder class converts the JSON response retrieved from
15
+ # the server to the value object i.e Push Notification
16
+ #
17
+ #
18
+ class PushNotificationResponseBuilder < App42ResponseBuilder
19
+ #
20
+ # Converts the response in JSON format to the value object i.e Push Notification
21
+ #
22
+ # @param json
23
+ # - response in JSON format
24
+ #
25
+ # @return Push Notification object filled with json data
26
+ #
27
+ #
28
+ def buildResponse(json)
29
+ pushObj = PushNotification.new()
30
+ channelList = Array.new
31
+ pushObj.channelList=(channelList)
32
+
33
+ pushObj.strResponse=json
34
+
35
+ jsonObj = JSON.parse(json)
36
+ jsonObjApp42 = jsonObj.fetch("app42");
37
+ jsonObjResponse = jsonObjApp42.fetch("response");
38
+ pushObj.isResponseSuccess=(jsonObjResponse.fetch("success"));
39
+ jsonObjPush= jsonObjResponse.fetch("push");
40
+
41
+ buildObjectFromJSONTree(pushObj, jsonObjPush);
42
+
43
+ if jsonObjPush.key?("channels") == false
44
+ return pushObj
45
+ end
46
+
47
+ jsonObjChannels = jsonObjPush.fetch("channels");
48
+
49
+ if jsonObjChannels.key?("channel") == false
50
+ return pushObj;
51
+ end
52
+
53
+ if jsonObjChannels.fetch("channel").instance_of?(Hash)
54
+ jsonObjChannel = jsonObjChannels.fetch("channel");
55
+ channelObject = App42::Push::Channel.new(pushObj)
56
+ buildObjectFromJSONTree(channelObject,jsonObjChannel);
57
+
58
+ else
59
+
60
+ jsonObjChannelArray= jsonObjChannels.fetch("channel");
61
+
62
+ jsonObjChannelArray.length.times do |i|
63
+ jsonObjChannel = jsonObjChannelArray.fetch(i);
64
+ channelObject = App42::Push::Channel.new(pushObj)
65
+ buildObjectFromJSONTree(channelObject,jsonObjChannel);
66
+ end
67
+ end
68
+
69
+ return pushObj;
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,458 @@
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 'push/PushNotificationResposneBuilder'
11
+ require 'push/PushNotification'
12
+ require 'push/DeviceType'
13
+
14
+ module App42
15
+ module Push
16
+ #
17
+ #
18
+ # The service is for pushing the notifications to any device using GCM(Google Cloud Messaging).
19
+ # You have to upload your apikey that you received while registering for GCM and you have to store your
20
+ # device token with particular username. This service allows you the feature of sending message to
21
+ # particular channel, particular user or to all your users.For sending message to any channel, you have to
22
+ # create the channel and send the message to channel. The users which have subscribed to that channel will receive
23
+ # all the notification for that channel. For sending message to particular user, you have to pass username and
24
+ # message. Notification will sent to the device of registered user. The most important feature you can send your message
25
+ # to all your device whether it is iphone, android or blackberry.
26
+ #
27
+ #
28
+ class PushNotificationService
29
+ #
30
+ # this is a constructor that takes
31
+ #
32
+ # @param apiKey
33
+ # @param secretKey
34
+ # @param baseURL
35
+ #
36
+ def initialize(api_key, secret_key, base_url)
37
+ puts "PushNotificationService->initialize"
38
+ @api_key = api_key
39
+ @secret_key = secret_key
40
+ @base_url = base_url
41
+ @resource = "push"
42
+ @version = "1.0"
43
+ end
44
+
45
+ # Stores your device token on server with particular username
46
+ #
47
+ # @param Username
48
+ # - username with which you want your device to be registered
49
+ # @param deviceToken
50
+ # - device id for android phones
51
+ # @param type
52
+ # -
53
+ #
54
+ # @return PushNotification Object
55
+ #
56
+ # @raise App42Exception
57
+ #
58
+
59
+ def store_device_token(userName, deviceToken, type)
60
+ puts "storeDeviceToken Called "
61
+ puts "Base url #{@base_url}"
62
+ response = nil;
63
+ pushObj = nil;
64
+ pushObj = PushNotification.new
65
+ util = Util.new
66
+ util.throwExceptionIfNullOrBlank(userName, "Username");
67
+ util.throwExceptionIfNullOrBlank(deviceToken, "deviceToken");
68
+ util.throwExceptionIfNullOrBlank(type, "Device Type");
69
+ begin
70
+ if (DeviceType.new.isAvailable(type) == nil)
71
+ raise App42NotFoundException.new("Device Type #{type} does not Exist ");
72
+ end
73
+ connection = App42::Connection::RESTConnection.new(@base_url)
74
+ body = {'app42' => {"push" => {
75
+ "userName" => userName,
76
+ "deviceToken" => deviceToken,
77
+ "type" => type
78
+ }}}.to_json
79
+ puts "Body #{body}"
80
+ query_params = Hash.new
81
+ params = {
82
+ 'apiKey'=> @api_key,
83
+ 'version' => @version,
84
+ 'timeStamp' => util.get_timestamp_utc
85
+ }
86
+ query_params = params.clone
87
+ params.store("body", body)
88
+ puts query_params
89
+ signature = util.sign(@secret_key, params)
90
+ resource_url = "#{@version}/#{@resource}/storeDeviceToken/#{userName}"
91
+ response = connection.post(signature, resource_url, query_params, body)
92
+ push = PushNotificationResponseBuilder.new()
93
+ pushObj = push.buildResponse(response)
94
+ rescue App42Exception =>e
95
+ raise e
96
+ rescue Exception => e
97
+ raise App42Exception.new(e)
98
+ end
99
+ return pushObj
100
+ end
101
+
102
+ # Create Channel for app on which user can subscribe and get the notification for that
103
+ # channel
104
+ #
105
+ # @param channel
106
+ # - channel name which you want to create
107
+ # @param description
108
+ # - description for that channel
109
+ #
110
+ # @return PushNotification Object
111
+ #
112
+ # @raise App42Exception
113
+ #
114
+
115
+ def create_channel_for_app(channel, description)
116
+ puts "createChannelForApp Called "
117
+ puts "Base url #{@base_url}"
118
+ response = nil;
119
+ pushObj = nil;
120
+ pushObj = PushNotification.new
121
+ util = Util.new
122
+ util.throwExceptionIfNullOrBlank(channel, "Channel Name");
123
+ util.throwExceptionIfNullOrBlank(description, "Description");
124
+ begin
125
+ connection = App42::Connection::RESTConnection.new(@base_url)
126
+ body = {'app42' => {"push" => {"channel" => {
127
+ "name" => channel,
128
+ "description" => description
129
+ }}}}.to_json
130
+ puts "Body #{body}"
131
+ query_params = Hash.new
132
+ params = {
133
+ 'apiKey'=> @api_key,
134
+ 'version' => @version,
135
+ 'timeStamp' => util.get_timestamp_utc,
136
+ }
137
+ query_params = params.clone
138
+ params.store("body", body)
139
+ puts query_params
140
+ signature = util.sign(@secret_key, params)
141
+ resource_url = "#{@version}/#{@resource}/createAppChannel"
142
+ response = connection.post(signature, resource_url, query_params, body)
143
+ push = PushNotificationResponseBuilder.new()
144
+ pushObj = push.buildResponse(response)
145
+ rescue App42Exception =>e
146
+ raise e
147
+ rescue Exception => e
148
+ raise App42Exception.new(e)
149
+ end
150
+ return pushObj
151
+ end
152
+
153
+ #
154
+ # Subscribe to the channel
155
+ #
156
+ # @param channel
157
+ # - the channel name which you want to subscribe
158
+ # @param userName
159
+ # - username which want to subscribe
160
+ #
161
+ # @return PushNotification Object
162
+ #
163
+ # @raise App42Exception
164
+ #
165
+
166
+ def subscribe_to_channel(channel, userName)
167
+ puts "subscribeToChannel Called "
168
+ puts "Base url #{@base_url}"
169
+ response = nil;
170
+ pushObj = nil;
171
+ pushObj = PushNotification.new
172
+ util = Util.new
173
+ util.throwExceptionIfNullOrBlank(channel, "Channel Name");
174
+ util.throwExceptionIfNullOrBlank(userName, "userName");
175
+ begin
176
+ connection = App42::Connection::RESTConnection.new(@base_url)
177
+ body = {'push' => {"channel" => {
178
+ "name" => channel,
179
+ "userName" => userName
180
+ }}}.to_json
181
+ puts "Body #{body}"
182
+ query_params = Hash.new
183
+ params = {
184
+ 'apiKey'=> @api_key,
185
+ 'version' => @version,
186
+ 'timeStamp' => util.get_timestamp_utc,
187
+ }
188
+ query_params = params.clone
189
+ params.store("body", body)
190
+ puts query_params
191
+ signature = util.sign(@secret_key, params)
192
+ resource_url = "#{@version}/#{@resource}/subscribeToChannel/#{userName}"
193
+ response = connection.post(signature, resource_url, query_params, body)
194
+ push = PushNotificationResponseBuilder.new()
195
+ pushObj = push.buildResponse(response)
196
+ rescue App42Exception =>e
197
+ raise e
198
+ rescue Exception => e
199
+ raise App42Exception.new(e)
200
+ end
201
+ return pushObj
202
+ end
203
+
204
+ # Unsubscribe from particular channel
205
+ #
206
+ # @param channel
207
+ # - channel name which you want to unsubscribe
208
+ # @param userName
209
+ # - username which want to unsubscribe
210
+ #
211
+ # @return PushNotification Object
212
+ #
213
+ # @raise App42Exception
214
+ #
215
+
216
+ def unsubscribe_from_channel(channel, userName)
217
+ puts "unsubscribeFromChannel Called "
218
+ puts "Base url #{@base_url}"
219
+ response = nil;
220
+ pushObj = nil;
221
+ pushObj = PushNotification.new
222
+ util = Util.new
223
+ util.throwExceptionIfNullOrBlank(channel, "Channel Name");
224
+ util.throwExceptionIfNullOrBlank(userName, "userName");
225
+ begin
226
+ connection = App42::Connection::RESTConnection.new(@base_url)
227
+ body = {'push' => {"channel" => {
228
+ "userName" => userName,
229
+ "name" => channel
230
+ }}}.to_json
231
+ puts "Body #{body}"
232
+ query_params = Hash.new
233
+ params = {
234
+ 'apiKey'=> @api_key,
235
+ 'version' => @version,
236
+ 'timeStamp' => util.get_timestamp_utc,
237
+ }
238
+ query_params = params.clone
239
+ params.store("body", body)
240
+ puts query_params
241
+ signature = util.sign(@secret_key, params)
242
+ resource_url = "#{@version}/#{@resource}/unsubscribeToChannel/#{userName}"
243
+ response = connection.put(signature, resource_url, query_params, body)
244
+ push = PushNotificationResponseBuilder.new()
245
+ pushObj = push.buildResponse(response)
246
+ rescue App42Exception =>e
247
+ raise e
248
+ rescue Exception => e
249
+ raise App42Exception.new(e)
250
+ end
251
+ return pushObj
252
+ end
253
+
254
+ #
255
+ # send push message to channel containing string
256
+ #
257
+ # @param channel
258
+ # - channel name which you want to send the message
259
+ # @param message
260
+ # - push message in string format
261
+ #
262
+ # @return PushNotification Object
263
+ #
264
+ # @raise App42Exception
265
+ #
266
+
267
+ def send_push_message_to_channel(channel, message)
268
+ puts "sendPushMessageToChannel Called "
269
+ puts "Base url #{@base_url}"
270
+ response = nil;
271
+ pushObj = nil;
272
+ pushObj = PushNotification.new
273
+ util = Util.new
274
+ util.throwExceptionIfNullOrBlank(channel, "channel");
275
+ util.throwExceptionIfNullOrBlank(message, "message");
276
+ begin
277
+ connection = App42::Connection::RESTConnection.new(@base_url)
278
+ body = {'app42' => {"push" => {"message" => {
279
+ "channel" => channel,
280
+ "expiry" => util.get_timestamp_utc,
281
+ "payload" => message
282
+ }}}}.to_json
283
+ puts "Body #{body}"
284
+ query_params = Hash.new
285
+ params = {
286
+ 'apiKey'=> @api_key,
287
+ 'version' => @version,
288
+ 'timeStamp' => util.get_timestamp_utc,
289
+ }
290
+ query_params = params.clone
291
+ params.store("body", body)
292
+ puts query_params
293
+ signature = util.sign(@secret_key, params)
294
+ resource_url = "#{@version}/#{@resource}/sendPushMessageToChannel/#{channel}"
295
+ response = connection.post(signature, resource_url, query_params, body)
296
+ push = PushNotificationResponseBuilder.new()
297
+ pushObj = push.buildResponse(response)
298
+ rescue App42Exception =>e
299
+ raise e
300
+ rescue Exception => e
301
+ raise App42Exception.new(e)
302
+ end
303
+ return pushObj
304
+ end
305
+
306
+ #
307
+ # Send push message to all your users
308
+ #
309
+ # @param message
310
+ # - push message
311
+ #
312
+ # @return PushNotification Object
313
+ #
314
+ # @raise App42Exception
315
+ #
316
+
317
+ def send_push_message_to_all(message)
318
+ puts "sendPushMessageToAll Called "
319
+ puts "Base url #{@base_url}"
320
+ response = nil;
321
+ pushObj = nil;
322
+ pushObj = PushNotification.new
323
+ util = Util.new
324
+ util.throwExceptionIfNullOrBlank(message, "message");
325
+ begin
326
+ connection = App42::Connection::RESTConnection.new(@base_url)
327
+ body = {'app42' => {"push" => {"message" => {
328
+ "expiry" => util.get_timestamp_utc,
329
+ "payload" => message
330
+ }}}}.to_json
331
+ puts "Body #{body}"
332
+ query_params = Hash.new
333
+ params = {
334
+ 'apiKey'=> @api_key,
335
+ 'version' => @version,
336
+ 'timeStamp' => util.get_timestamp_utc,
337
+ }
338
+ query_params = params.clone
339
+ params.store("body", body)
340
+ puts query_params
341
+ signature = util.sign(@secret_key, params)
342
+ resource_url = "#{@version}/#{@resource}/sendPushMessageToAll"
343
+ response = connection.post(signature, resource_url, query_params, body)
344
+ push = PushNotificationResponseBuilder.new()
345
+ pushObj = push.buildResponse(response)
346
+ rescue App42Exception =>e
347
+ raise e
348
+ rescue Exception => e
349
+ raise App42Exception.new(e)
350
+ end
351
+ return pushObj
352
+ end
353
+
354
+ #
355
+ # Send Push Message To paticular user in string format
356
+ #
357
+ # @param username
358
+ # - username which you want to send the message
359
+ # @param message
360
+ # - push message
361
+ #
362
+ # @return PushNotification Object
363
+ #
364
+ # @raise App42Exception
365
+ #
366
+
367
+ def send_push_message_to_user(userName, message)
368
+ puts "sendPushMessageToUser Called "
369
+ puts "Base url #{@base_url}"
370
+ response = nil;
371
+ pushObj = nil;
372
+ pushObj = PushNotification.new
373
+ util = Util.new
374
+ util.throwExceptionIfNullOrBlank(userName, "userName");
375
+ util.throwExceptionIfNullOrBlank(message, "message");
376
+ begin
377
+ connection = App42::Connection::RESTConnection.new(@base_url)
378
+ body = {'app42' => {"push" => {"message" => {
379
+ "userName" => userName,
380
+ "expiry" => util.get_timestamp_utc,
381
+ "payload" => message
382
+ }}}}.to_json
383
+ puts "Body #{body}"
384
+ query_params = Hash.new
385
+ params = {
386
+ 'apiKey'=> @api_key,
387
+ 'version' => @version,
388
+ 'timeStamp' => util.get_timestamp_utc,
389
+ }
390
+ query_params = params.clone
391
+ params.store("body", body)
392
+ puts query_params
393
+ signature = util.sign(@secret_key, params)
394
+ resource_url = "#{@version}/#{@resource}/sendMessage/#{userName}"
395
+ response = connection.post(signature, resource_url, query_params, body)
396
+ push = PushNotificationResponseBuilder.new()
397
+ pushObj = push.buildResponse(response)
398
+ rescue App42Exception =>e
399
+ raise e
400
+ rescue Exception => e
401
+ raise App42Exception.new(e)
402
+ end
403
+ return pushObj
404
+ end
405
+
406
+ #
407
+ # Send push message to all by type
408
+ #
409
+ # @param message
410
+ # - push message
411
+ #
412
+ # @return PushNotification Object
413
+ #
414
+ # @raise App42Exception
415
+ #
416
+
417
+ def send_push_message_to_all_by_type(message, type)
418
+ puts "sendPushMessageToAll Called "
419
+ puts "Base url #{@base_url}"
420
+ response = nil;
421
+ pushObj = nil;
422
+ pushObj = PushNotification.new
423
+ util = Util.new
424
+ util.throwExceptionIfNullOrBlank(message, "message");
425
+ util.throwExceptionIfNullOrBlank(type, "type");
426
+ begin
427
+ connection = App42::Connection::RESTConnection.new(@base_url)
428
+ body = {'app42' => {"push" => {"message" => {
429
+ "payload" => message,
430
+ "expiry" => util.get_timestamp_utc,
431
+ "type" => type
432
+ }}}}.to_json
433
+ puts "Body #{body}"
434
+ query_params = Hash.new
435
+ params = {
436
+ 'apiKey'=> @api_key,
437
+ 'version' => @version,
438
+ 'timeStamp' => util.get_timestamp_utc,
439
+ }
440
+ query_params = params.clone
441
+ params.store("body", body)
442
+ puts query_params
443
+ signature = util.sign(@secret_key, params)
444
+ resource_url = "#{@version}/#{@resource}/sendMessageToAllByType"
445
+ response = connection.post(signature, resource_url, query_params, body)
446
+ push = PushNotificationResponseBuilder.new()
447
+ pushObj = push.buildResponse(response)
448
+ rescue App42Exception =>e
449
+ raise e
450
+ rescue Exception => e
451
+ raise App42Exception.new(e)
452
+ end
453
+ return pushObj
454
+ end
455
+
456
+ end
457
+ end
458
+ end