diff --git a/lib/fog/aws/models/storage/file.rb b/lib/fog/aws/models/storage/file.rb index 2b704c507..5883cf5aa 100644 --- a/lib/fog/aws/models/storage/file.rb +++ b/lib/fog/aws/models/storage/file.rb @@ -1,4 +1,5 @@ require 'fog/core/model' +require 'fog/aws/models/storage/versions' module Fog module Storage @@ -132,6 +133,15 @@ module Fog collection.get_https_url(key, expires, options) end + def versions + @versions ||= begin + Fog::Storage::AWS::Versions.new( + :file => self, + :connection => connection + ) + end + end + private def directory=(new_directory) diff --git a/lib/fog/aws/models/storage/version.rb b/lib/fog/aws/models/storage/version.rb new file mode 100644 index 000000000..5e83cd6a4 --- /dev/null +++ b/lib/fog/aws/models/storage/version.rb @@ -0,0 +1,24 @@ +require 'fog/core/model' + +module Fog + module Storage + class AWS + + class Version < Fog::Model + + identity :version, :aliases => 'VersionId' + + attribute :key, :aliases => 'Key' + attribute :last_modified, :aliases => ['Last-Modified', 'LastModified'] + attribute :latest, :aliases => 'IsLatest', :type => :boolean + attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer + attribute :delete_marker, :type => :boolean + + def file + @file ||= collection.file.directory.files.get(key, 'versionId' => version) + end + end + + end + end +end diff --git a/lib/fog/aws/models/storage/versions.rb b/lib/fog/aws/models/storage/versions.rb new file mode 100644 index 000000000..42f1ccd5d --- /dev/null +++ b/lib/fog/aws/models/storage/versions.rb @@ -0,0 +1,34 @@ +require 'fog/core/collection' +require 'fog/aws/models/storage/version' + +module Fog + module Storage + class AWS + + class Versions < Fog::Collection + + attribute :file + + model Fog::Storage::AWS::Version + + def all + data = connection.get_bucket_object_versions(file.directory.key, :prefix => file.key).body['Versions'] + load(data) + end + + def new(attributes = {}) + requires :file + + version_type = attributes.keys.first + + model = super({ :file => file }.merge!(attributes[version_type])) + model.delete_marker = version_type == 'DeleteMarker' + + model + end + + end + + end + end +end \ No newline at end of file