Method: Fog::Storage::Ninefold::File#public_url

Defined in:
lib/fog/ninefold/models/storage/file.rb

#public_url(expires = (Time.now + 5 * 365 * 24 * 60 * 60)) ⇒ Object

By default, expire in 5 years



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fog/ninefold/models/storage/file.rb', line 59

def public_url(expires = (Time.now + 5 * 365 * 24 * 60 * 60))
  requires :objectid
  # TODO - more efficient method to get this?
  storage = Fog::Storage.new(:provider => 'Ninefold')
  uri = URI::HTTP.build(:scheme => Fog::Storage::Ninefold::STORAGE_SCHEME, :host => Fog::Storage::Ninefold::STORAGE_HOST, :port => Fog::Storage::Ninefold::STORAGE_PORT.to_i, :path => "/rest/objects/#{objectid}" )
  Fog::Storage.new(:provider => 'Ninefold').uid


  sb = "GET\n"
  sb += uri.path.downcase + "\n"
  sb += storage.uid + "\n"
  sb += String(expires.to_i())

  signature = storage.sign( sb )
  uri.query = "uid=#{CGI::escape(storage.uid)}&expires=#{expires.to_i()}&signature=#{CGI::escape(signature)}"
  uri.to_s
end