Class: CrateAPI::Crate
- Inherits:
-
CrateObject
- Object
- CrateObject
- CrateAPI::Crate
- Defined in:
- lib/crate_api/crate.rb
Overview
Crate object class which is used to manipulate the single Crate object.
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Attributes inherited from CrateObject
Instance Method Summary collapse
-
#add_file(path) ⇒ CrateFileAlreadyExistsError?
Add a file to the given crate object.
-
#destroy ⇒ CrateDestroyError?
Destroys the given crate object.
-
#initialize(hash) ⇒ Crate
constructor
A new instance of Crate.
-
#rename(name) ⇒ CrateRenameError?
Renamed the given crate object.
Methods inherited from CrateObject
Constructor Details
#initialize(hash) ⇒ Crate
Returns a new instance of Crate.
17 18 19 20 |
# File 'lib/crate_api/crate.rb', line 17 def initialize(hash) super(hash) @files = CrateAPI::Items.from_array(hash["files"]) end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
16 17 18 |
# File 'lib/crate_api/crate.rb', line 16 def files @files end |
Instance Method Details
#add_file(path) ⇒ CrateFileAlreadyExistsError?
Add a file to the given crate object.
42 43 44 45 46 |
# 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 ⇒ CrateDestroyError?
Destroys the given crate object.
25 26 27 28 |
# 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) ⇒ CrateRenameError?
Renamed the given crate object.
33 34 35 36 |
# 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 |