json-crud-api 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json-crud-api.rb +1 -0
- data/lib/json-crud-api/api.rb +6 -4
- data/lib/json-crud-api/crud.rb +1 -19
- data/lib/json-crud-api/crud_extension.rb +20 -0
- data/spec/unit/crud_spec.rb +0 -56
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc410c49c2e6a7721caefeaf56701e7ffc074e51
|
4
|
+
data.tar.gz: b93070f2495112662568de6719abd6a62e67a860
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8e8b68269544a177a403737cb22fd933bc04f1ecaf2f722fa185e8e1795d5df474bafe6e0382d182c63bb5b9251f9473d2ca8ebe1c6a43bf45b5adc836163a4
|
7
|
+
data.tar.gz: 3f269d7e5000223850301da05ac2fa96584aa8d83e8f7157b660f5acbaa3bc8d05d5304808d1834fa6f2b8094873556dc80ecf994834a9ba03bdedeab556602b
|
data/lib/json-crud-api.rb
CHANGED
@@ -2,6 +2,7 @@ require "json-crud-api/session"
|
|
2
2
|
require "json-crud-api/presenter"
|
3
3
|
require "json-crud-api/service"
|
4
4
|
require "json-crud-api/crud"
|
5
|
+
require "json-crud-api/crud_extension"
|
5
6
|
require "json-crud-api/json_payload"
|
6
7
|
require "json-crud-api/json_errors"
|
7
8
|
require "json-crud-api/auth_client"
|
data/lib/json-crud-api/api.rb
CHANGED
@@ -4,10 +4,12 @@ require 'sinatra'
|
|
4
4
|
module JsonCrudApi
|
5
5
|
class API < Sinatra::Base
|
6
6
|
|
7
|
-
|
8
|
-
register JsonCrudApi::
|
9
|
-
|
10
|
-
|
7
|
+
include JsonCrudApi::Crud
|
8
|
+
register JsonCrudApi::CrudExtension
|
9
|
+
|
10
|
+
include JsonCrudApi::Session
|
11
|
+
include JsonCrudApi::JsonPayload
|
12
|
+
include JsonCrudApi::JsonErrors
|
11
13
|
|
12
14
|
before do
|
13
15
|
# HTTPS Only (if configured)
|
data/lib/json-crud-api/crud.rb
CHANGED
@@ -1,25 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
-
module JsonCrudApi
|
3
|
+
module JsonCrudApi
|
4
4
|
module Crud
|
5
|
-
|
6
|
-
def crud_api(url, key, options = [])
|
7
|
-
|
8
|
-
unless options.include? :disable_read
|
9
|
-
get url do crud_get_all(key) end unless options.include? :disable_get_all
|
10
|
-
get url+"/:id" do crud_get(key) end unless options.include? :disable_get
|
11
|
-
end
|
12
|
-
|
13
|
-
unless options.include? :disable_write
|
14
|
-
post url do crud_post(key) end unless options.include? :disable_post
|
15
|
-
put url+"/:id" do crud_put(key) end unless options.include? :disable_put
|
16
|
-
delete url+"/:id" do crud_delete(key) end unless options.include? :disable_delete
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
5
|
def crud_get_all(key)
|
24
6
|
service = settings.services[key]
|
25
7
|
presenter = settings.presenters[key]
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module JsonCrudApi
|
4
|
+
module CrudExtension
|
5
|
+
def crud_api(url, key, options = [])
|
6
|
+
|
7
|
+
unless options.include? :disable_read
|
8
|
+
get url do crud_get_all(key) end unless options.include? :disable_get_all
|
9
|
+
get url+"/:id" do crud_get(key) end unless options.include? :disable_get
|
10
|
+
end
|
11
|
+
|
12
|
+
unless options.include? :disable_write
|
13
|
+
post url do crud_post(key) end unless options.include? :disable_post
|
14
|
+
put url+"/:id" do crud_put(key) end unless options.include? :disable_put
|
15
|
+
delete url+"/:id" do crud_delete(key) end unless options.include? :disable_delete
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/unit/crud_spec.rb
CHANGED
@@ -18,62 +18,6 @@ describe JsonCrudApi::AuthClient do
|
|
18
18
|
@test = CrudTest.new
|
19
19
|
end
|
20
20
|
|
21
|
-
describe '#crud_api' do
|
22
|
-
it 'should enable get_all if configured' do
|
23
|
-
expect(@test).to receive(:get).with('/test')
|
24
|
-
|
25
|
-
expect(@test).not_to receive(:get)
|
26
|
-
expect(@test).not_to receive(:post)
|
27
|
-
expect(@test).not_to receive(:put)
|
28
|
-
expect(@test).not_to receive(:delete)
|
29
|
-
|
30
|
-
@test.crud_api('/test',:one, [:disable_write,:disable_get])
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should enable get if configured' do
|
34
|
-
expect(@test).to receive(:get).with('/test/:id')
|
35
|
-
|
36
|
-
expect(@test).not_to receive(:get).with('/test')
|
37
|
-
expect(@test).not_to receive(:post)
|
38
|
-
expect(@test).not_to receive(:put)
|
39
|
-
expect(@test).not_to receive(:delete)
|
40
|
-
|
41
|
-
@test.crud_api('/test',:one, [:disable_write,:disable_get_all])
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should enable post if configured' do
|
45
|
-
expect(@test).to receive(:post).with('/test')
|
46
|
-
|
47
|
-
expect(@test).not_to receive(:get)
|
48
|
-
expect(@test).not_to receive(:post)
|
49
|
-
expect(@test).not_to receive(:put)
|
50
|
-
expect(@test).not_to receive(:delete)
|
51
|
-
|
52
|
-
@test.crud_api('/test',:one, [:disable_put,:disable_delete,:disable_read])
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should enable put if configured' do
|
56
|
-
expect(@test).to receive(:put).with('/test/:id')
|
57
|
-
|
58
|
-
expect(@test).not_to receive(:get)
|
59
|
-
expect(@test).not_to receive(:post)
|
60
|
-
expect(@test).not_to receive(:delete)
|
61
|
-
|
62
|
-
@test.crud_api('/test',:one, [:disable_post,:disable_delete,:disable_read])
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should enable delete if configured' do
|
66
|
-
expect(@test).to receive(:delete).with('/test/:id')
|
67
|
-
|
68
|
-
expect(@test).not_to receive(:get)
|
69
|
-
expect(@test).not_to receive(:post)
|
70
|
-
expect(@test).not_to receive(:put)
|
71
|
-
|
72
|
-
@test.crud_api('/test',:one, [:disable_post,:disable_put,:disable_read])
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
21
|
describe '#crud_get_all' do
|
78
22
|
|
79
23
|
before do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-crud-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Cully
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- lib/json-crud-api/api.rb
|
150
150
|
- lib/json-crud-api/auth_client.rb
|
151
151
|
- lib/json-crud-api/crud.rb
|
152
|
+
- lib/json-crud-api/crud_extension.rb
|
152
153
|
- lib/json-crud-api/json_errors.rb
|
153
154
|
- lib/json-crud-api/json_payload.rb
|
154
155
|
- lib/json-crud-api/presenter.rb
|