Class: StudioApi::File
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- StudioApi::File
- Extended by:
- StudioResource
- Defined in:
- lib/studio_api/file.rb
Overview
Represents overlay files which can be loaded to appliance.
Supports finding files for appliance, updating metadata, deleting, uploading and downloading.
StudioApi::File.find :all, :params => { :appliance_id => 1234 }
file = StudioApi::File.find 1234 file.owner = “root” file.path = “/etc” file.filename = “pg.conf” file.save
Class Method Summary collapse
-
.upload(content, appliance_id, options = {}) ⇒ StudioApi::File
Uploads file to appliance.
Instance Method Summary collapse
-
#content ⇒ String
Downloads file to output.
-
#overwrite(content) ⇒ StudioApi::File
Overwritte file content and keep metadata ( of course without such things like size ) Immediatelly store new content.
Methods included from StudioResource
collection_path, element_path, extended, studio_connection, studio_connection=
Class Method Details
.upload(content, appliance_id, options = {}) ⇒ StudioApi::File
Uploads file to appliance
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/studio_api/file.rb', line 53 def self.upload ( content, appliance_id, = {}) request_str = "files?appliance_id=#{appliance_id.to_i}" .each do |k,v| request_str << "&#{CGI.escape k.to_s}=#{CGI.escape v.to_s}" end rq = GenericRequest.new studio_connection response = rq.post request_str, :file => content if defined? ActiveModel #rails 3 and ActiveResource persistency File.new Hash.from_xml(response)["file"],true else File.new Hash.from_xml(response)["file"] end end |
Instance Method Details
#content ⇒ String
Downloads file to output. Allow downloading to stream or to path.
31 32 33 34 |
# File 'lib/studio_api/file.rb', line 31 def content rq = GenericRequest.new self.class.studio_connection rq.get "/files/#{id.to_i}/data" end |
#overwrite(content) ⇒ StudioApi::File
Overwritte file content and keep metadata ( of course without such things like size ) Immediatelly store new content
40 41 42 43 44 45 |
# File 'lib/studio_api/file.rb', line 40 def overwrite ( content ) request_str = "/files/#{id.to_i}/data" rq = GenericRequest.new self.class.studio_connection response = rq.put request_str, :file => content load Hash.from_xml(response)["file"] end |