schemaless_rest_api 0.2.0 → 0.2.1
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 772e554afa1851f8a505754ce97e174218f28b2fdfa7cb8cea9e20483fe1a0a0
|
4
|
+
data.tar.gz: 442745cdc52411aa5e2db5d20fc9474188314ef94282db4b620675114a84f1ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c5f723fba1e431ee358afadfb6ed5d96bd081f8849d565fd23e31474c720c2ecf39b3f7e43e2eecef8bb896686e0e4d4a8a4837b4a1a35c565c253ab95015c1
|
7
|
+
data.tar.gz: cb903faf022ce6d7605ae3ea60e570a548f2db2b5c246d67a1fff1c405b85854d49b4dde11b89390b7f2b855dcbf75f7e0ec74cfd3dc99b90c0f5ad2cdec902b
|
@@ -7,27 +7,32 @@ module MongoClient
|
|
7
7
|
|
8
8
|
def insert(model, data, id)
|
9
9
|
collection = MongoClient.client[model]
|
10
|
-
collection.insert_one({ id: id, data
|
10
|
+
collection.insert_one({ id: id, **data})
|
11
11
|
end
|
12
12
|
|
13
13
|
def find(model, id)
|
14
|
-
|
15
|
-
collection.find( { id: id } ).first
|
14
|
+
find_all(model, { id: id } )
|
16
15
|
end
|
17
16
|
|
18
17
|
def get_all(model)
|
19
18
|
collection = MongoClient.client[model]
|
20
|
-
collection.find.collect
|
19
|
+
collection.find.collect do |match|
|
20
|
+
match.delete("_id")
|
21
|
+
match
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
25
|
def find_all(model, query)
|
24
26
|
collection = MongoClient.client[model]
|
25
|
-
collection.find( query ).collect
|
27
|
+
collection.find( query ).collect do |match|
|
28
|
+
match.delete("_id")
|
29
|
+
match
|
30
|
+
end
|
26
31
|
end
|
27
32
|
|
28
33
|
def update(model, id, data)
|
29
34
|
collection = MongoClient.client[model]
|
30
|
-
collection.update_one({ id: id }, {
|
35
|
+
collection.update_one({ id: id }, { id: id, **data})
|
31
36
|
end
|
32
37
|
|
33
38
|
def delete(model, id)
|
@@ -56,9 +56,10 @@ class RestServer < Sinatra::Base
|
|
56
56
|
end
|
57
57
|
|
58
58
|
get "/#{model.downcase}/:id" do |id|
|
59
|
+
puts request.path.downcase
|
59
60
|
if ENV['mongodb']
|
60
|
-
results = MongoClient.
|
61
|
-
return not_have(id) unless results
|
61
|
+
results = MongoClient.find(model, id)
|
62
|
+
return not_have(id) unless results.first
|
62
63
|
JSON.generate(results.first)
|
63
64
|
else
|
64
65
|
return not_have(id) unless has_id?(model, id)
|
@@ -68,10 +69,11 @@ class RestServer < Sinatra::Base
|
|
68
69
|
end
|
69
70
|
|
70
71
|
put "/#{model.downcase}/:id" do |id|
|
72
|
+
puts request.path.downcase
|
71
73
|
data = JSON.parse(request.body.read)
|
72
74
|
if ENV['mongodb']
|
73
75
|
results = MongoClient.find(model, id)
|
74
|
-
return not_have(id) unless results.
|
76
|
+
return not_have(id) unless results.first
|
75
77
|
MongoClient.update(model, id, data)
|
76
78
|
else
|
77
79
|
return not_have(id) unless has_id?(model, id)
|
@@ -82,9 +84,10 @@ class RestServer < Sinatra::Base
|
|
82
84
|
end
|
83
85
|
|
84
86
|
delete "/#{model.downcase}/:id" do |id|
|
87
|
+
puts request.path.downcase
|
85
88
|
if ENV['mongodb']
|
86
89
|
results = MongoClient.find(model, id)
|
87
|
-
return not_have(id) unless results.
|
90
|
+
return not_have(id) unless results.first
|
88
91
|
MongoClient.delete(model, id)
|
89
92
|
else
|
90
93
|
return not_have(id) unless has_id?(model, id)
|