schemaless_rest_api 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbc856f4da6c97a932cf00591ae9330a8c11107f508394d7d17623bdba76427c
4
- data.tar.gz: 1e3286aa8f268ccbb8ce21fb9cf155e213ecaaa7cbcb5c44253bc225829118b0
3
+ metadata.gz: 772e554afa1851f8a505754ce97e174218f28b2fdfa7cb8cea9e20483fe1a0a0
4
+ data.tar.gz: 442745cdc52411aa5e2db5d20fc9474188314ef94282db4b620675114a84f1ba
5
5
  SHA512:
6
- metadata.gz: '0875ee228c90497a905699ea7c33e85dd4885178533be0551cec74000bfa743cb21630c7bba96322f88336c23dfce045fb0d372a7813d9ec85f2baf19da7cb37'
7
- data.tar.gz: 77402ef68678360df7cee76aa40b21c80eba52c9b90154cff13ce50a8600522147bbd807f248da79b7349ff2f6871c444985db73613fa327708dde9ae0f85f3e
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: data})
10
+ collection.insert_one({ id: id, **data})
11
11
  end
12
12
 
13
13
  def find(model, id)
14
- collection = MongoClient.client[model]
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 { |match| match }
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 { |match| match }
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 }, { '$set' => data })
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.find_all(model, { id: id})
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.count > 0
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.count > 0
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SchemalessRestApi
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schemaless_rest_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Garratt