App42_Ruby_API 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/App42_Ruby_API.gemspec +33 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/TODO.rb +3 -0
- data/lib/App42_Ruby_API.rb +232 -0
- data/lib/App42_Ruby_API/App42BadParameterException.rb +31 -0
- data/lib/App42_Ruby_API/App42Exception.rb +39 -0
- data/lib/App42_Ruby_API/App42LimitException.rb +15 -0
- data/lib/App42_Ruby_API/App42NotFoundException.rb +15 -0
- data/lib/App42_Ruby_API/App42Response.rb +13 -0
- data/lib/App42_Ruby_API/App42ResponseBuilder.rb +67 -0
- data/lib/App42_Ruby_API/App42SecurityException.rb +15 -0
- data/lib/App42_Ruby_API/version.rb +3 -0
- data/lib/connection/RESTConnection.rb +713 -0
- data/lib/email/Email.rb +51 -0
- data/lib/email/EmailMIME.rb +51 -0
- data/lib/email/EmailResponseBuilder.rb +76 -0
- data/lib/email/EmailService.rb +244 -0
- data/lib/gallery/Album.rb +56 -0
- data/lib/gallery/AlbumResponseBuilder.rb +168 -0
- data/lib/gallery/AlbumService.rb +337 -0
- data/lib/gallery/PhotoService.rb +591 -0
- data/lib/game/Game.rb +39 -0
- data/lib/game/GameResponseBuilder.rb +106 -0
- data/lib/game/GameService.rb +268 -0
- data/lib/game/Reward.rb +24 -0
- data/lib/game/RewardResponseBuilder.rb +85 -0
- data/lib/game/RewardService.rb +440 -0
- data/lib/game/ScoreBoardService.rb +433 -0
- data/lib/game/ScoreService.rb +157 -0
- data/lib/geo/Geo.rb +51 -0
- data/lib/geo/GeoPoint.rb +43 -0
- data/lib/geo/GeoResponseBuilder.rb +145 -0
- data/lib/geo/GeoService.rb +505 -0
- data/lib/imageProcessor/Image.rb +42 -0
- data/lib/imageProcessor/ImageProcessorResponseBuilder.rb +40 -0
- data/lib/imageProcessor/ImageProcessorService.rb +1054 -0
- data/lib/log/Log.rb +49 -0
- data/lib/log/LogResponseBuilder.rb +61 -0
- data/lib/log/LogService.rb +920 -0
- data/lib/message/Queue.rb +50 -0
- data/lib/message/QueueResponseBuilder.rb +64 -0
- data/lib/message/QueueService.rb +469 -0
- data/lib/push/DeviceType.rb +56 -0
- data/lib/push/PushNotification.rb +38 -0
- data/lib/push/PushNotificationResposneBuilder.rb +74 -0
- data/lib/push/PushNotificationService.rb +458 -0
- data/lib/recommend/PreferenceData.rb +25 -0
- data/lib/recommend/Recommender.rb +48 -0
- data/lib/recommend/RecommenderResponseBuilder.rb +70 -0
- data/lib/recommend/RecommenderService.rb +1092 -0
- data/lib/recommend/RecommenderSimilarity.rb +52 -0
- data/lib/review/Review.rb +38 -0
- data/lib/review/ReviewResponseBuilder.rb +76 -0
- data/lib/review/ReviewService.rb +590 -0
- data/lib/session/Session.rb +43 -0
- data/lib/session/SessionResponseBuilder.rb +70 -0
- data/lib/session/SessionService.rb +427 -0
- data/lib/shopping/Cart.rb +77 -0
- data/lib/shopping/CartResponseBuilder.rb +118 -0
- data/lib/shopping/CartService.rb +902 -0
- data/lib/shopping/Catalogue.rb +79 -0
- data/lib/shopping/CatalogueResponseBuilder.rb +170 -0
- data/lib/shopping/CatalogueService.rb +649 -0
- data/lib/shopping/ItemData.rb +29 -0
- data/lib/shopping/PaymentStatus.rb +60 -0
- data/lib/social/Social.rb +35 -0
- data/lib/social/SocialResponseBuilder.rb +38 -0
- data/lib/social/SocialService.rb +585 -0
- data/lib/storage/OrderByType.rb +29 -0
- data/lib/storage/Query.rb +39 -0
- data/lib/storage/QueryBuilder.rb +118 -0
- data/lib/storage/Storage.rb +45 -0
- data/lib/storage/StorageResponseBuilder.rb +86 -0
- data/lib/storage/StorageService.rb +775 -0
- data/lib/upload/Upload.rb +40 -0
- data/lib/upload/UploadFileType.rb +83 -0
- data/lib/upload/UploadResponseBuilder.rb +58 -0
- data/lib/upload/UploadService.rb +960 -0
- data/lib/user/User.rb +102 -0
- data/lib/user/UserResponseBuilder.rb +105 -0
- data/lib/user/UserService.rb +1209 -0
- data/lib/util/util.rb +244 -0
- data/question.rb +79 -0
- metadata +204 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'App42_Ruby_API/App42Response'
|
6
|
+
|
7
|
+
module App42
|
8
|
+
module Storage
|
9
|
+
class OrderByType < App42Response
|
10
|
+
|
11
|
+
ASCENDING = "ASCENDING"
|
12
|
+
DESCENDING = "DESCENDING"
|
13
|
+
def enum(string)
|
14
|
+
return OrderByType.const_get(string)
|
15
|
+
end
|
16
|
+
|
17
|
+
def isAvailable(string)
|
18
|
+
if(string == "ASCENDING")
|
19
|
+
return "ASCENDING"
|
20
|
+
elsif(string == "DESCENDING")
|
21
|
+
return "DESCENDING";
|
22
|
+
else
|
23
|
+
return nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'App42_Ruby_API/App42Response'
|
6
|
+
|
7
|
+
module App42
|
8
|
+
module Storage
|
9
|
+
class Query < App42Response
|
10
|
+
|
11
|
+
attr_accessor :jsonObject, :jsonArray
|
12
|
+
@jsonObject
|
13
|
+
@jsonArray
|
14
|
+
def initialize(jsonQuery)
|
15
|
+
if jsonQuery.kind_of?(Hash)
|
16
|
+
self.jsonObject = jsonQuery;
|
17
|
+
else
|
18
|
+
self.jsonArray = jsonQuery;
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def getStr
|
23
|
+
if (jsonObject != nil)
|
24
|
+
return "["+jsonObject.to_s()+"]"
|
25
|
+
else
|
26
|
+
return jsonArray.to_s()
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def getType
|
31
|
+
if (jsonObject != nil)
|
32
|
+
return jsonObject
|
33
|
+
else
|
34
|
+
return jsonArray
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'App42_Ruby_API/App42Response'
|
6
|
+
require 'storage/Query'
|
7
|
+
require 'storage/OrderByType'
|
8
|
+
require 'util/util'
|
9
|
+
|
10
|
+
module App42
|
11
|
+
module Storage
|
12
|
+
class QueryBuilder
|
13
|
+
class Operator < App42Response
|
14
|
+
attr_accessor :value
|
15
|
+
@value
|
16
|
+
|
17
|
+
unless (const_defined?(:EQUALS))
|
18
|
+
EQUALS = "\$eq"
|
19
|
+
end
|
20
|
+
unless (const_defined?(:NOT_EQUALS))
|
21
|
+
NOT_EQUALS = "\$ne"
|
22
|
+
end
|
23
|
+
unless (const_defined?(:GREATER_THAN))
|
24
|
+
GREATER_THAN = "\$gt"
|
25
|
+
end
|
26
|
+
unless (const_defined?(:LESS_THAN))
|
27
|
+
LESS_THAN = "\$lt"
|
28
|
+
end
|
29
|
+
unless (const_defined?(:GREATER_THAN_EQUALTO))
|
30
|
+
GREATER_THAN_EQUALTO = "\$gte"
|
31
|
+
end
|
32
|
+
unless (const_defined?(:LESS_THAN_EQUALTO))
|
33
|
+
LESS_THAN_EQUALTO = "\$lte"
|
34
|
+
end
|
35
|
+
unless (const_defined?(:LIKE))
|
36
|
+
LIKE = "\$lk"
|
37
|
+
end
|
38
|
+
unless (const_defined?(:AND))
|
39
|
+
AND = "\$and"
|
40
|
+
end
|
41
|
+
unless (const_defined?(:OR))
|
42
|
+
OR = "\$or"
|
43
|
+
end
|
44
|
+
|
45
|
+
def enum(string)
|
46
|
+
return Operator.const_get(string)
|
47
|
+
end
|
48
|
+
|
49
|
+
def isAvailable(string)
|
50
|
+
if(string == "\$eq")
|
51
|
+
return "EQUALS"
|
52
|
+
elsif(string == "\$ne")
|
53
|
+
return "NOT_EQUALS";
|
54
|
+
elsif(string == "\$gt")
|
55
|
+
return "GREATER_THAN"
|
56
|
+
elsif(string == "\$lt")
|
57
|
+
return "LESS_THAN"
|
58
|
+
elsif(string == "\$gte")
|
59
|
+
return "GREATER_THAN_EQUALTO"
|
60
|
+
elsif(string == "\$lte")
|
61
|
+
return "LESS_THAN_EQUALTO"
|
62
|
+
elsif(string == "\$lk")
|
63
|
+
return "LIKE"
|
64
|
+
elsif(string == "\$and")
|
65
|
+
return "AND"
|
66
|
+
elsif(string == "\$or")
|
67
|
+
return "OR";
|
68
|
+
else
|
69
|
+
return nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def build(key, value, op)
|
75
|
+
|
76
|
+
query = nil
|
77
|
+
begin
|
78
|
+
jsonObj = Hash.new()
|
79
|
+
jsonObj.store("key", key);
|
80
|
+
jsonObj.store("value", value);
|
81
|
+
jsonObj.store("operator", op);
|
82
|
+
query = Query.new(jsonObj);
|
83
|
+
rescue Exception => ex
|
84
|
+
raise App42Exception.new(ex)
|
85
|
+
end
|
86
|
+
return query
|
87
|
+
end
|
88
|
+
|
89
|
+
def compoundOperator(q1, op, q2)
|
90
|
+
util = Util.new()
|
91
|
+
util.throwExceptionIfNullOrBlank(q1, "q1");
|
92
|
+
util.throwExceptionIfNullOrBlank(q2, "q2");
|
93
|
+
jsonArray = Array.new()
|
94
|
+
query = Query.new(jsonArray)
|
95
|
+
begin
|
96
|
+
if q1.getType().instance_of?(Hash)
|
97
|
+
jsonArray.push(q1.getType());
|
98
|
+
else
|
99
|
+
jsonArray.push(q1.getType());
|
100
|
+
end
|
101
|
+
jsonObj = Hash.new()
|
102
|
+
jsonObj.store("compoundOpt", op);
|
103
|
+
jsonArray.push(jsonObj);
|
104
|
+
|
105
|
+
if q2.getType().instance_of?(Hash)
|
106
|
+
jsonArray.push(q2.getType());
|
107
|
+
else
|
108
|
+
jsonArray.push(q2.getType());
|
109
|
+
end
|
110
|
+
rescue Exception => ex
|
111
|
+
raise App42Exception.new(ex)
|
112
|
+
end
|
113
|
+
return query
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'App42_Ruby_API/App42Response'
|
6
|
+
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# This Storage object is the value object which contains the properties of
|
10
|
+
# Storage.
|
11
|
+
#
|
12
|
+
#
|
13
|
+
|
14
|
+
module App42
|
15
|
+
module Storage
|
16
|
+
class Storage < App42Response
|
17
|
+
attr_accessor :dbName, :collectionName,:jsonDocList
|
18
|
+
@dbName
|
19
|
+
@collectionName
|
20
|
+
@jsonDocList = Array.new
|
21
|
+
end
|
22
|
+
|
23
|
+
class JSONDocument
|
24
|
+
attr_accessor :jsonDoc, :docId
|
25
|
+
@jsonDoc
|
26
|
+
@docId
|
27
|
+
#
|
28
|
+
# This create the constructor and takes no parameter.
|
29
|
+
#
|
30
|
+
def initialize(storage)
|
31
|
+
storage.jsonDocList.push(self);
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Returns the Storage Response in JSON format.
|
36
|
+
#
|
37
|
+
# @return the response in JSON format.
|
38
|
+
#
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
return "#{self.docId} : #{self.jsonDoc}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,86 @@
|
|
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 'storage/Storage'
|
8
|
+
require 'storage/Query'
|
9
|
+
require 'storage/OrderByType'
|
10
|
+
|
11
|
+
module App42
|
12
|
+
module Storage
|
13
|
+
#
|
14
|
+
#
|
15
|
+
# StorageResponseBuilder class converts the JSON response retrieved from the
|
16
|
+
# server to the value object i.e Storage
|
17
|
+
#
|
18
|
+
#
|
19
|
+
class StorageResponseBuilder < App42ResponseBuilder
|
20
|
+
#
|
21
|
+
# Converts the response in JSON format to the value object i.e Storage
|
22
|
+
#
|
23
|
+
# @param json
|
24
|
+
# - response in JSON format
|
25
|
+
#
|
26
|
+
# @return Storage object filled with json data
|
27
|
+
#
|
28
|
+
#
|
29
|
+
def buildResponse(json)
|
30
|
+
storageObj = Storage.new
|
31
|
+
jsonDocList = Array.new
|
32
|
+
storageObj.jsonDocList = (jsonDocList)
|
33
|
+
storageObj.strResponse = (json)
|
34
|
+
jsonObj = JSON.parse(json)
|
35
|
+
jsonObjApp42 = jsonObj["app42"]
|
36
|
+
jsonObjResponse = jsonObjApp42["response"]
|
37
|
+
storageObj.isResponseSuccess=(jsonObjResponse.fetch("success"))
|
38
|
+
jsonObjStorage = jsonObjResponse.fetch("storage");
|
39
|
+
buildObjectFromJSONTree(storageObj, jsonObjStorage);
|
40
|
+
|
41
|
+
if jsonObjStorage.key?("jsonDoc") == false
|
42
|
+
return storageObj;
|
43
|
+
end
|
44
|
+
|
45
|
+
if jsonObjStorage.fetch("jsonDoc").instance_of?(Hash)
|
46
|
+
# Only One attribute is there
|
47
|
+
|
48
|
+
jsonObjDoc = jsonObjStorage.fetch("jsonDoc");
|
49
|
+
document = App42::Storage::JSONDocument.new(storageObj)
|
50
|
+
|
51
|
+
buildJsonDocument(document, jsonObjDoc);
|
52
|
+
else
|
53
|
+
# There is an Array of attribute
|
54
|
+
|
55
|
+
jsonObjDocArray = jsonObjStorage.fetch("jsonDoc")
|
56
|
+
jsonObjDocArray.length.times do |i|
|
57
|
+
# Get Individual Attribute Node and set it into Object
|
58
|
+
jsonObjDoc = jsonObjDocArray[i]
|
59
|
+
document = App42::Storage::JSONDocument.new(storageObj)
|
60
|
+
buildJsonDocument(document, jsonObjDoc);
|
61
|
+
end
|
62
|
+
end
|
63
|
+
return storageObj
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Builds the Json Document for the storage w.r.t their docId
|
68
|
+
#
|
69
|
+
# @param document
|
70
|
+
# - document for storage
|
71
|
+
# @param jsonObjDoc
|
72
|
+
# - jsonDoc object for storage
|
73
|
+
#
|
74
|
+
|
75
|
+
def buildJsonDocument(document,jsonObjDoc)
|
76
|
+
if jsonObjDoc.fetch("_id").instance_of?(Hash)
|
77
|
+
idObj = jsonObjDoc.fetch("_id");
|
78
|
+
oIdObj = idObj.fetch("$oid")
|
79
|
+
document.docId = oIdObj
|
80
|
+
jsonObjDoc.delete("_id")
|
81
|
+
document.jsonDoc = jsonObjDoc.to_s
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,775 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'connection/RESTConnection'
|
6
|
+
require 'util/util'
|
7
|
+
require 'json/pure'
|
8
|
+
require 'storage/StorageResponseBuilder'
|
9
|
+
require 'storage/Storage'
|
10
|
+
require 'storage/Query'
|
11
|
+
require 'storage/QueryBuilder'
|
12
|
+
require 'storage/OrderByType'
|
13
|
+
|
14
|
+
module App42
|
15
|
+
module Storage
|
16
|
+
#
|
17
|
+
# Storage service on cloud provides the way to store the JSON document in NoSQL database running on cloud.
|
18
|
+
# One can store the JSON document, update it , search it and can apply the map-reduce search on stored documents.
|
19
|
+
# Example : If one will store JSON doc {"date":"5Feb"} it will be stored with unique Object Id and stored JSON object will look like
|
20
|
+
# { "date" : "5Feb" , "_id" : { "$oid" : "4f423dcce1603b3f0bd560cf"}}. This oid can further be used to access/search the document.
|
21
|
+
#
|
22
|
+
# @see Storage
|
23
|
+
#
|
24
|
+
# @see App42Response
|
25
|
+
#
|
26
|
+
class StorageService
|
27
|
+
#
|
28
|
+
# this is a constructor that takes
|
29
|
+
#
|
30
|
+
# @param apiKey
|
31
|
+
# @param secretKey
|
32
|
+
# @param baseURL
|
33
|
+
#
|
34
|
+
def initialize(api_key, secret_key, base_url)
|
35
|
+
puts "StorageService->initialize"
|
36
|
+
@api_key = api_key
|
37
|
+
@secret_key = secret_key
|
38
|
+
@base_url = base_url
|
39
|
+
@resource = "storage"
|
40
|
+
@version = "1.0"
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Save the JSON document in given database name and collection name.
|
45
|
+
#
|
46
|
+
# @param dbName
|
47
|
+
# - Unique handler for storage name
|
48
|
+
# @param collectionName
|
49
|
+
# - Name of collection under which JSON doc has to be saved.
|
50
|
+
# @param json
|
51
|
+
# - Target JSON document to be saved
|
52
|
+
#
|
53
|
+
# @return Storage object
|
54
|
+
#
|
55
|
+
# @raise App42Exception
|
56
|
+
#
|
57
|
+
|
58
|
+
def insert_json_document(dbName, collectionName, json)
|
59
|
+
puts "Create Insert JSON Document Called "
|
60
|
+
puts "Base url #{@base_url}"
|
61
|
+
response = nil
|
62
|
+
storage = nil
|
63
|
+
storage = Storage.new
|
64
|
+
util = Util.new
|
65
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName")
|
66
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName")
|
67
|
+
util.throwExceptionIfNullOrBlank(json, "Json")
|
68
|
+
begin
|
69
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
70
|
+
body = {'app42' => {"storage"=> {
|
71
|
+
"jsonDoc" => json
|
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
|
+
params.store("dbName", dbName)
|
81
|
+
params.store("collectionName", collectionName)
|
82
|
+
query_params = params.clone
|
83
|
+
params.store("body", body)
|
84
|
+
signature = util.sign(@secret_key, params)
|
85
|
+
resource_url = "#{@version}/#{@resource}/insert/dbName/#{dbName}/collectionName/#{collectionName}"
|
86
|
+
response = connection.post(signature, resource_url, query_params, body)
|
87
|
+
storageObj = StorageResponseBuilder.new
|
88
|
+
storage = storageObj.buildResponse(response)
|
89
|
+
rescue App42Exception => e
|
90
|
+
raise e
|
91
|
+
rescue Exception => e
|
92
|
+
raise App42Exception.new(e)
|
93
|
+
end
|
94
|
+
return storage
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Find all documents stored in given database and collection.
|
99
|
+
#
|
100
|
+
# @param dbName
|
101
|
+
# - Unique handler for storage name
|
102
|
+
# @param collectionName
|
103
|
+
# - Name of collection under which JSON doc needs to be searched.
|
104
|
+
#
|
105
|
+
# @return Storage object
|
106
|
+
#
|
107
|
+
# @raise App42Exception
|
108
|
+
#
|
109
|
+
|
110
|
+
def find_all_documents(dbName, collectionName)
|
111
|
+
puts "Find All Documents Called "
|
112
|
+
puts "Base url #{@base_url}"
|
113
|
+
response = nil
|
114
|
+
storage = nil
|
115
|
+
storage = Storage.new()
|
116
|
+
util = Util.new
|
117
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName");
|
118
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName");
|
119
|
+
begin
|
120
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
121
|
+
query_params = Hash.new
|
122
|
+
params = {
|
123
|
+
'apiKey'=> @api_key,
|
124
|
+
'version' => @version,
|
125
|
+
'timeStamp' => util.get_timestamp_utc,
|
126
|
+
}
|
127
|
+
query_params = params.clone
|
128
|
+
params.store("dbName", dbName)
|
129
|
+
params.store("collectionName", collectionName)
|
130
|
+
signature = util.sign(@secret_key, params)
|
131
|
+
resource_url = "#{@version}/#{@resource}/findAll/dbName/#{dbName}/collectionName/#{collectionName}"
|
132
|
+
response = connection.get(signature, resource_url, query_params)
|
133
|
+
storage = StorageResponseBuilder.new().buildResponse(response);
|
134
|
+
rescue App42Exception =>e
|
135
|
+
raise e
|
136
|
+
rescue Exception => e
|
137
|
+
raise App42Exception.new(e)
|
138
|
+
end
|
139
|
+
return storage
|
140
|
+
end
|
141
|
+
|
142
|
+
#
|
143
|
+
# Gets the count of all documents stored in given database and collection.
|
144
|
+
#
|
145
|
+
# @param dbName
|
146
|
+
# - Unique handler for storage name
|
147
|
+
# @param collectionName
|
148
|
+
# - Name of collection under which JSON doc needs to be searched.
|
149
|
+
#
|
150
|
+
# @return App42Response object
|
151
|
+
#
|
152
|
+
# @raise App42Exception
|
153
|
+
#
|
154
|
+
|
155
|
+
def find_all_documents_count(dbName, collectionName)
|
156
|
+
puts "Find All Documents Count Called "
|
157
|
+
puts "Base url #{@base_url}"
|
158
|
+
response = nil;
|
159
|
+
responseObj = App42Response.new();
|
160
|
+
util = Util.new
|
161
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName");
|
162
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName");
|
163
|
+
begin
|
164
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
165
|
+
query_params = Hash.new
|
166
|
+
params = {
|
167
|
+
'apiKey'=> @api_key,
|
168
|
+
'version' => @version,
|
169
|
+
'timeStamp' => util.get_timestamp_utc,
|
170
|
+
}
|
171
|
+
query_params = params.clone
|
172
|
+
params.store("dbName", dbName)
|
173
|
+
params.store("collectionName", collectionName)
|
174
|
+
signature = util.sign(@secret_key, params)
|
175
|
+
resource_url = "#{@version}/#{@resource}/findAll/count/dbName/#{dbName}/collectionName/#{collectionName}"
|
176
|
+
response = connection.get(signature, resource_url, query_params)
|
177
|
+
responseObj.strResponse=(response)
|
178
|
+
responseObj.isResponseSuccess=(true)
|
179
|
+
responseObj = StorageResponseBuilder.new()
|
180
|
+
responseObj.getTotalRecords(response);
|
181
|
+
rescue App42Exception =>e
|
182
|
+
raise e
|
183
|
+
rescue Exception => e
|
184
|
+
raise App42Exception.new(e)
|
185
|
+
end
|
186
|
+
return responseObj
|
187
|
+
end
|
188
|
+
|
189
|
+
#
|
190
|
+
# Find all documents stored in given database and collection.
|
191
|
+
#
|
192
|
+
# @param dbName
|
193
|
+
# - Unique handler for storage name
|
194
|
+
# @param collectionName
|
195
|
+
# - Name of collection under which JSON doc needs to be searched.
|
196
|
+
# @param max
|
197
|
+
# - Maximum number of records to be fetched
|
198
|
+
# @param offset
|
199
|
+
# - From where the records are to be fetched
|
200
|
+
#
|
201
|
+
# @return Storage object
|
202
|
+
#
|
203
|
+
# @raise App42Exception
|
204
|
+
#
|
205
|
+
|
206
|
+
def find_all_documents_by_paging(dbName, collectionName, max, offset)
|
207
|
+
puts "Find All Documents Called "
|
208
|
+
puts "Base url #{@base_url}"
|
209
|
+
response = nil
|
210
|
+
storageObj = nil
|
211
|
+
storageObj = Storage.new()
|
212
|
+
util = Util.new
|
213
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName");
|
214
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName");
|
215
|
+
begin
|
216
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
217
|
+
query_params = Hash.new
|
218
|
+
params = {
|
219
|
+
'apiKey'=> @api_key,
|
220
|
+
'version' => @version,
|
221
|
+
'timeStamp' => util.get_timestamp_utc,
|
222
|
+
}
|
223
|
+
query_params = params.clone
|
224
|
+
params.store("dbName", dbName)
|
225
|
+
params.store("collectionName", collectionName)
|
226
|
+
params.store("max", "" + (max.to_i).to_s);
|
227
|
+
params.store("offset", "" + (offset.to_i).to_s);
|
228
|
+
signature = util.sign(@secret_key, params)
|
229
|
+
resource_url = "#{@version}/#{@resource}/findAll/dbName/#{dbName}/collectionName/#{collectionName}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
|
230
|
+
response = connection.get(signature, resource_url, query_params)
|
231
|
+
storageObj = StorageResponseBuilder.new().buildResponse(response);
|
232
|
+
rescue App42Exception =>e
|
233
|
+
raise e
|
234
|
+
rescue Exception => e
|
235
|
+
raise App42Exception.new(e)
|
236
|
+
end
|
237
|
+
return storageObj
|
238
|
+
end
|
239
|
+
|
240
|
+
#
|
241
|
+
# Find target document by given unique object id.
|
242
|
+
#
|
243
|
+
# @param dbName
|
244
|
+
# - Unique handler for storage name
|
245
|
+
# @param collectionName
|
246
|
+
# - Name of collection under which JSON doc needs to be searched.
|
247
|
+
# @param docId
|
248
|
+
# - Unique Object Id handler.
|
249
|
+
#
|
250
|
+
# @return Storage object
|
251
|
+
#
|
252
|
+
# @raise App42Exception
|
253
|
+
#
|
254
|
+
|
255
|
+
def find_document_by_id(dbName, collectionName, docId)
|
256
|
+
puts "Final Document By ID Called "
|
257
|
+
puts "Base url #{@base_url}"
|
258
|
+
response = nil
|
259
|
+
storage = nil
|
260
|
+
storage = Storage.new
|
261
|
+
util = Util.new
|
262
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName");
|
263
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName");
|
264
|
+
util.throwExceptionIfNullOrBlank(docId, "DocumentId");
|
265
|
+
begin
|
266
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
267
|
+
query_params = Hash.new
|
268
|
+
params = {
|
269
|
+
'apiKey'=> @api_key,
|
270
|
+
'version' => @version,
|
271
|
+
'timeStamp' => util.get_timestamp_utc,
|
272
|
+
}
|
273
|
+
query_params = params.clone
|
274
|
+
params.store("dbName", dbName)
|
275
|
+
params.store("collectionName", collectionName)
|
276
|
+
params.store("docId", docId)
|
277
|
+
signature = util.sign(@secret_key, params)
|
278
|
+
resource_url = "#{@version}/#{@resource}/findDocById/dbName/#{dbName}/collectionName/#{collectionName}/docId/#{docId}"
|
279
|
+
response = connection.get(signature, resource_url, query_params)
|
280
|
+
storage = StorageResponseBuilder.new().buildResponse(response);
|
281
|
+
rescue App42Exception =>e
|
282
|
+
raise e
|
283
|
+
rescue Exception => e
|
284
|
+
raise App42Exception.new(e)
|
285
|
+
end
|
286
|
+
return storage
|
287
|
+
end
|
288
|
+
|
289
|
+
#
|
290
|
+
# Find target document using key value search parameter.
|
291
|
+
# This key value pair will be searched in the JSON doc stored on the cloud and matching Doc will be returned as a result of this method.
|
292
|
+
#
|
293
|
+
# @param dbName
|
294
|
+
# - Unique handler for storage name
|
295
|
+
# @param collectionName
|
296
|
+
# - Name of collection under which JSON doc needs to be searched.
|
297
|
+
# @param key
|
298
|
+
# - Key to be searched for target JSON doc.
|
299
|
+
# @param value
|
300
|
+
# - Value to be searched for target JSON doc.
|
301
|
+
#
|
302
|
+
# @return Storage object
|
303
|
+
#
|
304
|
+
# @raise App42Exception
|
305
|
+
#
|
306
|
+
|
307
|
+
def find_document_by_key_value(dbName, collectionName, key, value)
|
308
|
+
puts "Find Document By Key Value Called"
|
309
|
+
puts "Base url #{@base_url}"
|
310
|
+
response = nil
|
311
|
+
storage = nil
|
312
|
+
storage = Storage.new
|
313
|
+
util = Util.new
|
314
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName");
|
315
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName");
|
316
|
+
util.throwExceptionIfNullOrBlank(key, "Key");
|
317
|
+
util.throwExceptionIfNullOrBlank(value, "Value");
|
318
|
+
begin
|
319
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
320
|
+
query_params = Hash.new
|
321
|
+
params = {
|
322
|
+
'apiKey'=> @api_key,
|
323
|
+
'version' => @version,
|
324
|
+
'timeStamp' => util.get_timestamp_utc,
|
325
|
+
}
|
326
|
+
query_params = params.clone
|
327
|
+
params.store("dbName", dbName)
|
328
|
+
params.store("collectionName", collectionName)
|
329
|
+
params.store("key", key)
|
330
|
+
params.store("value", value)
|
331
|
+
puts query_params
|
332
|
+
signature = util.sign(@secret_key, params)
|
333
|
+
resource_url = "#{@version}/#{@resource}/findDocByKV/dbName/#{dbName}/collectionName/#{collectionName}/#{key}/#{value}"
|
334
|
+
response = connection.get(signature, resource_url, query_params)
|
335
|
+
storage = StorageResponseBuilder.new().buildResponse(response);
|
336
|
+
rescue App42Exception =>e
|
337
|
+
raise e
|
338
|
+
rescue Exception => e
|
339
|
+
raise App42Exception.new(e)
|
340
|
+
end
|
341
|
+
return storage
|
342
|
+
end
|
343
|
+
|
344
|
+
#
|
345
|
+
# Update target document using key value search parameter.
|
346
|
+
#
|
347
|
+
# This key value pair will be searched in the JSON doc stored in the cloud and matching Doc will be updated with new value passed.
|
348
|
+
#
|
349
|
+
# @param dbName
|
350
|
+
# - Unique handler for storage name
|
351
|
+
# @param collectionName
|
352
|
+
# - Name of collection under which JSON doc needs to be searched.
|
353
|
+
# @param key
|
354
|
+
# - Key to be searched for target JSON doc.
|
355
|
+
# @param value
|
356
|
+
# - Value to be searched for target JSON doc.
|
357
|
+
# @param newJsonDoc
|
358
|
+
# - New Json document to be added.
|
359
|
+
#
|
360
|
+
# @return Storage object
|
361
|
+
#
|
362
|
+
# @raise App42Exception
|
363
|
+
#
|
364
|
+
|
365
|
+
def update_document_by_key_value(dbName, collectionName, key, value, newJsonDoc)
|
366
|
+
puts "Update Document By Key Value Called"
|
367
|
+
puts "Base url #{@base_url}"
|
368
|
+
response = nil
|
369
|
+
storageObj = nil
|
370
|
+
storageObj = Storage.new
|
371
|
+
util = Util.new
|
372
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName");
|
373
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName");
|
374
|
+
util.throwExceptionIfNullOrBlank(key, "Key");
|
375
|
+
util.throwExceptionIfNullOrBlank(value, "Value");
|
376
|
+
util.throwExceptionIfNullOrBlank(newJsonDoc, "NewJsonDocument");
|
377
|
+
begin
|
378
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
379
|
+
body = {'app42' => {"storage"=> {
|
380
|
+
"jsonDoc" => newJsonDoc
|
381
|
+
}}}.to_json
|
382
|
+
puts "Body #{body}"
|
383
|
+
query_params = Hash.new
|
384
|
+
params = {
|
385
|
+
'apiKey'=> @api_key,
|
386
|
+
'version' => @version,
|
387
|
+
'timeStamp' => util.get_timestamp_utc,
|
388
|
+
}
|
389
|
+
query_params = params.clone
|
390
|
+
params.store("body", body)
|
391
|
+
params.store("dbName", dbName)
|
392
|
+
params.store("collectionName", collectionName)
|
393
|
+
params.store("key", key)
|
394
|
+
params.store("value", value)
|
395
|
+
puts query_params
|
396
|
+
signature = util.sign(@secret_key, params)
|
397
|
+
resource_url = "#{@version}/#{@resource}/update/dbName/#{dbName}/collectionName/#{collectionName}/#{key}/#{value}"
|
398
|
+
response = connection.put(signature, resource_url, query_params,body)
|
399
|
+
storage = StorageResponseBuilder.new().buildResponse(response);
|
400
|
+
rescue App42Exception =>e
|
401
|
+
raise e
|
402
|
+
rescue Exception => e
|
403
|
+
raise App42Exception.new(e)
|
404
|
+
end
|
405
|
+
return storage
|
406
|
+
end
|
407
|
+
|
408
|
+
#
|
409
|
+
# Delete target document using Object Id from given db and collection.
|
410
|
+
# The Object Id will be searched in the JSON doc stored on the cloud and matching Doc will be deleted.
|
411
|
+
#
|
412
|
+
# @param dbName
|
413
|
+
# - Unique handler for storage name
|
414
|
+
# @param collectionName
|
415
|
+
# - Name of collection under which JSON doc needs to be searched.
|
416
|
+
# @param docId
|
417
|
+
# - Unique Object Id handler.
|
418
|
+
#
|
419
|
+
# @return App42Response object if deleted successfully
|
420
|
+
#
|
421
|
+
# @raise App42Exception
|
422
|
+
#
|
423
|
+
|
424
|
+
def delete_document_by_id(dbName, collectionName, docId)
|
425
|
+
puts "Delete Document By ID Called "
|
426
|
+
puts "Base url #{@base_url}"
|
427
|
+
response = nil
|
428
|
+
responseObj = App42Response.new();
|
429
|
+
util = Util.new
|
430
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName");
|
431
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName");
|
432
|
+
util.throwExceptionIfNullOrBlank(docId, "DocumentId");
|
433
|
+
begin
|
434
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
435
|
+
util = Util.new
|
436
|
+
query_params = Hash.new
|
437
|
+
params = {
|
438
|
+
'apiKey'=> @api_key,
|
439
|
+
'version' => @version,
|
440
|
+
'timeStamp' => util.get_timestamp_utc,
|
441
|
+
}
|
442
|
+
query_params = params.clone
|
443
|
+
puts params
|
444
|
+
params.store("dbName", dbName)
|
445
|
+
params.store("collectionName", collectionName)
|
446
|
+
params.store("docId", docId)
|
447
|
+
puts query_params
|
448
|
+
signature = util.sign(@secret_key, params)
|
449
|
+
resource_url = "#{@version}/#{@resource}/deleteDocById/dbName/#{dbName}/collectionName/#{collectionName}/docId/#{docId}"
|
450
|
+
response = connection.delete(signature, resource_url, query_params)
|
451
|
+
responseObj.strResponse=(response)
|
452
|
+
responseObj.isResponseSuccess=(true)
|
453
|
+
rescue App42Exception =>e
|
454
|
+
raise e
|
455
|
+
rescue Exception => e
|
456
|
+
raise App42Exception.new(e)
|
457
|
+
end
|
458
|
+
return responseObj
|
459
|
+
end
|
460
|
+
|
461
|
+
#
|
462
|
+
# @param map
|
463
|
+
#
|
464
|
+
# @return
|
465
|
+
#
|
466
|
+
|
467
|
+
def get_json_from_map(map)
|
468
|
+
return map.to_json
|
469
|
+
end
|
470
|
+
|
471
|
+
#
|
472
|
+
# Save the JSON document in given database name and collection name. It accepts the HashMap containing key-value and convert it into JSON.
|
473
|
+
# Converted JSON doc further saved on the cloud using given db name and collection name.
|
474
|
+
#
|
475
|
+
# @param dbName
|
476
|
+
# - Unique handler for storage name
|
477
|
+
# @param collectionName
|
478
|
+
# - Name of collection under which JSON doc has to be saved.
|
479
|
+
# @param map
|
480
|
+
# - HashMap containing key-value pairs
|
481
|
+
#
|
482
|
+
# @return Storage object
|
483
|
+
#
|
484
|
+
# @raise App42Exception
|
485
|
+
#
|
486
|
+
|
487
|
+
def insert_json_doc_using_map(dbName,collectionName,map)
|
488
|
+
puts "insert_json_doc_using_map Called "
|
489
|
+
puts "Base url #{@base_url}"
|
490
|
+
jsonBody = get_json_from_map(map);
|
491
|
+
return insert_json_document(dbName, collectionName, jsonBody)
|
492
|
+
end
|
493
|
+
|
494
|
+
#
|
495
|
+
# Map reduce function to search the target document.
|
496
|
+
#
|
497
|
+
# Please see detail information on map-reduce http://en.wikipedia.org/wiki/MapReduce
|
498
|
+
#
|
499
|
+
# @param dbName
|
500
|
+
# - Unique handler for storage name
|
501
|
+
# @param collectionName
|
502
|
+
# - Name of collection under which JSON doc needs to be searched.
|
503
|
+
# @param mapFunction
|
504
|
+
# - Map function to be used to search the document
|
505
|
+
# @param reduceFunction
|
506
|
+
# - Reduce function to be used to search the document
|
507
|
+
#
|
508
|
+
# @return Returns the target JSON document.
|
509
|
+
#
|
510
|
+
# @raise App42Exception
|
511
|
+
#
|
512
|
+
|
513
|
+
def map_reduce(dbName,collectionName,mapFunction,reduceFunction)
|
514
|
+
response = nil
|
515
|
+
util = Util.new
|
516
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName");
|
517
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName");
|
518
|
+
util.throwExceptionIfNullOrBlank(mapFunction, "MapFunction");
|
519
|
+
util.throwExceptionIfNullOrBlank(reduceFunction, "ReduceFunction");
|
520
|
+
begin
|
521
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
522
|
+
body = {'app42' => {"storage"=> {
|
523
|
+
"map" => mapFunction,
|
524
|
+
"reduce" => reduceFunction
|
525
|
+
}}}.to_json
|
526
|
+
query_params = Hash.new
|
527
|
+
params = {
|
528
|
+
'apiKey'=> @api_key,
|
529
|
+
'version' => @version,
|
530
|
+
'timeStamp' => util.get_timestamp_utc,
|
531
|
+
}
|
532
|
+
params.store("dbName", dbName)
|
533
|
+
params.store("collectionName", collectionName)
|
534
|
+
query_params = params.clone
|
535
|
+
params.store("body", body)
|
536
|
+
signature = util.sign(@secret_key, params)
|
537
|
+
resource_url = "#{@version}/#{@resource}/mapReduce/dbName/#{dbName}/collectionName/#{collectionName}"
|
538
|
+
response = connection.post(signature, resource_url, query_params, body)
|
539
|
+
rescue App42Exception =>e
|
540
|
+
raise e
|
541
|
+
rescue Exception => e
|
542
|
+
raise App42Exception.new(e)
|
543
|
+
end
|
544
|
+
return response
|
545
|
+
end
|
546
|
+
|
547
|
+
#
|
548
|
+
# Update target document using the document id.
|
549
|
+
#
|
550
|
+
# @param dbName
|
551
|
+
# - Unique handler for storage name
|
552
|
+
# @param collectionName
|
553
|
+
# - Name of collection under which JSON doc needs to be searched.
|
554
|
+
# @param docId
|
555
|
+
# - Id of the document to be searched for target JSON doc.
|
556
|
+
# @param newJsonDoc
|
557
|
+
# - New Json document to be added.
|
558
|
+
#
|
559
|
+
# @return Storage object
|
560
|
+
#
|
561
|
+
# @raise App42Exception
|
562
|
+
#
|
563
|
+
|
564
|
+
def update_document_by_doc_id(dbName, collectionName, docId, newJsonDoc)
|
565
|
+
puts "Update Document By Document Id Called "
|
566
|
+
puts "Base url #{@base_url}"
|
567
|
+
response = nil
|
568
|
+
storage = nil
|
569
|
+
storage = Storage.new
|
570
|
+
util = Util.new
|
571
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName")
|
572
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName")
|
573
|
+
util.throwExceptionIfNullOrBlank(docId, "DocId");
|
574
|
+
util.throwExceptionIfNullOrBlank(newJsonDoc, "NewJsonDocument");
|
575
|
+
begin
|
576
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
577
|
+
body = {'app42' => {"storage"=> {
|
578
|
+
"jsonDoc" => newJsonDoc
|
579
|
+
}}}.to_json
|
580
|
+
puts "Body #{body}"
|
581
|
+
query_params = Hash.new
|
582
|
+
params = {
|
583
|
+
'apiKey'=> @api_key,
|
584
|
+
'version' => @version,
|
585
|
+
'timeStamp' => util.get_timestamp_utc
|
586
|
+
}
|
587
|
+
params.store("body", body)
|
588
|
+
params.store("docId", docId)
|
589
|
+
params.store("dbName", dbName)
|
590
|
+
params.store("collectionName", collectionName)
|
591
|
+
query_params = params.clone
|
592
|
+
signature = util.sign(@secret_key, params)
|
593
|
+
resource_url = "#{@version}/#{@resource}/updateByDocId/dbName/#{dbName}/collectionName/#{collectionName}/docId/#{docId}"
|
594
|
+
response = connection.put(signature, resource_url, query_params, body)
|
595
|
+
storageObj = StorageResponseBuilder.new
|
596
|
+
storage = storageObj.buildResponse(response)
|
597
|
+
rescue App42Exception =>e
|
598
|
+
raise e
|
599
|
+
rescue Exception => e
|
600
|
+
raise App42Exception.new(e)
|
601
|
+
end
|
602
|
+
return storage
|
603
|
+
end
|
604
|
+
|
605
|
+
#
|
606
|
+
# Find target document using Custom Query.
|
607
|
+
#
|
608
|
+
# @param dbName
|
609
|
+
# - Unique handler for storage name
|
610
|
+
# @param collectionName
|
611
|
+
# - Name of collection under which JSON doc needs to be searched
|
612
|
+
# @param Query
|
613
|
+
# - Query Object containing custom query for searching docs
|
614
|
+
#
|
615
|
+
# @return Storage object
|
616
|
+
#
|
617
|
+
# @raise App42Exception
|
618
|
+
#
|
619
|
+
|
620
|
+
def find_document_by_query(dbName, collectionName, query)
|
621
|
+
puts "find_document_by_query Called "
|
622
|
+
puts "Base url #{@base_url}"
|
623
|
+
response = nil
|
624
|
+
storageObj = nil
|
625
|
+
storageObj = Storage.new()
|
626
|
+
util = Util.new
|
627
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName");
|
628
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName");
|
629
|
+
util.throwExceptionIfNullOrBlank(query, "query");
|
630
|
+
begin
|
631
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
632
|
+
query_params = Hash.new
|
633
|
+
params = {
|
634
|
+
'apiKey'=> @api_key,
|
635
|
+
'version' => @version,
|
636
|
+
'timeStamp' => util.get_timestamp_utc,
|
637
|
+
'jsonQuery' => query.getStr()
|
638
|
+
}
|
639
|
+
params.store("dbName", dbName);
|
640
|
+
params.store("collectionName", collectionName);
|
641
|
+
query_params = params.clone
|
642
|
+
signature = util.sign(@secret_key, params)
|
643
|
+
resource_url = "#{@version}/#{@resource}/findDocsByQuery/dbName/#{dbName}/collectionName/#{collectionName}"
|
644
|
+
response = connection.get(signature, resource_url, query_params)
|
645
|
+
storage = StorageResponseBuilder.new
|
646
|
+
storageObj = storage.buildResponse(response)
|
647
|
+
rescue App42Exception =>e
|
648
|
+
raise e
|
649
|
+
rescue Exception => e
|
650
|
+
raise App42Exception.new(e)
|
651
|
+
end
|
652
|
+
return storageObj
|
653
|
+
end
|
654
|
+
|
655
|
+
#
|
656
|
+
# Find target document using Custom Query with paging.
|
657
|
+
#
|
658
|
+
# @param dbName
|
659
|
+
# - Unique handler for storage name
|
660
|
+
# @param collectionName
|
661
|
+
# - Name of collection under which JSON doc needs to be searched
|
662
|
+
# @param Query
|
663
|
+
# - Query Object containing custom query for searching docs
|
664
|
+
# @param max
|
665
|
+
# - max result parameter
|
666
|
+
# @param offset
|
667
|
+
# - offset result parameter
|
668
|
+
#
|
669
|
+
# @return Storage object
|
670
|
+
#
|
671
|
+
# @raise App42Exception
|
672
|
+
#
|
673
|
+
|
674
|
+
def find_documents_by_query_with_paging(dbName, collectionName, query, max, offset)
|
675
|
+
puts "findDocumentsByQueryWithPaging Called "
|
676
|
+
puts "Base url #{@base_url}"
|
677
|
+
response = nil
|
678
|
+
storageObj = nil
|
679
|
+
storageObj = Storage.new()
|
680
|
+
util = Util.new
|
681
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName");
|
682
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName");
|
683
|
+
util.throwExceptionIfNullOrBlank(query, "query");
|
684
|
+
begin
|
685
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
686
|
+
query_params = Hash.new
|
687
|
+
params = {
|
688
|
+
'apiKey'=> @api_key,
|
689
|
+
'version' => @version,
|
690
|
+
'timeStamp' => util.get_timestamp_utc,
|
691
|
+
'jsonQuery' => query.getStr()
|
692
|
+
}
|
693
|
+
params.store("dbName", dbName);
|
694
|
+
params.store("collectionName", collectionName);
|
695
|
+
params.store("max", "" + (max.to_i).to_s)
|
696
|
+
params.store("offset", "" + (offset.to_i).to_s)
|
697
|
+
query_params = params.clone
|
698
|
+
signature = util.sign(@secret_key, params)
|
699
|
+
resource_url = "#{@version}/#{@resource}/findDocsByQuery/dbName/#{dbName}/collectionName/#{collectionName}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
|
700
|
+
response = connection.get(signature, resource_url, query_params)
|
701
|
+
storage = StorageResponseBuilder.new
|
702
|
+
storageObj = storage.buildResponse(response)
|
703
|
+
rescue App42Exception =>e
|
704
|
+
raise e
|
705
|
+
rescue Exception => e
|
706
|
+
raise App42Exception.new(e)
|
707
|
+
end
|
708
|
+
return storageObj
|
709
|
+
end
|
710
|
+
|
711
|
+
#
|
712
|
+
# Find target document using Custom Query with paging and orderby.
|
713
|
+
#
|
714
|
+
# @param dbName
|
715
|
+
# - Unique handler for storage name
|
716
|
+
# @param collectionName
|
717
|
+
# - Name of collection under which JSON doc needs to be searched
|
718
|
+
# @param Query
|
719
|
+
# - Query Object containing custom query for searching docs
|
720
|
+
# @param max
|
721
|
+
# - max result parameter
|
722
|
+
# @param offset
|
723
|
+
# - offset result parameter
|
724
|
+
#
|
725
|
+
# @return Storage object
|
726
|
+
#
|
727
|
+
# @raise App42Exception
|
728
|
+
#
|
729
|
+
|
730
|
+
def find_docs_with_query_paging_order_by(dbName, collectionName, query, max, offset, orderByKey, type)
|
731
|
+
puts "findDocsWithQueryPagingOrderBy Called "
|
732
|
+
puts "Base url #{@base_url}"
|
733
|
+
response = nil
|
734
|
+
storageObj = nil
|
735
|
+
storageObj = Storage.new()
|
736
|
+
util = Util.new
|
737
|
+
util.throwExceptionIfNullOrBlank(dbName, "DataBaseName");
|
738
|
+
util.throwExceptionIfNullOrBlank(collectionName, "CollectionName");
|
739
|
+
util.throwExceptionIfNullOrBlank(query, "query");
|
740
|
+
begin
|
741
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
742
|
+
query_params = Hash.new
|
743
|
+
params = {
|
744
|
+
'apiKey'=> @api_key,
|
745
|
+
'version' => @version,
|
746
|
+
'timeStamp' => util.get_timestamp_utc,
|
747
|
+
'jsonQuery' => query.getStr()
|
748
|
+
}
|
749
|
+
if (orderByKey != nil)
|
750
|
+
query_params.store("orderByKey", orderByKey);
|
751
|
+
end
|
752
|
+
if (type != nil)
|
753
|
+
query_params.store("orderByType", type);
|
754
|
+
end
|
755
|
+
params.store("dbName", dbName);
|
756
|
+
params.store("collectionName", collectionName);
|
757
|
+
params.store("max", "" + (max.to_i).to_s)
|
758
|
+
params.store("offset", "" + (offset.to_i).to_s)
|
759
|
+
query_params = params.clone
|
760
|
+
signature = util.sign(@secret_key, params)
|
761
|
+
resource_url = "#{@version}/#{@resource}/findDocsByQuery/dbName/#{dbName}/collectionName/#{collectionName}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
|
762
|
+
response = connection.get(signature, resource_url, query_params)
|
763
|
+
storage = StorageResponseBuilder.new
|
764
|
+
storageObj = storage.buildResponse(response)
|
765
|
+
rescue App42Exception =>e
|
766
|
+
raise e
|
767
|
+
rescue Exception => e
|
768
|
+
raise App42Exception.new(e)
|
769
|
+
end
|
770
|
+
return storageObj
|
771
|
+
end
|
772
|
+
|
773
|
+
end
|
774
|
+
end
|
775
|
+
end
|