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 {|socket response segment| ... } ⇒ 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
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/studio_api/file.rb', line 58 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 {|socket response segment| ... } ⇒ String?
Downloads file to output. Allow downloading to stream or to path. @yieldparam[body segment] buffered chunk of body
35 36 37 38 39 |
# File 'lib/studio_api/file.rb', line 35 def content &block rq = GenericRequest.new self.class.studio_connection path = "/files/#{id.to_i}/data" block_given? ? rq.get_file(path, &block) : rq.get(path) end |
#overwrite(content) ⇒ StudioApi::File
Overwritte file content and keep metadata ( of course without such things like size ) Immediatelly store new content
45 46 47 48 49 50 |
# File 'lib/studio_api/file.rb', line 45 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 |