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,49 @@
1
+ # -----------------------------------------------------------------------
2
+ # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
3
+ # -----------------------------------------------------------------------
4
+
5
+ require 'App42_Ruby_API/App42Response'
6
+
7
+ #
8
+ #
9
+ # This Log object is the value object which contains the properties of Log.
10
+ #
11
+ #
12
+
13
+ module App42
14
+ module Log
15
+ class Log < App42Response
16
+ attr_accessor :messageList
17
+ @messageList = Array.new
18
+ end
19
+
20
+ class Message
21
+ attr_accessor :message,:type,:logTime,:module
22
+
23
+ #
24
+ # This is a constructor that takes no parameter
25
+ #
26
+ #
27
+ def initialize(log)
28
+ log.messageList.push(self);
29
+ end
30
+
31
+ #
32
+ # Returns the Log Response in JSON format.
33
+ #
34
+ # @return the response in JSON format.
35
+ #
36
+ #
37
+
38
+ def to_s
39
+ return "Message : #{self.message}" + "type : #{self.type}" + "AppModule : #{self.module}" + "logTime : #{self.logTime}";
40
+ end
41
+
42
+ @message
43
+ @type
44
+ @logTime
45
+ @module
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,61 @@
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 'log/Log'
8
+
9
+ module App42
10
+ module Log
11
+ #
12
+ #
13
+ # LogResponseBuilder class converts the JSON response retrieved from the server
14
+ # to the value object i.e Log
15
+ #
16
+ #
17
+ class LogResponseBuilder < App42ResponseBuilder
18
+ #
19
+ # Converts the response in JSON format to the value object i.e Log
20
+ #
21
+ # @param json
22
+ # - response in JSON format
23
+ #
24
+ # @return Log object filled with json data
25
+ #
26
+ #
27
+ def buildResponse(json)
28
+ puts "testing #{json}"
29
+ logObj = Log.new()
30
+ messageList = Array.new
31
+ logObj.messageList= messageList
32
+ logObj.strResponse=json
33
+ jsonObj = JSON.parse(json)
34
+ jsonObjApp42 = jsonObj.fetch("app42")
35
+ jsonObjResponse = jsonObjApp42.fetch("response")
36
+ logObj.isResponseSuccess = jsonObjResponse.fetch("success")
37
+ jsonObjLog = jsonObjResponse["logs"]
38
+ if jsonObjLog.key?("log") == false
39
+ return logObj;
40
+ end
41
+
42
+ if jsonObjLog.fetch("log").instance_of?(Hash)
43
+ # Only One attribute is there
44
+ jsonObjLogMessage = jsonObjLog.fetch("log")
45
+ messageItem = App42::Log::Message.new(logObj)
46
+ buildObjectFromJSONTree(messageItem, jsonObjLogMessage);
47
+ else
48
+ jsonObjMessageArray = jsonObjLog.fetch("log")
49
+ # There is an Array of attribute
50
+ jsonObjMessageArray.length.times do |i|
51
+ # Get Individual Attribute Node and set it into Object
52
+ jsonObjLogMessage = jsonObjMessageArray[i]
53
+ messageItem = App42::Log::Message.new(logObj)
54
+ buildObjectFromJSONTree(messageItem, jsonObjLogMessage);
55
+ end
56
+ end
57
+ return logObj;
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,920 @@
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 'log/LogResponseBuilder'
11
+ require 'log/Log'
12
+
13
+ module App42
14
+ module Log
15
+ #
16
+ # Centralize logging for your App. This service allows different levels e.g. info,
17
+ # debug, fatal, error etc. to log a message and query the messages based on
18
+ # different parameters.
19
+ #
20
+ # You can fetch logs based on module, level, message, date range etc.
21
+ #
22
+ # @see Log
23
+ #
24
+ class LogService
25
+ #
26
+ # this is a constructor that takes
27
+ #
28
+ # @param apiKey
29
+ # @param secretKey
30
+ # @param baseURL
31
+ #
32
+ def initialize(api_key, secret_key, base_url)
33
+ puts "LogService->initialize"
34
+ @api_key = api_key
35
+ @secret_key = secret_key
36
+ @base_url = base_url
37
+ @resource = "log"
38
+ @version = "1.0"
39
+ end
40
+
41
+ #
42
+ # Builds and Logs the message
43
+ #
44
+ # @param msg
45
+ # - Message to be logged
46
+ # @param module
47
+ # - Module name for which the message is getting logged
48
+ # @param level
49
+ # - The level on which the message is getting logged
50
+ #
51
+ # @return Log object containing logged message
52
+ #
53
+ # @throws App42Exception
54
+ #
55
+
56
+ def build_and_send(msg,appModule,level)
57
+ puts "Build and Send Called "
58
+ puts "Base url #{@base_url}"
59
+ response = nil
60
+ logObj = nil
61
+ logObj = Log.new
62
+ util = Util.new
63
+ util.throwExceptionIfNullOrBlank(msg, "Message");
64
+ util.throwExceptionIfNullOrBlank(appModule, "App Module");
65
+ util.throwExceptionIfNullOrBlank(appModule, "Level");
66
+ begin
67
+ connection = App42::Connection::RESTConnection.new(@base_url)
68
+ body = {'app42' => {"log"=> {
69
+ "message" => msg,
70
+ "appModule" => appModule
71
+ }}}.to_json
72
+ puts "Body #{body}"
73
+ query_params = Hash.new
74
+ params = {
75
+ 'apiKey'=> @api_key,
76
+ 'version' => @version,
77
+ 'timeStamp' => util.get_timestamp_utc
78
+ }
79
+ query_params = params.clone
80
+ params.store("body", body)
81
+ puts query_params
82
+ signature = util.sign(@secret_key, params)
83
+ resource_url = "#{@version}/#{@resource}/#{level}"
84
+ response = connection.post(signature, resource_url, query_params, body)
85
+ log = LogResponseBuilder.new()
86
+ logObj = log.buildResponse(response);
87
+ rescue App42Exception =>e
88
+ puts e
89
+ raise e
90
+ rescue Exception => e
91
+ puts e
92
+ raise App42Exception.new(e)
93
+ end
94
+ return logObj
95
+ end
96
+
97
+ #
98
+ # Logs the info message
99
+ #
100
+ # @param msg
101
+ # - Message to be logged
102
+ # @param module
103
+ # - Module name for which the message is getting logged
104
+ #
105
+ # @return Log object containing logged message
106
+ #
107
+ # @raise App42Exception
108
+ #
109
+
110
+ def info( msg, appModule)
111
+ return build_and_send(msg, appModule, "info");
112
+ end
113
+
114
+ #
115
+ # Logs the debug message
116
+ #
117
+ # @param msg
118
+ # - Message to be logged
119
+ # @param module
120
+ # - Module name for which the message is getting logged
121
+ #
122
+ # @return Log object containing logged message
123
+ #
124
+ # @raise App42Exception
125
+ #
126
+
127
+ def debug( msg, appModule)
128
+ return build_and_send(msg, appModule, "debug");
129
+ end
130
+
131
+ #
132
+ # Logs the fatal message
133
+ #
134
+ # @param msg
135
+ # - Message to be logged
136
+ # @param module
137
+ # - Module name for which the message is getting logged
138
+ #
139
+ # @return Log object containing logged message
140
+ #
141
+ # @raise App42Exception
142
+ #
143
+
144
+ def fatal( msg, appModule)
145
+ return build_and_send(msg, appModule, "fatal");
146
+ end
147
+
148
+ #
149
+ # Logs the error message
150
+ #
151
+ # @param msg
152
+ # - Message to be logged
153
+ # @param module
154
+ # - Module name for which the message is getting logged
155
+ #
156
+ # @return Log object containing logged message
157
+ #
158
+ # @raise App42Exception
159
+ #
160
+
161
+ def error( msg, appModule)
162
+ return build_and_send(msg, appModule, "error");
163
+ end
164
+
165
+ #
166
+ # Fetch the log messages based on the Module
167
+ #
168
+ # @param moduleName
169
+ # - Module name for which the messages has to be fetched
170
+ #
171
+ # @return Log object containing fetched messages
172
+ #
173
+ # @raise App42Exception
174
+ #
175
+
176
+ def fetch_logs_by_module(moduleName)
177
+ puts "Fetch Logs By Module Called "
178
+ puts "Base url #{@base_url}"
179
+ response = nil
180
+ logObj = nil
181
+ logObj = Log.new
182
+ util = Util.new
183
+ util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
184
+ begin
185
+ connection = App42::Connection::RESTConnection.new(@base_url)
186
+ query_params = Hash.new
187
+ params = {
188
+ 'apiKey'=> @api_key,
189
+ 'version' => @version,
190
+ 'timeStamp' => util.get_timestamp_utc,
191
+ }
192
+ query_params = params.clone
193
+ params.store("moduleName", moduleName)
194
+ puts query_params
195
+ signature = util.sign(@secret_key, params)
196
+ resource_url = "#{@version}/#{@resource}/module/#{moduleName}"
197
+ response = connection.get(signature, resource_url, query_params)
198
+ puts "Response is #{response}"
199
+ logObj = LogResponseBuilder.new().buildResponse(response);
200
+ rescue App42Exception =>e
201
+ raise e
202
+ rescue Exception => e
203
+ raise App42Exception.new(e)
204
+ end
205
+ return logObj
206
+ end
207
+
208
+ #
209
+ # Fetch the log messages based on the Module by paging.
210
+ #
211
+ # @param moduleName
212
+ # - Module name for which the messages has to be fetched
213
+ # @param max
214
+ # - Maximum number of records to be fetched
215
+ # @param offset
216
+ # - From where the records are to be fetched
217
+ #
218
+ # @return Log object containing fetched messages
219
+ #
220
+ # @raise App42Exception
221
+ #
222
+
223
+ def fetch_logs_by_module_by_paging(moduleName, max, offset)
224
+ puts "Fetch Logs By Module By Paging Called "
225
+ puts "Base url #{@base_url}"
226
+ response = nil
227
+ logObj = nil
228
+ logObj = Log.new
229
+ util = Util.new
230
+ util.validateMax(max);
231
+ util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
232
+ util.throwExceptionIfNullOrBlank(max, "Max");
233
+ util.throwExceptionIfNullOrBlank(offset, "Offset");
234
+ begin
235
+ connection = App42::Connection::RESTConnection.new(@base_url)
236
+ query_params = Hash.new
237
+ params = {
238
+ 'apiKey'=> @api_key,
239
+ 'version' => @version,
240
+ 'timeStamp' => util.get_timestamp_utc,
241
+ }
242
+ query_params = params.clone
243
+ params.store("moduleName", moduleName)
244
+ params.store("max", "" + (max.to_i).to_s)
245
+ params.store("offset", "" + (offset.to_i).to_s)
246
+ puts query_params
247
+ signature = util.sign(@secret_key, params)
248
+ resource_url = "#{@version}/#{@resource}/paging/module/#{moduleName}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
249
+ response = connection.get(signature, resource_url, query_params)
250
+ logObj = LogResponseBuilder.new().buildResponse(response);
251
+ rescue App42Exception =>e
252
+ raise e
253
+ rescue Exception => e
254
+ raise App42Exception.new(e)
255
+ end
256
+ puts logObj
257
+ return logObj
258
+ end
259
+
260
+ #
261
+ # Fetch log messages based on the Module and Message Text
262
+ #
263
+ # @param moduleName
264
+ # - Module name for which the messages has to be fetched
265
+ # @param text
266
+ # - The log message on which logs have to be searched
267
+ #
268
+ # @return Log object containing fetched messages
269
+ #
270
+ # @raise App42Exception
271
+ #
272
+
273
+ def fetch_logs_by_module_and_text(moduleName, text)
274
+ puts "Fetch Logs By Module And Text Called "
275
+ puts "Base url #{@base_url}"
276
+ response = nil
277
+ logObj = nil
278
+ logObj = Log.new
279
+ util = Util.new
280
+ util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
281
+ util.throwExceptionIfNullOrBlank(text, "Text");
282
+ begin
283
+ connection = App42::Connection::RESTConnection.new(@base_url)
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("moduleName", moduleName)
292
+ params.store("text", text)
293
+ puts query_params
294
+ signature = util.sign(@secret_key, params)
295
+ resource_url = "#{@version}/#{@resource}/module/#{moduleName}/text/#{text}"
296
+ response = connection.get(signature, resource_url, query_params)
297
+ logObj = LogResponseBuilder.new().buildResponse(response);
298
+ rescue App42Exception =>e
299
+ raise e
300
+ rescue Exception => e
301
+ raise App42Exception.new(e)
302
+ end
303
+ return logObj
304
+ end
305
+
306
+ #
307
+ # Fetch log messages based on the Module and Message Text by paging.
308
+ #
309
+ # @param moduleName
310
+ # - Module name for which the messages has to be fetched
311
+ # @param text
312
+ # - The log message on which logs have to be searched
313
+ # @param max
314
+ # - Maximum number of records to be fetched
315
+ # @param offset
316
+ # - From where the records are to be fetched
317
+ #
318
+ # @return Log object containing fetched messages
319
+ #
320
+ # @raise App42Exception
321
+ #
322
+
323
+ def fetch_logs_by_module_and_text_by_paging(moduleName, text, max, offset)
324
+ puts "Fetch Logs By Module And Text By Paging Called "
325
+ puts "Base url #{@base_url}"
326
+ response = nil
327
+ logObj = nil
328
+ logObj = Log.new
329
+ util = Util.new
330
+ util.validateMax(max);
331
+ util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
332
+ util.throwExceptionIfNullOrBlank(text, "Text");
333
+ util.throwExceptionIfNullOrBlank(max, "Max");
334
+ util.throwExceptionIfNullOrBlank(offset, "Offset");
335
+ begin
336
+ connection = App42::Connection::RESTConnection.new(@base_url)
337
+ query_params = Hash.new
338
+ params = {
339
+ 'apiKey'=> @api_key,
340
+ 'version' => @version,
341
+ 'timeStamp' => util.get_timestamp_utc,
342
+ }
343
+ query_params = params.clone
344
+ params.store("moduleName", moduleName)
345
+ params.store("text", text)
346
+ params.store("max", "" + (max.to_i).to_s)
347
+ params.store("offset", "" + (offset.to_i).to_s)
348
+ puts query_params
349
+ signature = util.sign(@secret_key, params)
350
+ resource_url = "#{@version}/#{@resource}/paging/module/#{moduleName}/text/#{text}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
351
+ response = connection.get(signature, resource_url, query_params)
352
+ logObj = LogResponseBuilder.new().buildResponse(response);
353
+ rescue App42Exception =>e
354
+ raise e
355
+ rescue Exception => e
356
+ raise App42Exception.new(e)
357
+ end
358
+ return logObj
359
+ end
360
+
361
+ #
362
+ # Fetch the log messages based on the Level
363
+ #
364
+ # @param level
365
+ # - The level on which logs have to be searched
366
+ #
367
+ # @return Log object containing fetched messages
368
+ #
369
+ # @raise App42Exception
370
+ #
371
+
372
+ def fetch_logs_by_level(level)
373
+ puts "Fetch Logs By Leve Called "
374
+ puts "Base url #{@base_url}"
375
+ response = nil
376
+ logObj = nil
377
+ logObj = Log.new
378
+ util = Util.new
379
+ util.throwExceptionIfNullOrBlank(level, "Level");
380
+ begin
381
+ connection = App42::Connection::RESTConnection.new(@base_url)
382
+ query_params = Hash.new
383
+ params = {
384
+ 'apiKey'=> @api_key,
385
+ 'version' => @version,
386
+ 'timeStamp' => util.get_timestamp_utc,
387
+ }
388
+ query_params = params.clone
389
+ params.store("type", level)
390
+ puts query_params
391
+ signature = util.sign(@secret_key, params)
392
+ resource_url = "#{@version}/#{@resource}/type/#{level}"
393
+ response = connection.get(signature, resource_url, query_params)
394
+ logObj = LogResponseBuilder.new().buildResponse(response);
395
+ rescue App42Exception =>e
396
+ raise e
397
+ rescue Exception => e
398
+ raise App42Exception.new(e)
399
+ end
400
+ return logObj
401
+ end
402
+
403
+ #
404
+ # Fetch the log messages based on the Level by paging.
405
+ #
406
+ # @param level
407
+ # - The level on which logs have to be searched
408
+ # @param max
409
+ # - Maximum number of records to be fetched
410
+ # @param offset
411
+ # - From where the records are to be fetched
412
+ #
413
+ # @return Log object containing fetched messages
414
+ #
415
+ # @raise App42Exception
416
+ #
417
+
418
+ def fetch_logs_by_level_by_paging(level, max, offset)
419
+ puts "Fetch Logs By Level By Paging Called "
420
+ puts "Base url #{@base_url}"
421
+ response = nil
422
+ logObj = nil
423
+ logObj = Log.new
424
+ util = Util.new
425
+ util.validateMax(max);
426
+ util.throwExceptionIfNullOrBlank(level, "Level");
427
+ util.throwExceptionIfNullOrBlank(max, "Max");
428
+ util.throwExceptionIfNullOrBlank(offset, "Offset");
429
+ begin
430
+ connection = App42::Connection::RESTConnection.new(@base_url)
431
+ query_params = Hash.new
432
+ params = {
433
+ 'apiKey'=> @api_key,
434
+ 'version' => @version,
435
+ 'timeStamp' => util.get_timestamp_utc,
436
+ }
437
+ query_params = params.clone
438
+ params.store("type", level)
439
+ params.store("max", "" + (max.to_i).to_s)
440
+ params.store("offset", "" + (offset.to_i).to_s)
441
+ puts query_params
442
+ signature = util.sign(@secret_key, params)
443
+ resource_url = "#{@version}/#{@resource}/paging/type/#{level}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
444
+ response = connection.get(signature, resource_url, query_params)
445
+ logObj = LogResponseBuilder.new().buildResponse(response);
446
+ rescue App42Exception =>e
447
+ raise e
448
+ rescue Exception => e
449
+ raise App42Exception.new(e)
450
+ end
451
+ return logObj
452
+ end
453
+
454
+ #
455
+ # Fetch log messages based on Info Level
456
+ #
457
+ # @return Log object containing fetched info messages
458
+ #
459
+ # @raise App42Exception
460
+ #
461
+
462
+ def fetch_logs_by_info()
463
+ return fetch_logs_by_level("INFO");
464
+ end
465
+
466
+ #
467
+ # Fetch log messages based on Info Level by paging.
468
+ #
469
+ # @param max
470
+ # - Maximum number of records to be fetched
471
+ # @param offset
472
+ # - From where the records are to be fetched
473
+ #
474
+ # @return Log object containing fetched info messages
475
+ #
476
+ # @raise App42Exception
477
+ #
478
+
479
+ def fetch_logs_by_info_by_paging(max, offset)
480
+ return fetch_logs_by_level_by_paging("INFO", max, offset);
481
+ end
482
+
483
+ #
484
+ # Fetch log messages based on Debug Level by paging.
485
+ #
486
+ # @param max
487
+ # - Maximum number of records to be fetched
488
+ # @param offset
489
+ # - From where the records are to be fetched
490
+ #
491
+ # @return Log object containing fetched debug messages
492
+ #
493
+ # @raise App42Exception
494
+ #
495
+
496
+ def fetch_logs_by_debug_by_paging(max, offset)
497
+ return fetch_logs_by_level_by_paging("DEBUG", max, offset);
498
+ end
499
+
500
+ #
501
+ # Fetch log messages based on Error Level by paging.
502
+ #
503
+ # @param max
504
+ # - Maximum number of records to be fetched
505
+ # @param offset
506
+ # - From where the records are to be fetched
507
+ #
508
+ # @return Log object containing fetched error messages
509
+ #
510
+ # @raise App42Exception
511
+ #
512
+
513
+ def fetch_logs_by_error_by_paging(max, offset)
514
+ return fetch_logs_by_level_by_paging("ERROR", max, offset);
515
+ end
516
+
517
+ #
518
+ # Fetch log messages based on Fatal Level by paging.
519
+ #
520
+ # @param max
521
+ # - Maximum number of records to be fetched
522
+ # @param offset
523
+ # - From where the records are to be fetched
524
+ #
525
+ # @return Log object containing fetched Fatal messages
526
+ #
527
+ # @raise App42Exception
528
+ #
529
+
530
+ def fetch_logs_by_fatal_by_paging(max, offset)
531
+ return fetch_logs_by_level_by_paging("FATAL", max, offset);
532
+ end
533
+
534
+ #
535
+ # Fetch log messages based on Date range by paging.
536
+ #
537
+ # @param startDate
538
+ # - Start date from which the log messages have to be fetched
539
+ # @param endDate
540
+ # - End date upto which the log messages have to be fetched
541
+ # @param max
542
+ # - Maximum number of records to be fetched
543
+ # @param offset
544
+ # - From where the records are to be fetched
545
+ #
546
+ # @return Log object containing fetched messages
547
+ #
548
+ # @raise App42Exception
549
+ #
550
+
551
+ def fetch_log_by_date_range_by_paging(startDate, endDate, max, offset)
552
+ puts "Fetch Logs By Date Range By Paging Called "
553
+ puts "Base url #{@base_url}"
554
+ response = nil
555
+ logObj = nil
556
+ logObj = Log.new
557
+ util = Util.new
558
+ util.validateMax(max);
559
+ util.throwExceptionIfNullOrBlank(max, "Max");
560
+ util.throwExceptionIfNullOrBlank(offset, "Offset");
561
+ util.throwExceptionIfNullOrBlank(startDate, "Start Date");
562
+ util.throwExceptionIfNullOrBlank(endDate, "End Date");
563
+ strStartdate = util.get_timestamp_utc_from_date(startDate)
564
+ strEnddate = util.get_timestamp_utc_from_date(endDate)
565
+ begin
566
+ connection = App42::Connection::RESTConnection.new(@base_url)
567
+ query_params = Hash.new
568
+ params = {
569
+ 'apiKey'=> @api_key,
570
+ 'version' => @version,
571
+ 'timeStamp' => util.get_timestamp_utc,
572
+ }
573
+ query_params = params.clone
574
+
575
+ strStartDate = util.get_timestamp_utc_from_date(startDate);
576
+ strEndDate = util.get_timestamp_utc_from_date(endDate);
577
+ params.store("startDate", strStartdate)
578
+ params.store("endDate", strEnddate)
579
+ params.store("max", "" + (max.to_i).to_s)
580
+ params.store("offset", "" + (offset.to_i).to_s)
581
+ puts query_params
582
+ signature = util.sign(@secret_key, params)
583
+ resource_url = "#{@version}/#{@resource}/paging/startDate/#{strStartdate}/endDate/#{strEnddate}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
584
+ response = connection.get(signature, resource_url, query_params)
585
+ logObj = LogResponseBuilder.new().buildResponse(response);
586
+ rescue App42Exception =>e
587
+ raise e
588
+ rescue Exception => e
589
+ raise App42Exception.new(e)
590
+ end
591
+ return logObj
592
+ end
593
+
594
+ #
595
+ # Fetch log messages based on Debug Level
596
+ #
597
+ # @return Log object containing fetched debug messages
598
+ #
599
+ # @raise App42Exception
600
+ #
601
+
602
+ def fetch_logs_by_debug()
603
+ return fetch_logs_by_level("DEBUG");
604
+ end
605
+
606
+ #
607
+ # Fetch log messages based on Error Level
608
+ #
609
+ # @return Log object containing fetched error messages
610
+ #
611
+ # @raise App42Exception
612
+ #
613
+
614
+ def fetch_logs_by_error()
615
+ return fetch_logs_by_level("ERROR");
616
+ end
617
+
618
+ #
619
+ # Fetch log messages based on Fatal Level
620
+ #
621
+ # @return Log object containing fetched Fatal messages
622
+ #
623
+ # @raise App42Exception
624
+ #
625
+
626
+ def fetch_logs_by_fatal()
627
+ return fetch_logs_by_level("FATAL");
628
+ end
629
+
630
+ #
631
+ # Fetch log messages based on Date range
632
+ #
633
+ # @param startDate
634
+ # - Start date from which the log messages have to be fetched
635
+ # @param endDate
636
+ # - End date upto which the log messages have to be fetched
637
+ #
638
+ # @return Log object containing fetched messages
639
+ #
640
+ # @raise App42Exception
641
+ #
642
+
643
+ def fetch_log_by_date_range(startDate, endDate)
644
+ puts "Fetch Logs By Date Range Called "
645
+ puts "Base url #{@base_url}"
646
+ response = nil
647
+ logObj = nil
648
+ logObj = Log.new
649
+ util = Util.new
650
+ util.throwExceptionIfNullOrBlank(startDate, "Start Date");
651
+ util.throwExceptionIfNullOrBlank(endDate, "End Date");
652
+ strStartdate = util.get_timestamp_utc_from_date(startDate)
653
+ strEnddate = util.get_timestamp_utc_from_date(endDate)
654
+ begin
655
+ connection = App42::Connection::RESTConnection.new(@base_url)
656
+ query_params = Hash.new
657
+ params = {
658
+ 'apiKey'=> @api_key,
659
+ 'version' => @version,
660
+ 'timeStamp' => util.get_timestamp_utc,
661
+ }
662
+ query_params = params.clone
663
+ strStartDate = util.get_timestamp_utc_from_date(startDate);
664
+ strEndDate = util.get_timestamp_utc_from_date(endDate);
665
+ params.store("startDate", strStartdate)
666
+ params.store("endDate", strEnddate)
667
+ puts query_params
668
+ signature = util.sign(@secret_key, params)
669
+ resource_url = "#{@version}/#{@resource}/startDate/#{strStartdate}/endDate/#{strEnddate}"
670
+ response = connection.get(signature, resource_url, query_params)
671
+ logObj = LogResponseBuilder.new().buildResponse(response);
672
+ rescue App42Exception =>e
673
+ raise e
674
+ rescue Exception => e
675
+ raise App42Exception.new(e)
676
+ end
677
+ return logObj
678
+ end
679
+
680
+ #
681
+ # Fetch the count of log messages based on the Module
682
+ #
683
+ # @param moduleName
684
+ # - Module name for which the count of messages has to be fetched
685
+ #
686
+ # @return App42Response object containing count of fetched messages
687
+ #
688
+ # @raise App42Exception
689
+ #
690
+
691
+ def fetch_logs_count_by_module(moduleName)
692
+ puts "Fetch Logs Count By Module Called "
693
+ puts "Base url #{@base_url}"
694
+ response = nil
695
+ responseObj = App42Response.new
696
+ util = Util.new
697
+ util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
698
+ begin
699
+ connection = App42::Connection::RESTConnection.new(@base_url)
700
+ query_params = Hash.new
701
+ params = {
702
+ 'apiKey'=> @api_key,
703
+ 'version' => @version,
704
+ 'timeStamp' => util.get_timestamp_utc,
705
+ }
706
+ query_params = params.clone
707
+ params.store("moduleName", moduleName)
708
+ puts query_params
709
+ signature = util.sign(@secret_key, params)
710
+ resource_url = "#{@version}/#{@resource}/module/#{moduleName}/count"
711
+ response = connection.get(signature, resource_url, query_params)
712
+ responseObj.strResponse=(response)
713
+ responseObj.isResponseSuccess=(true)
714
+ responseObj = LogResponseBuilder.new()
715
+ responseObj.getTotalRecords(response);
716
+ rescue App42Exception =>e
717
+ raise e
718
+ rescue Exception => e
719
+ raise App42Exception.new(e)
720
+ end
721
+ return responseObj
722
+ end
723
+
724
+ #
725
+ # Fetch count of log messages based on the Module and Message Text
726
+ #
727
+ # @param moduleName
728
+ # - Module name for which the count of messages has to be fetched
729
+ # @param text
730
+ # - The log message on which count of logs have to be searched
731
+ #
732
+ # @return App42Response object containing count of fetched messages
733
+ #
734
+ # @raise App42Exception
735
+ #
736
+
737
+ def fetch_logs_count_by_module_and_text(moduleName, text)
738
+ puts "Fetch Logs Count By Module And Text Called "
739
+ puts "Base url #{@base_url}"
740
+ response = nil
741
+ responseObj = App42Response.new
742
+ util = Util.new
743
+ util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
744
+ util.throwExceptionIfNullOrBlank(text, "Text");
745
+ begin
746
+ connection = App42::Connection::RESTConnection.new(@base_url)
747
+ query_params = Hash.new
748
+ params = {
749
+ 'apiKey'=> @api_key,
750
+ 'version' => @version,
751
+ 'timeStamp' => util.get_timestamp_utc,
752
+ }
753
+ query_params = params.clone
754
+ params.store("moduleName", moduleName)
755
+ params.store("text", text);
756
+ puts query_params
757
+ signature = util.sign(@secret_key, params)
758
+ resource_url = "#{@version}/#{@resource}/module/#{moduleName}/text/#{text}/count"
759
+ response = connection.get(signature, resource_url, query_params)
760
+ puts "Response is #{response}"
761
+ responseObj.strResponse=(response)
762
+ responseObj.isResponseSuccess=(true)
763
+ responseObj = LogResponseBuilder.new()
764
+ responseObj.getTotalRecords(response);
765
+ rescue App42Exception =>e
766
+ raise e
767
+ rescue Exception => e
768
+ raise App42Exception.new(e)
769
+ end
770
+ return responseObj
771
+ end
772
+
773
+ #
774
+ # Fetch the count of log messages based on the Level
775
+ #
776
+ # @param level
777
+ # - The level on which count of logs have to be searched
778
+ #
779
+ # @return App42Response object containing count of fetched messages
780
+ #
781
+ # @raise App42Exception
782
+ #
783
+
784
+ def fetch_logs_count_by_level(level)
785
+ puts "Fetch Logs Count By Level Called "
786
+ puts "Base url #{@base_url}"
787
+ response = nil
788
+ responseObj = App42Response.new
789
+ util = Util.new
790
+ util.throwExceptionIfNullOrBlank(level, "Level");
791
+ begin
792
+ connection = App42::Connection::RESTConnection.new(@base_url)
793
+ query_params = Hash.new
794
+ params = {
795
+ 'apiKey'=> @api_key,
796
+ 'version' => @version,
797
+ 'timeStamp' => util.get_timestamp_utc,
798
+ }
799
+ query_params = params.clone
800
+ params.store("type", level)
801
+ puts query_params
802
+ signature = util.sign(@secret_key, params)
803
+ resource_url = "#{@version}/#{@resource}/type/#{level}/count"
804
+ response = connection.get(signature, resource_url, query_params)
805
+ puts "Response is #{response}"
806
+ responseObj.strResponse=(response)
807
+ responseObj.isResponseSuccess=(true)
808
+ responseObj = LogResponseBuilder.new()
809
+ responseObj.getTotalRecords(response);
810
+ rescue App42Exception =>e
811
+ raise e
812
+ rescue Exception => e
813
+ raise App42Exception.new(e)
814
+ end
815
+ return responseObj
816
+ end
817
+
818
+ #
819
+ # Fetch count of log messages based on Info Level
820
+ #
821
+ # @return App42Response object containing count of fetched info messages
822
+ #
823
+ # @raise App42Exception
824
+ #
825
+
826
+ def fetch_logs_count_by_info()
827
+ return fetch_logs_count_by_level("INFO");
828
+ end
829
+
830
+ #
831
+ # Fetch count of log messages based on Debug Level
832
+ #
833
+ # @return App42Response object containing count of fetched debug messages
834
+ #
835
+ # @raise App42Exception
836
+ #
837
+
838
+ def fetch_logs_count_by_debug()
839
+ return fetch_logs_count_by_level("DEBUG");
840
+ end
841
+
842
+ #
843
+ # Fetch count of log messages based on Error Level
844
+ #
845
+ # @return App42Response object containing count of fetched error messages
846
+ #
847
+ # @raise App42Exception
848
+ #
849
+
850
+ def fetch_logs_count_by_error()
851
+ return fetch_logs_count_by_level("ERROR");
852
+ end
853
+
854
+ #
855
+ # Fetch count of log messages based on Fatal Level
856
+ #
857
+ # @return App42Response object containing count of fetched Fatal messages
858
+ #
859
+ # @raise App42Exception
860
+ #
861
+
862
+ def fetch_logs_count_by_fatal()
863
+ return fetch_logs_count_by_level("FATAL");
864
+ end
865
+
866
+ #
867
+ # Fetch count of log messages based on Date range
868
+ #
869
+ # @param startDate
870
+ # - Start date from which the count of log messages have to be fetched
871
+ # @param endDate
872
+ # - End date upto which the count of log messages have to be fetched
873
+ #
874
+ # @return App42Response object containing count of fetched messages
875
+ #
876
+ # @raise App42Exception
877
+ #
878
+
879
+ def fetch_logs_count_by_date_range(startDate, endDate)
880
+ puts "Fetch Logs Count By Date Range Called "
881
+ puts "Base url #{@base_url}"
882
+ response = nil
883
+ responseObj = App42Response.new
884
+ util = Util.new
885
+ util.throwExceptionIfNullOrBlank(startDate, "Start Date");
886
+ util.throwExceptionIfNullOrBlank(endDate, "End Date");
887
+ strStartdate = util.get_timestamp_utc_from_date(startDate)
888
+ strEnddate = util.get_timestamp_utc_from_date(endDate)
889
+ begin
890
+ connection = App42::Connection::RESTConnection.new(@base_url)
891
+ query_params = Hash.new
892
+ params = {
893
+ 'apiKey'=> @api_key,
894
+ 'version' => @version,
895
+ 'timeStamp' => util.get_timestamp_utc,
896
+ }
897
+ query_params = params.clone
898
+ strStartDate = util.get_timestamp_utc_from_date(startDate);
899
+ strEndDate = util.get_timestamp_utc_from_date(endDate);
900
+ params.store("startDate", strStartdate)
901
+ params.store("endDate", strEnddate)
902
+ puts query_params
903
+ signature = util.sign(@secret_key, params)
904
+ resource_url = "#{@version}/#{@resource}/startDate/#{strStartdate}/endDate/#{strEnddate}/count"
905
+ response = connection.get(signature, resource_url, query_params)
906
+ responseObj.strResponse=(response)
907
+ responseObj.isResponseSuccess=(true)
908
+ responseObj = LogResponseBuilder.new()
909
+ responseObj.getTotalRecords(response);
910
+ rescue App42Exception =>e
911
+ raise e
912
+ rescue Exception => e
913
+ raise App42Exception.new(e)
914
+ end
915
+ return responseObj
916
+ end
917
+
918
+ end
919
+ end
920
+ end