class CrateAPI::Crate

Crate object class which is used to manipulate the single Crate object.

Attributes

files[R]

Public Class Methods

new(hash) click to toggle source
Calls superclass method
# File lib/crate_api/crate.rb, line 17
def initialize(hash)
  super(hash)
  @files = CrateAPI::Items.from_array(hash["files"])
end

Public Instance Methods

add_file(path) click to toggle source

Add a file to the given crate object.

@param [String] This is the path to the file that you wish to upload. @return [CrateFileAlreadyExistsError, nil] if there is an issue uploading the file to the crate, an error will be raised with the message explaining why.

# File lib/crate_api/crate.rb, line 42
def add_file(path)
  file = File.new(path)
  response = CrateAPI::Base.call("#{CrateAPI::Base::ITEMS_URL}/#{CrateAPI::Items::ITEM_ACTIONS[:upload]}", :post, {:body => {:file => file, :crate_id => @id}})
  raise CrateFileAlreadyExistsError, response["message"] unless response["status"] != "failure"
end
destroy() click to toggle source

Destroys the given crate object.

@return [CrateDestroyError, nil] if there is an issue destroying the crate, an error will be raised with the message explaining why.

# File lib/crate_api/crate.rb, line 25
def destroy
  response = JSON.parse(CrateAPI::Base.call("#{CrateAPI::Base::CRATES_URL}/#{CrateAPI::Crates::CRATE_ACTIONS[:destroy] % ["#{self.id}"]}", :post))
  raise CrateDestroyError, response["message"] unless response["status"] != "failure"
end
rename(name) click to toggle source

Renamed the given crate object.

@return [CrateRenameError, nil] if there is an issue with renaming the crate, an error will be raised with the message explaining why.

# File lib/crate_api/crate.rb, line 33
def rename(name)
  response = JSON.parse(CrateAPI::Base.call("#{CrateAPI::Base::CRATES_URL}/#{CrateAPI::Crates::CRATE_ACTIONS[:rename] % ["#{self.id}"]}", :post, {:body => {:name => name}}))
  raise CrateRenameError, response["message"] unless response["status"] != "failure"
end