def public_url(expires = (Time.now + 5 * 365 * 24 * 60 * 60))
file = directory.files.head(key)
self.objectid = if file.present? then file.attributes['x-emc-meta'].scan(/objectid=(\w+),/).flatten[0] else nil end
if self.objectid.present?
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