class Craftar::Item

Attributes

collection[R]
content[R]
custom[R]
name[R]
resource_uri[R]
tags[R]
trackable[R]
url[R]
uuid[R]

Public Class Methods

craftar_name() click to toggle source
# File lib/craftar/item.rb, line 4
def self.craftar_name
  'item'
end
new(opts) click to toggle source
# File lib/craftar/item.rb, line 8
def initialize(opts)
  @name = opts[:name]
  @collection = opts[:collection]
  @url = opts[:url]
  @content = opts[:content]
  @custom = opts[:custom]
  @trackable = opts[:trackable]
  @uuid = opts[:uuid]
  @tags = opts[:tags]
  @resource_uri = opts[:resource_uri]
end

Public Instance Methods

save() click to toggle source
# File lib/craftar/item.rb, line 20
def save
  response = json_call(
    :post,
    {
     name: @name,
     collection: @collection,
     trackable: @trackable,
     content: @content,
     custom: @custom,
     tags: @tags
    }.select { |_, value| !value.nil? }
  )
  @uuid = response['uuid']
  @resource_uri = response['resource_uri']
  self
end
update(opts) click to toggle source
# File lib/craftar/item.rb, line 37
def update(opts)
  options = {
    name: opts[:name],
    collection: opts[:collection],
    url: opts[:url],
    content: opts[:content],
    custom: opts[:custom],
    tags: opts[:tags],
    trackable: opts[:trackable]
  }.select { |_, value| !value.nil? }
  response = json_call(:put, { uuid: @uuid }.merge(options))
  @name = response['name']
  @collection = response['collection']
  @tags = response['tags']
  @url = response['url']
  @content = response['content']
  @custom = response['custom']
  @trackable = response['trackable']
  self
end