Class: CrateAPI::Item

Inherits:
CrateObject show all
Defined in:
lib/crate_api/item.rb

Overview

Item class which is used to manipulate and represent a file blob which is inside of a Crate.

Instance Attribute Summary collapse

Attributes inherited from CrateObject

#id, #name, #short_code

Instance Method Summary collapse

Methods inherited from CrateObject

#short_url

Constructor Details

#initialize(hash) ⇒ CrateAPI::Item

Default initializer for the Item object.

Parameters:

  • hash (Hash)

    an item hash.



13
14
15
16
# File 'lib/crate_api/item.rb', line 13

def initialize(hash)
  super(hash)
  @size = hash["size"]
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'lib/crate_api/item.rb', line 8

def size
  @size
end

Instance Method Details

#destroynil

Will destroy the given file.

Returns:

  • (nil)

    this method should return nil if there are no issues.

Raises:



22
23
24
25
# File 'lib/crate_api/item.rb', line 22

def destroy
  response = JSON.parse(CrateAPI::Base.call("#{CrateAPI::Base::ITEMS_URL}/#{CrateAPI::Items::ITEM_ACTIONS[:destroy] % ["#{self.id}"]}", :post))
  raise FileDestroyError, response["message"] unless response["status"] != "failure"
end