auto_api 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/auto_api/base.rb +42 -50
- data/lib/auto_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61da606bd6dd0ba85d235ff83595fcba05634ac1
|
4
|
+
data.tar.gz: ce6a77f7f348684e6a260d45b85e71b98fc1b544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4ee01d473f6bffaf149d63abf092bece678600800235f0d9a3599b783148c308a10be287b8a3259b12717f1c24c21a270f28e1516f908c7209201ee0797fc54
|
7
|
+
data.tar.gz: 97dd6e121f7b84bb1caa2125d81faf4d5967a8a938a9893b506d4d069fde93fecb2e4c268e12e9eb7d0fc0abb7fb02f62e2ac57a2164a137c5af9083b6728749
|
data/lib/auto_api/base.rb
CHANGED
@@ -1,27 +1,23 @@
|
|
1
1
|
require 'sinatra'
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'sinatra/reloader'
|
3
|
+
require 'sinatra/json'
|
4
4
|
require 'mongoid'
|
5
5
|
require 'active_support/inflector'
|
6
6
|
require 'active_model'
|
7
|
-
require 'logger'
|
8
|
-
|
9
|
-
|
10
7
|
|
11
8
|
class AutoApi::Base < Sinatra::Base
|
12
|
-
logger = Logger.new(STDOUT)
|
13
9
|
configure :development do
|
14
10
|
register Sinatra::Reloader
|
15
11
|
end
|
16
12
|
|
17
13
|
Mongoid.load!('./config/mongoid.yml')
|
18
14
|
|
19
|
-
#WE ARE RETURNING JSON
|
15
|
+
# WE ARE RETURNING JSON
|
20
16
|
before '/*' do
|
21
17
|
content_type 'application/json'
|
22
18
|
end
|
23
19
|
|
24
|
-
before '/:resource1/:id1/:resource2/?' do |
|
20
|
+
before '/:resource1/:id1/:resource2/?' do |resource1, _id1, resource2|
|
25
21
|
@resource1 = Object.const_set(resource1.classify, Class.new)
|
26
22
|
@resource1.include(Mongoid::Document)
|
27
23
|
@resource1.has_many resource2
|
@@ -37,66 +33,62 @@ logger = Logger.new(STDOUT)
|
|
37
33
|
end
|
38
34
|
end
|
39
35
|
|
40
|
-
get '/:resource/?' do |
|
41
|
-
webtry
|
36
|
+
get '/:resource/?' do |_resource|
|
37
|
+
webtry { json @resource.all }
|
42
38
|
end
|
43
39
|
|
44
|
-
get '/:resource/:id/?' do |
|
45
|
-
webtry
|
40
|
+
get '/:resource/:id/?' do |_resource, id|
|
41
|
+
webtry { json @resource.find(id) }
|
46
42
|
end
|
47
43
|
|
48
|
-
post '/:resource/?' do |
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
json resource
|
55
|
-
})
|
44
|
+
post '/:resource/?' do |resource|
|
45
|
+
webtry do
|
46
|
+
resource = @resource.new(request.params)
|
47
|
+
resource.save!
|
48
|
+
json resource
|
49
|
+
end
|
56
50
|
end
|
57
51
|
|
58
|
-
put '/:resource/:id/?' do |
|
59
|
-
webtry
|
60
|
-
|
61
|
-
|
62
|
-
|
52
|
+
put '/:resource/:id/?' do |resource, id|
|
53
|
+
webtry do
|
54
|
+
resource = @resource.find(id)
|
55
|
+
resource.update_attributes!(request.params)
|
56
|
+
end
|
63
57
|
end
|
64
58
|
|
65
|
-
delete '/:resource/:id/?' do |
|
66
|
-
webtry
|
59
|
+
delete '/:resource/:id/?' do |_resource, id|
|
60
|
+
webtry { json @resource.find(id).delete }
|
67
61
|
end
|
68
62
|
|
69
63
|
delete '/:resource/?' do
|
70
|
-
webtry
|
64
|
+
webtry { json @resource.all.delete }
|
71
65
|
end
|
72
66
|
|
73
|
-
#NESTED
|
74
|
-
get '/:resource1/:id1/:resource2/?' do |
|
75
|
-
webtry
|
67
|
+
# NESTED
|
68
|
+
get '/:resource1/:id1/:resource2/?' do |_resource1, id1, resource2|
|
69
|
+
webtry { json @resource1.find(id1).send(resource2) }
|
76
70
|
end
|
77
71
|
|
78
|
-
post '/:resource1/:id1/:resource2/?' do |
|
79
|
-
webtry
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
72
|
+
post '/:resource1/:id1/:resource2/?' do |_resource1, id1, resource2|
|
73
|
+
webtry do
|
74
|
+
parent_resource = @resource1.find(id1)
|
75
|
+
child_resource = @resource2.new(request.params)
|
76
|
+
child_resource.save!
|
77
|
+
parent_resource.send(resource2) << child_resource
|
78
|
+
json child_resource
|
79
|
+
end
|
86
80
|
end
|
87
81
|
|
88
|
-
delete '/:resource1/:id1/:resource2/?' do |
|
89
|
-
webtry
|
82
|
+
delete '/:resource1/:id1/:resource2/?' do |_resource1, id1, resource2|
|
83
|
+
webtry { json @resource1.find(id1).send(resource2).all.delete }
|
90
84
|
end
|
91
85
|
|
92
|
-
def webtry
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
status 500
|
100
|
-
end
|
86
|
+
def webtry
|
87
|
+
status 200
|
88
|
+
yield
|
89
|
+
rescue Mongoid::Errors::DocumentNotFound
|
90
|
+
status 404
|
91
|
+
rescue
|
92
|
+
status 500
|
101
93
|
end
|
102
94
|
end
|
data/lib/auto_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phillip R. Spitler (Phil)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|