Class: ZedDB::ModelItems

Inherits:
Object
  • Object
show all
Defined in:
lib/zeddb/resources/model_items.rb

Class Method Summary collapse

Class Method Details

.create(zks = {}, &block) ⇒ Object



60
61
62
# File 'lib/zeddb/resources/model_items.rb', line 60

def create(zks = {}, &block)
  Zedkit::Client.crud(:create, 'db/items', zks, [], &block)
end

.delete(zks = {}, &block) ⇒ Object



68
69
70
# File 'lib/zeddb/resources/model_items.rb', line 68

def delete(zks = {}, &block)
  Zedkit::Client.crud(:delete, "db/items/#{zks[:uuid]}", zks, [], &block)
end

.get(zks = {}, &block) ⇒ Object

ZedDB Models Data Items

All ZedDB models need data items. You can create, read, update, or delete model data items. To perform an operation on a specific model item you need its UUID, as available from the Models.get() method.

To get a Model Item:

ZedDB::ModelItems.get(:user_key => user['user_key'], :uuid => item['uuid'])

To update a Model Item:

ZedDB::ModelItems.update(:user_key => user['user_key'], :uuid => item['uuid'], :item => { :name => 'newname' })

To delete a Model Item:

ZedDB::ModelItems.delete(:user_key => user['user_key'], :uuid => item['uuid])

To create a new Model Item you submit the required parameters with the model UUID that you are creating the model item within. Whatever items you send within the :item Hash are passed through to the ZedAPI untouched. There is no client side validation within this gem.

ZedDB::ModelItems.create(:user_key => user['user_key'],
                         :model => { :uuid => model['uuid'] }, :item => { :name => 'whatever' })

From each of these requests the Zedkit::Client class will return a response hash for your reference, if needed, or as applicable to the request. If there was a HTTP 401 or 404 you will get a nil response. This indicates a security failure or that an UUID is incorrect, not attached the user’s account, or non-existent.

For each request you can also pass a block to process the response directly:

ZedDB::ModelItems.get(:user_key => user['user_key'], :uuid => model['uuid']) do |result|
end


56
57
58
# File 'lib/zeddb/resources/model_items.rb', line 56

def get(zks = {}, &block)
  Zedkit::Client.crud(:get, "db/items/#{zks[:uuid]}", zks, [], &block)
end

.update(zks = {}, &block) ⇒ Object



64
65
66
# File 'lib/zeddb/resources/model_items.rb', line 64

def update(zks = {}, &block)
  Zedkit::Client.crud(:update, "db/items/#{zks[:uuid]}", zks, [], &block)
end