zeddb 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +15 -0
- data/README.rdoc +8 -0
- data/Rakefile +75 -0
- data/VERSION +1 -0
- data/bin/zeddb +23 -0
- data/lib/cli/config.rb +20 -0
- data/lib/cli/model_associations.rb +38 -0
- data/lib/cli/model_items.rb +59 -0
- data/lib/cli/model_transformer.rb +53 -0
- data/lib/cli/model_validations.rb +56 -0
- data/lib/cli/models.rb +59 -0
- data/lib/cli/projects.rb +49 -0
- data/lib/cli/runner.rb +55 -0
- data/lib/cli/text.rb +52 -0
- data/lib/zeddb/instances/model.rb +71 -0
- data/lib/zeddb/instances/model_item.rb +77 -0
- data/lib/zeddb/instances/model_transformer.rb +34 -0
- data/lib/zeddb/instances/model_validation.rb +36 -0
- data/lib/zeddb/instances/project.rb +24 -0
- data/lib/zeddb/resources/model_associations.rb +66 -0
- data/lib/zeddb/resources/model_items.rb +73 -0
- data/lib/zeddb/resources/model_transformers.rb +62 -0
- data/lib/zeddb/resources/model_validations.rb +66 -0
- data/lib/zeddb/resources/models.rb +73 -0
- data/lib/zeddb/resources/projects.rb +40 -0
- data/lib/zeddb.rb +34 -0
- data/test/helper.rb +47 -0
- data/test/test_associations.rb +64 -0
- data/test/test_entities.rb +36 -0
- data/test/test_model_items.rb +79 -0
- data/test/test_models.rb +72 -0
- data/test/test_projects.rb +35 -0
- data/test/test_transformers.rb +60 -0
- data/test/test_validations.rb +73 -0
- metadata +134 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module ZedDB
|
19
|
+
class ModelItem < Zedkit::Instance
|
20
|
+
def model
|
21
|
+
ZedDB::Model.new(:user_key => uk, :locale => lc, :uuid => self['model']['uuid'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def validations
|
25
|
+
self.has_key?('validations') && self['validations'].is_a?(Array) ? self['validations'] : []
|
26
|
+
end
|
27
|
+
def transformers
|
28
|
+
self.has_key?('transformers') && self['transformers'].is_a?(Array) ? self['transformers'] : []
|
29
|
+
end
|
30
|
+
|
31
|
+
def update
|
32
|
+
end
|
33
|
+
def delete
|
34
|
+
ZedDB::ModelItems.delete(:user_key => uk, :locale => lc, :uuid => uuid)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
rs = "\nZedDB Data Item within Model \"#{model['name']}\":\n" \
|
39
|
+
<< " Name : #{self['name']}\n" \
|
40
|
+
<< " UUID : #{self['uuid']}\n" \
|
41
|
+
<< " Type : #{self['type']['code']}\n" \
|
42
|
+
<< " Validations : #{validations.count}\n" \
|
43
|
+
<< " Transformers : #{transformers.count}\n" \
|
44
|
+
<< " Version : #{self['version']}\n" \
|
45
|
+
<< " Created : #{time(self['created_at'])}\n" \
|
46
|
+
<< " Updated : #{time(self['updated_at'])}\n"
|
47
|
+
if validations.empty? && transformers.empty?
|
48
|
+
rs << dashes(20) << "\n"
|
49
|
+
else
|
50
|
+
unless validations.empty?
|
51
|
+
rs << dashes(70) << "| #{'Data Item Validations'.center(66)} |\n" << dashes(70) \
|
52
|
+
<< "| #{'UUID'.ljust(32)} | #{'Code'.center(4)} | #{'Qualifier'.center(24)} |\n" << dashes(70)
|
53
|
+
validations.each {|vd| rs << "| #{vd['uuid']} | #{vd['validation']['code'].center(4)} | #{qualifier(vd)} |\n" }
|
54
|
+
rs << dashes(70)
|
55
|
+
end
|
56
|
+
unless transformers.empty?
|
57
|
+
rs << dashes(70) << "| #{'Data Item Transformers'.center(66)} |\n" << dashes(70) \
|
58
|
+
<< "| #{'UUID'.ljust(32)} | #{'Code'.center(31)} |\n" << dashes(70)
|
59
|
+
transformers.each {|ts| rs << "| #{ts['uuid']} | #{ts['transformer']['code'].center(31)} |\n" }
|
60
|
+
rs << dashes(70)
|
61
|
+
end
|
62
|
+
rs << "\n"
|
63
|
+
end
|
64
|
+
rs
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
def set_with_uuid(uuid_to_use)
|
69
|
+
replace ZedDB::ModelItems.get(:user_key => uk, :locale => lc, :uuid => uuid_to_use)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def qualifier(vd)
|
74
|
+
vd.has_key?('qualifier') ? vd['qualifer'].center(24) : 'N/A'.center(24)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module ZedDB
|
19
|
+
class ModelTransformer < Zedkit::Instance
|
20
|
+
def model_item
|
21
|
+
ZedDB::ModelItem.new(:user_key => uk, :locale => lc, :uuid => item['uuid'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete
|
25
|
+
ZedDB::ModelTransformers.delete(:user_key => uk, :locale => lc, :item => { :uuid => item['uuid'] }, :uuid => uuid)
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
def set_with_owner_and_uuid(item_uuid, transformer_uuid)
|
30
|
+
replace ZedDB::ModelTransformers.get(:user_key => uk, :locale => lc,
|
31
|
+
:item => { :uuid => item_uuid }, :uuid => transformer_uuid)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module ZedDB
|
19
|
+
class ModelValidation < Zedkit::Instance
|
20
|
+
def model_item
|
21
|
+
ZedDB::ModelItem.new(:user_key => uk, :locale => lc, :uuid => item['uuid'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def update
|
25
|
+
end
|
26
|
+
def delete
|
27
|
+
ZedDB::ModelValidations.delete(:user_key => uk, :locale => lc, :item => { :uuid => item['uuid'] }, :uuid => uuid)
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
def set_with_owner_and_uuid(item_uuid, validation_uuid)
|
32
|
+
replace ZedDB::ModelValidations.get(:user_key => uk, :locale => lc,
|
33
|
+
:item => { :uuid => item_uuid }, :uuid => validation_uuid)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module Zedkit
|
19
|
+
class Project < Zedkit::Instance
|
20
|
+
def models
|
21
|
+
Zedkit::Projects::Models.get(:user_key => uk, :locale => lc, :project => { :uuid => uuid })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module ZedDB
|
19
|
+
class ModelAssociations
|
20
|
+
class << self
|
21
|
+
#
|
22
|
+
# = ZedDB Model Associations
|
23
|
+
#
|
24
|
+
# ZedDB models can be associated with each other in predetermined ways. You can create or delete model associations.
|
25
|
+
# A model's associations are listed within its response data set.
|
26
|
+
#
|
27
|
+
# To create a new Model Assocation you submit the required parameters of the association type with the model UUIDs that
|
28
|
+
# you are creating an association between. Whatever items you send within the :association Hash are passed through to
|
29
|
+
# the ZedAPI untouched. There is no client side validation within this gem.
|
30
|
+
#
|
31
|
+
# Associations can be confusing to create, given that the order is arbitary. But you would read an association as
|
32
|
+
# Model B belongs to Model A. So, to create a belongs_to association. You would be using the resource location based
|
33
|
+
# on Model B, creating an association to Model A, with "first" and "second" labels as you read the association aloud.
|
34
|
+
#
|
35
|
+
# ZedDB::ModelAssociations.create(:user_key => user['user_key'],
|
36
|
+
# :association => { :first => model_b['uuid'],
|
37
|
+
# :code => 'BT', :inverse => 'HM', :second => model_b['uuid] })
|
38
|
+
#
|
39
|
+
# To delete a Model Association:
|
40
|
+
#
|
41
|
+
# ZedDB::ModelAssociations.delete(:user_key => user['user_key'], :uuid => association['uuid])
|
42
|
+
#
|
43
|
+
# From each of these requests the Zedkit::Client class will return a response hash for your reference, if needed,
|
44
|
+
# or as applicable to the request. If there was a HTTP 401 or 404 you will get a nil response. This indicates a
|
45
|
+
# security failure or that an UUID is incorrect, not attached the user's account, or non-existent.
|
46
|
+
#
|
47
|
+
# For each request you can also pass a block to process the response directly:
|
48
|
+
#
|
49
|
+
# ZedDB::ModelAssociations.delete(:user_key => user['user_key'], :uuid => association['uuid]) do |result|
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
|
53
|
+
def get(zks = {}, &block)
|
54
|
+
Zedkit::Client.crud(:get, "db/associations/#{zks[:uuid]}", zks, [], &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
def create(zks = {}, &block)
|
58
|
+
Zedkit::Client.crud(:create, 'db/associations', zks, [], &block)
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete(zks = {}, &block)
|
62
|
+
Zedkit::Client.crud(:delete, "db/associations/#{zks[:uuid]}", zks, [], &block)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module ZedDB
|
19
|
+
class ModelItems
|
20
|
+
class << self
|
21
|
+
#
|
22
|
+
# = ZedDB Models Data Items
|
23
|
+
#
|
24
|
+
# All ZedDB models need data items. You can create, read, update, or delete model data items. To perform an
|
25
|
+
# operation on a specific model item you need its UUID, as available from the Models.get() method.
|
26
|
+
#
|
27
|
+
# To get a Model Item:
|
28
|
+
#
|
29
|
+
# ZedDB::ModelItems.get(:user_key => user['user_key'], :uuid => item['uuid'])
|
30
|
+
#
|
31
|
+
# To update a Model Item:
|
32
|
+
#
|
33
|
+
# ZedDB::ModelItems.update(:user_key => user['user_key'], :uuid => item['uuid'], :item => { :name => 'newname' })
|
34
|
+
#
|
35
|
+
# To delete a Model Item:
|
36
|
+
#
|
37
|
+
# ZedDB::ModelItems.delete(:user_key => user['user_key'], :uuid => item['uuid])
|
38
|
+
#
|
39
|
+
# To create a new Model Item you submit the required parameters with the model UUID that you are creating the
|
40
|
+
# model item within. Whatever items you send within the :item Hash are passed through to the ZedAPI untouched.
|
41
|
+
# There is no client side validation within this gem.
|
42
|
+
#
|
43
|
+
# ZedDB::ModelItems.create(:user_key => user['user_key'],
|
44
|
+
# :model => { :uuid => model['uuid'] }, :item => { :name => 'whatever' })
|
45
|
+
#
|
46
|
+
# From each of these requests the Zedkit::Client class will return a response hash for your reference, if needed,
|
47
|
+
# or as applicable to the request. If there was a HTTP 401 or 404 you will get a nil response. This indicates a
|
48
|
+
# security failure or that an UUID is incorrect, not attached the user's account, or non-existent.
|
49
|
+
#
|
50
|
+
# For each request you can also pass a block to process the response directly:
|
51
|
+
#
|
52
|
+
# ZedDB::ModelItems.get(:user_key => user['user_key'], :uuid => model['uuid']) do |result|
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
|
56
|
+
def get(zks = {}, &block)
|
57
|
+
Zedkit::Client.crud(:get, "db/items/#{zks[:uuid]}", zks, [], &block)
|
58
|
+
end
|
59
|
+
|
60
|
+
def create(zks = {}, &block)
|
61
|
+
Zedkit::Client.crud(:create, 'db/items', zks, [], &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
def update(zks = {}, &block)
|
65
|
+
Zedkit::Client.crud(:update, "db/items/#{zks[:uuid]}", zks, [], &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete(zks = {}, &block)
|
69
|
+
Zedkit::Client.crud(:delete, "db/items/#{zks[:uuid]}", zks, [], &block)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module ZedDB
|
19
|
+
class ModelTransformers
|
20
|
+
class << self
|
21
|
+
#
|
22
|
+
# = ZedDB Model Transformers
|
23
|
+
#
|
24
|
+
# ZedDB model data items can have standard "transformers" attached to them -- actions to be performed on the data item
|
25
|
+
# just before it is saved to the underlying storage system. You can create or delete model item transformers.
|
26
|
+
# A model item's transformers are listed within its response data set.
|
27
|
+
#
|
28
|
+
# To create a new Model Transformer you submit the required parameters of the transformer type with the model item
|
29
|
+
# UUID that you are attaching a transformer to. Whatever items you send within the :transformer Hash are passed through
|
30
|
+
# to the ZedAPI untouched. There is no client side validation within this gem.
|
31
|
+
#
|
32
|
+
# ZedDB::ModelTransformers.create(:user_key => user['user_key'], :item => { :uuid => item['uuid'] },
|
33
|
+
# :transformer => { :code => 'UP' })
|
34
|
+
#
|
35
|
+
# To delete a Model Transformer:
|
36
|
+
#
|
37
|
+
# ZedDB::ModelTransformers.delete(:user_key => user['user_key'], :uuid => transformer['uuid])
|
38
|
+
#
|
39
|
+
# From each of these requests the Zedkit::Client class will return a response hash for your reference, if needed,
|
40
|
+
# or as applicable to the request. If there was a HTTP 401 or 404 you will get a nil response. This indicates a
|
41
|
+
# security failure or that an UUID is incorrect, not attached the user's account, or non-existent.
|
42
|
+
#
|
43
|
+
# For each request you can also pass a block to process the response directly:
|
44
|
+
#
|
45
|
+
# ZedDB::ModelTransformers.delete(:user_key => user['user_key'], :uuid => transformer['uuid]) do |result|
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
|
49
|
+
def get(zks = {}, &block)
|
50
|
+
Zedkit::Client.crud(:get, "db/items/#{zks[:item][:uuid]}/transformers/#{zks[:uuid]}", zks, %w(item), &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def create(zks = {}, &block)
|
54
|
+
Zedkit::Client.crud(:create, "db/items/#{zks[:item][:uuid]}/transformers", zks, %w(item), &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
def delete(zks = {}, &block)
|
58
|
+
Zedkit::Client.crud(:delete, "db/items/#{zks[:item][:uuid]}/transformers/#{zks[:uuid]}", zks, [], &block)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module ZedDB
|
19
|
+
class ModelValidations
|
20
|
+
class << self
|
21
|
+
#
|
22
|
+
# = ZedDB Model Validations
|
23
|
+
#
|
24
|
+
# ZedDB model data items can have standard validations attached to them. You can create, update (if applicable to
|
25
|
+
# the validation type) or delete model item validations. A model item's validations are listed within its API
|
26
|
+
# response data set.
|
27
|
+
#
|
28
|
+
# To create a new model item validation you submit the required parameters of the validation type with the model item
|
29
|
+
# UUID that you are attaching a valiation to. Whatever items you send within the :validation Hash are passed through
|
30
|
+
# to the ZedAPI untouched. There is no client side validation within this gem.
|
31
|
+
#
|
32
|
+
# ZedDB::ModelValidations.create(:user_key => user['user_key'], :item => { :uuid => item['uuid'] },
|
33
|
+
# :validation => { :code => "SB" })
|
34
|
+
#
|
35
|
+
# To delete a model item validation:
|
36
|
+
#
|
37
|
+
# ZedDB::ModelValidations.delete(:user_key => user['user_key'], :uuid => validation['uuid])
|
38
|
+
#
|
39
|
+
# From each of these requests the Zedkit::Client class will return a response hash for your reference, if needed,
|
40
|
+
# or as applicable to the request. If there was a HTTP 401 or 404 you will get a nil response. This indicates a
|
41
|
+
# security failure or that an UUID is incorrect, not attached the user's account, or non-existent.
|
42
|
+
#
|
43
|
+
# For each request you can also pass a block to process the response directly:
|
44
|
+
#
|
45
|
+
# ZedDB::ModelValidations.delete(:user_key => user['user_key'], :uuid => validation['uuid]) do |result|
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
|
49
|
+
def get(zks = {}, &block)
|
50
|
+
Zedkit::Client.crud(:get, "db/items/#{zks[:item][:uuid]}/validations/#{zks[:uuid]}", zks, %w(item), &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def create(zks = {}, &block)
|
54
|
+
Zedkit::Client.crud(:create, "db/items/#{zks[:item][:uuid]}/validations", zks, %w(item), &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
def update(zks = {}, &block)
|
58
|
+
Zedkit::Client.crud(:update, "db/items/#{zks[:item][:uuid]}/validations/#{zks[:uuid]}", zks, %w(item), &block)
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete(zks = {}, &block)
|
62
|
+
Zedkit::Client.crud(:delete, "db/items/#{zks[:item][:uuid]}/validations/#{zks[:uuid]}", zks, [], &block)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module ZedDB
|
19
|
+
class Models
|
20
|
+
class << self
|
21
|
+
#
|
22
|
+
# = ZedDB Database Models
|
23
|
+
#
|
24
|
+
# All ZedDB application databases have models. You can create, read, update, or delete models. To perform an
|
25
|
+
# operation on a specific model you need its UUID, as available from the Websites.models method.
|
26
|
+
#
|
27
|
+
# To get a Model:
|
28
|
+
#
|
29
|
+
# ZedDB::Models.get(:user_key => user['user_key'], :uuid => model['uuid'])
|
30
|
+
#
|
31
|
+
# To update a Model:
|
32
|
+
#
|
33
|
+
# ZedDB::Models.update(:user_key => user['user_key'], :uuid => model['uuid'])
|
34
|
+
#
|
35
|
+
# To delete a Model:
|
36
|
+
#
|
37
|
+
# ZedDB::Models.delete(:user_key => user['user_key'], :uuid => model['uuid'])
|
38
|
+
#
|
39
|
+
# To create a new Model you submit the required parameters with the project UUID that you are creating the
|
40
|
+
# model for. Whatever items you send within the :model Hash are passed through to the ZedAPI untouched.
|
41
|
+
# There is no client side validation within this gem.
|
42
|
+
#
|
43
|
+
# ZedDB::Models.create(:user_key => user['user_key'],
|
44
|
+
# :project => { :uuid => project['uuid'] }, :model => { :name => 'whatever' })
|
45
|
+
#
|
46
|
+
# From each of these requests the Zedkit::Client class will return a response hash for your reference, if needed,
|
47
|
+
# or as applicable to the request. If there was a HTTP 401 or 404 you will get a nil response. This indicates a
|
48
|
+
# security failure or that an UUID is incorrect, not attached the user's account, or non-existent.
|
49
|
+
#
|
50
|
+
# For each request you can also pass a block to process the response directly:
|
51
|
+
#
|
52
|
+
# ZedDB::Models.get(:user_key => user['user_key'], :uuid => model['uuid']) do |result|
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
|
56
|
+
def get(zks = {}, &block)
|
57
|
+
Zedkit::Client.crud(:get, "db/models/#{zks[:uuid]}", zks, [], &block)
|
58
|
+
end
|
59
|
+
|
60
|
+
def create(zks = {}, &block)
|
61
|
+
Zedkit::Client.crud(:create, 'db/models', zks, [], &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
def update(zks = {}, &block)
|
65
|
+
Zedkit::Client.crud(:update, "db/models/#{zks[:uuid]}", zks, [], &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete(zks = {}, &block)
|
69
|
+
Zedkit::Client.crud(:delete, "db/models/#{zks[:uuid]}", zks, [], &block)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module Zedkit
|
19
|
+
class Projects
|
20
|
+
class Models
|
21
|
+
class << self
|
22
|
+
#
|
23
|
+
# = ZedDB Application Databases
|
24
|
+
#
|
25
|
+
# All projects/applications have an assigned database whether they use it or not. We just bypass the concept of a
|
26
|
+
# separate database API resource. You ask the project/application directly for the models setup within its database:
|
27
|
+
#
|
28
|
+
# Zedkit::Projects.Models.get(:user_key => user['user_key'], :project => { :uuid => project['uuid'] })
|
29
|
+
#
|
30
|
+
# Each Zedkit project/application has an unique UUID available within the user's projects list, which you can then use
|
31
|
+
# here, and with all methods that collect objects attached to a project/application.
|
32
|
+
#
|
33
|
+
|
34
|
+
def get(zks = {}, &block)
|
35
|
+
Zedkit::Client.crud(:get, 'db/models', zks, [], &block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/zeddb.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
require 'rubygems'
|
19
|
+
require 'zedkit'
|
20
|
+
|
21
|
+
module ZedDB
|
22
|
+
class << self
|
23
|
+
def entities(user_key)
|
24
|
+
rs = Zedkit::Client.get('entities/zeddb', user_key)
|
25
|
+
if rs && block_given?
|
26
|
+
rs.is_a?(Array) ? rs.each {|i| yield(i) } : yield(rs)
|
27
|
+
end
|
28
|
+
rs
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Dir["#{File.dirname(__FILE__)}/zeddb/instances/*.rb"].each {|ci| require ci }
|
34
|
+
Dir["#{File.dirname(__FILE__)}/zeddb/resources/*.rb"].each {|ci| require ci }
|
data/test/helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
require 'test/unit'
|
19
|
+
require 'rubygems'
|
20
|
+
require 'zeddb'
|
21
|
+
|
22
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
23
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
24
|
+
|
25
|
+
class Test::Unit::TestCase
|
26
|
+
TEST_GEMS_PROJECT_KEY = 'BE1OZog8gJogtQTosh'
|
27
|
+
TEST_GEMS_LOGIN = 'gems@zedkit.com'
|
28
|
+
TEST_GEMS_PASSWORD = 'NGIaDhr5vDlXo1tDs6bW3Gd'
|
29
|
+
|
30
|
+
def setup
|
31
|
+
Zedkit.configure do |zb|
|
32
|
+
zb.project_key = TEST_GEMS_PROJECT_KEY
|
33
|
+
# zb.exceptions = true
|
34
|
+
# zb.api_host = '0.0.0.0'
|
35
|
+
# zb.api_port = 5010
|
36
|
+
end
|
37
|
+
@uu = Zedkit::Users.verify(:username => TEST_GEMS_LOGIN, :password => TEST_GEMS_PASSWORD)
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
def pmodels
|
42
|
+
Zedkit::Projects::Models.get(:user_key => @uu['user_key'], :project => { :uuid => @uu['projects'][0] })
|
43
|
+
end
|
44
|
+
def item_model
|
45
|
+
pmodels.find {|i| i['name'] == 'item' }
|
46
|
+
end
|
47
|
+
end
|