restful_objects 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/restful_objects.rb +1 -2
- data/lib/restful_objects/domain_model/domain_model.rb +14 -11
- data/lib/restful_objects/domain_model/helpers/link_generator.rb +102 -90
- data/lib/restful_objects/domain_model/mixins/object.rb +10 -13
- data/lib/restful_objects/domain_model/mixins/object_actions.rb +106 -117
- data/lib/restful_objects/domain_model/mixins/object_base.rb +175 -131
- data/lib/restful_objects/domain_model/mixins/object_collections.rb +58 -71
- data/lib/restful_objects/domain_model/mixins/object_macros.rb +20 -26
- data/lib/restful_objects/domain_model/mixins/object_properties.rb +85 -98
- data/lib/restful_objects/domain_model/mixins/service.rb +9 -17
- data/lib/restful_objects/domain_model/types/action_description.rb +80 -82
- data/lib/restful_objects/domain_model/types/collection_description.rb +39 -40
- data/lib/restful_objects/domain_model/types/domain_type.rb +102 -105
- data/lib/restful_objects/domain_model/types/parameter_description.rb +42 -47
- data/lib/restful_objects/domain_model/types/parameter_description_list.rb +9 -12
- data/lib/restful_objects/domain_model/types/property_description.rb +62 -64
- data/lib/restful_objects/router.rb +6 -0
- data/lib/restful_objects/router/base.rb +23 -32
- data/lib/restful_objects/router/domain_object_resources.rb +89 -94
- data/lib/restful_objects/router/domain_type_resources.rb +24 -29
- data/lib/restful_objects/router/supporting_resources.rb +26 -31
- data/lib/restful_objects/version.rb +1 -1
- data/spec/integration/domain-types_actions_spec.rb +1 -3
- data/spec/integration/domain-types_collections_spec.rb +1 -39
- data/spec/integration/domain-types_properties_spec.rb +1 -78
- data/spec/integration/domain-types_spec.rb +39 -0
- data/spec/integration/{server-root_spec.rb → homepage_spec.rb} +2 -3
- data/spec/integration/objects_actions_spec.rb +7 -0
- data/spec/integration/objects_collections_spec.rb +169 -0
- data/spec/integration/objects_properties_spec.rb +122 -0
- data/spec/{acceptance/generate_json_representations_spec.rb → integration/objects_spec.rb} +12 -4
- data/spec/unit/object_actions_spec.rb +5 -5
- data/spec/unit/object_collections_spec.rb +1 -1
- data/spec/unit/object_properties_spec.rb +6 -6
- data/spec/unit/object_spec.rb +9 -9
- data/spec/unit/service_spec.rb +5 -5
- metadata +54 -35
- data/spec/integration/domain_model_spec.rb +0 -35
- data/spec/unit/type_list_spec.rb +0 -37
@@ -0,0 +1,6 @@
|
|
1
|
+
module RestfulObjects::Router
|
2
|
+
autoload :Base, 'restful_objects/router/base'
|
3
|
+
autoload :SupportingResources, 'restful_objects/router/supporting_resources'
|
4
|
+
autoload :DomainObjectResources, 'restful_objects/router/domain_object_resources'
|
5
|
+
autoload :DomainTypeResources, 'restful_objects/router/domain_type_resources'
|
6
|
+
end
|
@@ -1,41 +1,32 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
class RestfulObjects::Router::Base < Sinatra::Base
|
2
|
+
register RestfulObjects::Router::SupportingResources
|
3
|
+
register RestfulObjects::Router::DomainObjectResources
|
4
|
+
register RestfulObjects::Router::DomainTypeResources
|
4
5
|
|
5
|
-
|
6
|
-
module Router
|
7
|
-
class Base < Sinatra::Base
|
8
|
-
register RestfulObjects::Router::SupportingResources
|
9
|
-
register RestfulObjects::Router::DomainObjectResources
|
10
|
-
register RestfulObjects::Router::DomainTypeResources
|
6
|
+
set :bind, '0.0.0.0' # listen at all networks (needed for example using vagrant port forwarding)
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
headers['Access-Control-Allow-Origin'] = '*'
|
16
|
-
end
|
8
|
+
after do
|
9
|
+
headers['Access-Control-Allow-Origin'] = '*'
|
10
|
+
end
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
helpers do
|
13
|
+
def model
|
14
|
+
RestfulObjects::DomainModel.current
|
15
|
+
end
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
def objects
|
18
|
+
RestfulObjects::DomainModel.current.objects
|
19
|
+
end
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
21
|
+
def process_params
|
22
|
+
if request.query_string != ''
|
23
|
+
query_params = CGI.parse(request.query_string)
|
24
|
+
parameters = Hash.new
|
25
|
+
query_params.each { |key, value| parameters[key] = { 'value' => value.first } }
|
26
|
+
parameters.to_json
|
27
|
+
else
|
28
|
+
request.body.read
|
37
29
|
end
|
38
30
|
end
|
39
31
|
end
|
40
32
|
end
|
41
|
-
|
@@ -1,97 +1,92 @@
|
|
1
|
-
module RestfulObjects
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
router.post "/services/:service_id/actions/:action_id/invoke" do
|
91
|
-
model.services[params[:service_id]].get_action_invoke(params[:action_id], request.body.read)
|
92
|
-
end
|
93
|
-
end
|
1
|
+
module RestfulObjects::Router::DomainObjectResources
|
2
|
+
def self.registered(router)
|
3
|
+
# ** 14 Domain Object Resource & Representation **
|
4
|
+
# 14.1
|
5
|
+
router.get '/objects/:domain_type/:instance_id' do
|
6
|
+
objects[params[:instance_id].to_i].ro_get_representation_response
|
7
|
+
end
|
8
|
+
|
9
|
+
# 14.2
|
10
|
+
router.put '/objects/:domain_type/:instance_id' do
|
11
|
+
objects[params[:instance_id].to_i].ro_put_multiple_properties_and_get_response(request.body.read)
|
12
|
+
end
|
13
|
+
|
14
|
+
# 14.3
|
15
|
+
router.delete '/objects/:domain_type/:instance_id' do
|
16
|
+
objects[params[:instance_id].to_i].ro_delete
|
17
|
+
end
|
18
|
+
|
19
|
+
# patch to allow cross-origin put & delete requests #
|
20
|
+
router.options "/objects/:domain_type/:instance_id" do
|
21
|
+
headers['Access-Control-Allow-Methods'] = 'GET, DELETE, PUT, OPTIONS'
|
22
|
+
headers['Access-Control-Allow-Headers'] = 'Origin, Content-Type, Methods'
|
23
|
+
end
|
24
|
+
|
25
|
+
# C.15 Domain Services
|
26
|
+
router.get "/services/:service_id" do
|
27
|
+
model.services[params[:service_id]].ro_get_representation_response
|
28
|
+
end
|
29
|
+
|
30
|
+
# C.16 Property
|
31
|
+
router.get "/objects/:domain_type/:instance_id/properties/:property_id" do
|
32
|
+
objects[params[:instance_id].to_i].ro_get_property_response(params[:property_id])
|
33
|
+
end
|
34
|
+
|
35
|
+
router.put "/objects/:domain_type/:instance_id/properties/:property_id" do
|
36
|
+
objects[params[:instance_id].to_i].ro_put_property_and_get_response(params[:property_id], request.body.read)
|
37
|
+
end
|
38
|
+
|
39
|
+
router.delete "/objects/:domain_type/:instance_id/properties/:property_id" do
|
40
|
+
objects[params[:instance_id].to_i].ro_clear_property_and_get_response(params[:property_id])
|
41
|
+
end
|
42
|
+
|
43
|
+
# C.17 Collection #
|
44
|
+
router.get "/objects/:domain_type/:instance_id/collections/:collection_id" do
|
45
|
+
objects[params[:instance_id].to_i].ro_get_collection_response(params[:collection_id])
|
46
|
+
end
|
47
|
+
|
48
|
+
router.post "/objects/:domain_type/:instance_id/collections/:collection_id" do
|
49
|
+
objects[params[:instance_id].to_i].ro_add_to_collection_and_get_response(params[:collection_id], request.body.read)
|
50
|
+
end
|
51
|
+
|
52
|
+
router.put "/objects/:domain_type/:instance_id/collections/:collection_id" do
|
53
|
+
objects[params[:instance_id].to_i].ro_add_to_collection_and_get_response(params[:collection_id], request.body.read)
|
54
|
+
end
|
55
|
+
|
56
|
+
router.delete "/objects/:domain_type/:instance_id/collections/:collection_id" do
|
57
|
+
objects[params[:instance_id].to_i].ro_delete_from_collection_and_get_response(params[:collection_id], request.body.read)
|
58
|
+
end
|
59
|
+
|
60
|
+
# patch to allow cross-origin put & delete requests #
|
61
|
+
router.options "/objects/:domain_type/:instance_id/collections/:collection_id" do
|
62
|
+
headers['Access-Control-Allow-Methods'] = 'GET, DELETE, PUT, OPTIONS'
|
63
|
+
headers['Access-Control-Allow-Headers'] = 'Origin, Content-Type, Methods'
|
64
|
+
end
|
65
|
+
|
66
|
+
# C.18 Action
|
67
|
+
router.get "/objects/:domain_type/:instance_id/actions/:action_id" do
|
68
|
+
objects[params[:instance_id].to_i].ro_get_action_response(params[:action_id])
|
69
|
+
end
|
70
|
+
|
71
|
+
router.get "/services/:service_id/actions/:action_id" do
|
72
|
+
model.services[params[:service_id]].ro_get_action_response(params[:action_id])
|
73
|
+
end
|
74
|
+
|
75
|
+
# C.19 Action Invoke
|
76
|
+
router.get "/objects/:domain_type/:instance_id/actions/:action_id/invoke" do
|
77
|
+
objects[params[:instance_id].to_i].ro_invoke_action_and_get_response(params[:action_id], process_params)
|
78
|
+
end
|
79
|
+
|
80
|
+
router.get "/services/:service_id/actions/:action_id/invoke" do
|
81
|
+
model.services[params[:service_id]].ro_invoke_action_and_get_response(params[:action_id], process_params)
|
82
|
+
end
|
83
|
+
|
84
|
+
router.post "/objects/:domain_type/:instance_id/actions/:action_id/invoke" do
|
85
|
+
objects[params[:instance_id].to_i].ro_invoke_action_and_get_response(params[:action_id], request.body.read)
|
86
|
+
end
|
87
|
+
|
88
|
+
router.post "/services/:service_id/actions/:action_id/invoke" do
|
89
|
+
model.services[params[:service_id]].ro_invoke_action_and_get_response(params[:action_id], request.body.read)
|
94
90
|
end
|
95
91
|
end
|
96
92
|
end
|
97
|
-
|
@@ -1,37 +1,32 @@
|
|
1
|
-
module RestfulObjects
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
model.get_type_list_representation
|
8
|
-
end
|
1
|
+
module RestfulObjects::Router::DomainTypeResources
|
2
|
+
def self.registered(router)
|
3
|
+
# D.21 Domain Types
|
4
|
+
router.get "/domain-types" do
|
5
|
+
model.get_type_list_representation
|
6
|
+
end
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
# D.22 Domain Type
|
9
|
+
router.get "/domain-types/:domain_type" do
|
10
|
+
model.types[params[:domain_type]].get_representation
|
11
|
+
end
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
# D.23 Domain Type Property
|
14
|
+
router.get "/domain-types/:domain_type/properties/:property_id" do
|
15
|
+
model.types[params[:domain_type]].properties[params[:property_id]].get_representation
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
# D.24 Domain Type Collection
|
19
|
+
router.get "/domain-types/:domain_type/collections/:collection_id" do
|
20
|
+
model.types[params[:domain_type]].collections[params[:collection_id]].get_representation
|
21
|
+
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
# D.25 Domain Type Action
|
24
|
+
router.get "/domain-types/:domain_type/actions/:action_id" do
|
25
|
+
model.types[params[:domain_type]].actions[params[:action_id]].get_representation
|
26
|
+
end
|
29
27
|
|
30
|
-
|
28
|
+
# D.26 Domain Type Action Parameter
|
31
29
|
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
30
|
+
# D.27 Domain Type Action Invoke
|
35
31
|
end
|
36
32
|
end
|
37
|
-
|
@@ -1,39 +1,34 @@
|
|
1
|
-
module RestfulObjects
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
model.get_homepage
|
8
|
-
end
|
1
|
+
module RestfulObjects::Router::SupportingResources
|
2
|
+
def self.registered(router)
|
3
|
+
# B.5 Homepage
|
4
|
+
router.get '/' do
|
5
|
+
model.get_homepage_representation_response
|
6
|
+
end
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
# B.6 User
|
9
|
+
router.get '/user' do
|
10
|
+
model.get_user_as_json
|
11
|
+
end
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
# B.7 Services
|
14
|
+
router.get '/services' do
|
15
|
+
model.get_services
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
# B.8 Version
|
19
|
+
router.get '/version' do
|
20
|
+
model.get_version_representation_response
|
21
|
+
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
# B.9 Objects of Type Resource
|
24
|
+
router.post '/objects/:domain_type' do
|
25
|
+
model.types[params[:domain_type]].post_prototype_object(request.body.read)
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
28
|
+
# patch to allow cross-origin put & delete requests #
|
29
|
+
router.options '/objects/:domain_type' do
|
30
|
+
headers['Access-Control-Allow-Methods'] = 'POST, OPTIONS'
|
31
|
+
headers['Access-Control-Allow-Headers'] = 'Origin, Content-Type, Methods'
|
36
32
|
end
|
37
33
|
end
|
38
34
|
end
|
39
|
-
|
@@ -1,7 +1,6 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require_relative '../spec_helper'
|
3
2
|
|
4
|
-
describe '/domain-types/:type/actions
|
3
|
+
describe '=> /domain-types/:type/actions/' do
|
5
4
|
before(:all) do
|
6
5
|
RestfulObjects::DomainModel.current.reset
|
7
6
|
end
|
@@ -40,4 +39,3 @@ describe '/domain-types/:type/actions/:action' do
|
|
40
39
|
last_response.body.should match_json_expression expected
|
41
40
|
end
|
42
41
|
end
|
43
|
-
|
@@ -1,45 +1,7 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require_relative '../spec_helper'
|
3
2
|
|
4
|
-
describe '/domain-types/:type/collections
|
3
|
+
describe '=> /domain-types/:type/collections/' do
|
5
4
|
before(:all) do
|
6
5
|
RestfulObjects::DomainModel.current.reset
|
7
6
|
end
|
8
|
-
|
9
|
-
it 'should generate a collection description representation' do
|
10
|
-
class CollectionTest
|
11
|
-
include RestfulObjects::Object
|
12
|
-
collection :items, 'ItemClass', friendly_name: 'item collection', description: 'a collection description'
|
13
|
-
end
|
14
|
-
|
15
|
-
expected = {
|
16
|
-
'id' => 'items',
|
17
|
-
'friendlyName' => 'item collection',
|
18
|
-
'description' => 'a collection description',
|
19
|
-
'memberOrder' => 1,
|
20
|
-
'links' => [
|
21
|
-
{ 'rel' => 'self',
|
22
|
-
'href' => 'http://localhost/domain-types/CollectionTest/collections/items',
|
23
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/collection-description"',
|
24
|
-
'method' => 'GET' },
|
25
|
-
{ 'rel' => 'up',
|
26
|
-
'href' => 'http://localhost/domain-types/CollectionTest',
|
27
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
|
28
|
-
'method' => 'GET' },
|
29
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/return-type',
|
30
|
-
'href' => 'http://localhost/domain-types/list',
|
31
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
|
32
|
-
'method' => 'GET' },
|
33
|
-
{ 'rel' => 'urn:org.restfulobjects:rels/element-type',
|
34
|
-
'href' => 'http://localhost/domain-types/ItemClass',
|
35
|
-
'type' => 'application/json;profile="urn:org.restfulobjects:repr-types/domain-type"',
|
36
|
-
'method' => 'GET' }
|
37
|
-
],
|
38
|
-
'extensions' => wildcard_matcher
|
39
|
-
}
|
40
|
-
|
41
|
-
get '/domain-types/CollectionTest/collections/items'
|
42
|
-
last_response.body.should match_json_expression expected
|
43
|
-
end
|
44
7
|
end
|
45
|
-
|