class Fog::Storage::Atmos::File
Public Instance Methods
body()
click to toggle source
# File lib/fog/atmos/models/storage/file.rb, line 15 def body attributes[:body] ||= if objectid collection.get(identity).body else '' end end
body=(new_body)
click to toggle source
# File lib/fog/atmos/models/storage/file.rb, line 23 def body=(new_body) attributes[:body] = new_body end
copy(target_directory_key, target_file_key, options={})
click to toggle source
# File lib/fog/atmos/models/storage/file.rb, line 31 def copy(target_directory_key, target_file_key, options={}) target_directory = service.directories.new(:key => target_directory_key) target_directory.files.create( :key => target_file_key, :body => body ) end
destroy()
click to toggle source
# File lib/fog/atmos/models/storage/file.rb, line 39 def destroy requires :directory, :key service.delete_namespace([directory.key, key].join('/')) true end
directory()
click to toggle source
# File lib/fog/atmos/models/storage/file.rb, line 27 def directory @directory end
public=(new_public)
click to toggle source
def owner=(new_owner)
if new_owner attributes[:owner] = { :display_name => new_owner['DisplayName'], :id => new_owner['ID'] } end
end
# File lib/fog/atmos/models/storage/file.rb, line 54 def public=(new_public) # NOOP - we don't need to flag files as public, getting the public URL for a file handles it. end
public_url(expires = (Time.now + 5 * 365 * 24 * 60 * 60))
click to toggle source
By default, expire in 5 years
# File lib/fog/atmos/models/storage/file.rb, line 59 def public_url(expires = (Time.now + 5 * 365 * 24 * 60 * 60)) file = directory.files.head(key) self.objectid = if file && file.to_s.strip != "" then file.attributes['x-emc-meta'].scan(/objectid=(\w+),/).flatten[0] else nil end if self.objectid && self.objectid.to_s.strip != "" uri = URI::HTTP.build(:scheme => service.ssl? ? "http" : "https" , :host => service.host, :port => service.port.to_i, :path => "/rest/objects/#{self.objectid}" ) sb = "GET\n" sb += uri.path.downcase + "\n" sb += service.uid + "\n" sb += String(expires.to_i()) signature = service.sign( sb ) uri.query = "uid=#{CGI::escape(service.uid)}&expires=#{expires.to_i()}&signature=#{CGI::escape(signature)}" uri.to_s else nil end end
save(options = {})
click to toggle source
# File lib/fog/atmos/models/storage/file.rb, line 78 def save(options = {}) requires :body, :directory, :key directory.kind_of?(Directory) ? ns = directory.key : ns = directory ns += key options[:headers] ||= {} options[:headers]['Content-Type'] = content_type if content_type options[:body] = body begin data = service.post_namespace(ns, options) self.objectid = data.headers['location'].split('/')[-1] rescue => error if error.message =~ /The resource you are trying to create already exists./ data = service.put_namespace(ns, options) else raise error end end # merge_attributes(data.headers) true end
Private Instance Methods
directory=(new_directory)
click to toggle source
# File lib/fog/atmos/models/storage/file.rb, line 101 def directory=(new_directory) @directory = new_directory end