Module: Instances

Included in:
Content
Defined in:
lib/user/content/instances.rb

Instance Method Summary collapse

Instance Method Details

#add_variant_value_to_instance(id, data, options = nil) ⇒ Object



93
94
95
# File 'lib/user/content/instances.rb', line 93

def add_variant_value_to_instance(id, data, options = nil)
  @client.raw('post', "/content/instances/#{id}/variant-value", options, data_transform(data))
end

#create_instance(data, options = nil) ⇒ Object

Create instance.

Create a instance with data.

Parameters

data

(Hash) – Data to be submitted.

Example

data = {
  user_id: 1,
  slug: "new-instance",
  instance_template_id: 1
}

options = { fields: 'id,slug' }

@data = @cxf_user.create_instance(data, options)


78
79
80
# File 'lib/user/content/instances.rb', line 78

def create_instance(data, options = nil)
  @client.raw('post', '/content/instances', options, data_transform(data))
end

#create_instance_version(id, data, options = nil) ⇒ Object

Create instance version.

Create a instance version with data.

Parameters

id

(Integer) – instance id.

data

(Hash) – Data to be submitted.

options

(Hash) – List of Resource Collection Options shown above can be used as parameter.



89
90
91
# File 'lib/user/content/instances.rb', line 89

def create_instance_version(id, data, options = nil)
  @client.raw('post', "/content/instances/#{id}/print-version", options, data_transform(data))
end

#create_item_code_for_instance(id, data, options = nil) ⇒ Object

Create item code for instance.

Create a item code for a instance with data.

Parameters

id

(Integer) – instance id.

data

(Hash) – Data to be submitted.

options

(Hash) – List of Resource Collection Options shown above can be used as parameter.



126
127
128
# File 'lib/user/content/instances.rb', line 126

def create_item_code_for_instance(id, data, options = nil)
  @client.raw('post', "/content/instances/#{id}/item-codes", options, data_transform(data))
end

#delete_instance(id) ⇒ Object

Delete instance.

Delete a instance.

Parameters

id

(Integer) – instance id.

Example

@data = @cxf_user.delete_instance(6)


155
156
157
# File 'lib/user/content/instances.rb', line 155

def delete_instance(id)
  @client.raw('delete', "/content/instances/#{id}")
end

#delete_variant_value_from_instance(id, data, options = nil) ⇒ Object

Delete variant value from instance.

Delete a variant value from a instance.

Parameters

id

(Integer) – instance id.

data

(Hash) – Data to be submitted.

options

(Hash) – List of Resource Collection Options shown above can be used as parameter.



104
105
106
# File 'lib/user/content/instances.rb', line 104

def delete_variant_value_from_instance(id, data, options = nil)
  @client.raw('delete', "/content/instances/#{id}/variant-value", options, data_transform(data))
end

#duplicate_instance(id, data) ⇒ Object

Duplicate instance.

Duplicate a instance.

Parameters

id

(Integer) – instance id.

data

(Hash) – Data to be submitted.

Example

data = { options: [] }
@data = @cxf_user.duplicate_instance(1, data.to_json)


14
15
16
# File 'lib/user/content/instances.rb', line 14

def duplicate_instance(id, data)
  @client.raw('post', "/content/instances/#{id}/duplicate", nil, data)
end

#get_instance(id, options = nil) ⇒ Object

Get instance.

Get a instance info.

Parameters

id

(Integer) – instance id.

options

(Hash) – List of Resource Collection Options shown above can be used as parameter.

First Example

@data = @cxf_user.get_instance(1)

Second Example

options = {
  fields: 'id, slug'
}
@data = @cxf_user.get_instance(1, options)


58
59
60
# File 'lib/user/content/instances.rb', line 58

def get_instance(id, options = nil)
  @client.raw('get', "/content/instances/#{id}", options)
end

#get_instances(options = nil, use_post = true) ⇒ Object

Get instances.

Get a collection of instances.

Parameters

options

(Hash) – List of Resource Collection Options shown above can be used as parameter.

use_post

(Boolean) – Variable to determine if the request is by ‘post’ or ‘get’ functions.

First Example

@data = @cxf_user.get_instances

Second Example

options = {
  fields: 'id, slug'
}
@data = @cxf_user.get_instances(options)

Third Example

options = {
  fields: 'id, slug'
}
@data = @cxf_user.get_instances(options, true)


39
40
41
# File 'lib/user/content/instances.rb', line 39

def get_instances(options = nil, use_post = true)
  get_query_results('/content/instances', options, use_post)
end

#get_intance_variations(id, options = nil) ⇒ Object

Get instance variations.

Get a collection of instance variations.

Parameters

id

(Integer) – instance id.

options

(Hash) – List of Resource Collection Options shown above can be used as parameter.



115
116
117
# File 'lib/user/content/instances.rb', line 115

def get_intance_variations(id, options = nil)
  @client.raw('get', "/content/instances/#{id}/build-variations", options)
end

#update_instance(id, data, options = nil) ⇒ Object

Update instance.

Update a instance info.

Parameters

id

(Integer) – instance id.

data

(Hash) – Data to be submitted.

Example

data = {
  user_id: 1,
  slug: 'new-instance'
}
@data = @cxf_user.update_instance(5, data)


143
144
145
# File 'lib/user/content/instances.rb', line 143

def update_instance(id, data, options = nil)
  @client.raw('put', "/content/instances/#{id}", options, data_transform(data))
end