Class: FakeS3::XmlAdapter
- Inherits:
-
Object
- Object
- FakeS3::XmlAdapter
- Defined in:
- lib/fakes3/xml_adapter.rb
Class Method Summary collapse
-
.acl(object = nil) ⇒ Object
ACL xml.
- .append_common_prefixes_to_list_bucket_result(lbr, prefixes) ⇒ Object
-
.append_objects_to_list_bucket_result(lbr, objects) ⇒ Object
<LastModified>2006-01-01T12:00:00.000Z</LastModified> <ETag>"828ef3fdfa96f00ad9f27c383fc9ac7f"</ETag> <Size>5</Size> <StorageClass>STANDARD</StorageClass> <Owner> <ID>bcaf161ca5fb16fd081034f</ID> <DisplayName>webfile</DisplayName> </Owner> </Contents>.
- .bucket(bucket) ⇒ Object
- .bucket_query(bucket_query) ⇒ Object
- .buckets(bucket_objects) ⇒ Object
-
.complete_multipart_result(object) ⇒ Object
<CompleteMultipartUploadResult> <Location>Example-Bucket.s3.amazonaws.com/Example-Object</Location> <Bucket>Example-Bucket</Bucket> <Key>Example-Object</Key> <ETag>“3858f62230ac3c915f300c664312c11f-9”</ETag> </CompleteMultipartUploadResult>.
-
.copy_object_result(object) ⇒ Object
<CopyObjectResult> <LastModified>2009-10-28T22:32:00</LastModified> <ETag>“9b2cf535f27731c974343645a3985328”</ETag> </CopyObjectResult>.
- .error(error) ⇒ Object
- .error_bucket_not_empty(name) ⇒ Object
-
.error_no_such_bucket(name) ⇒ Object
<?xml version=“1.0” encoding=“UTF-8”?> <Error>
NoSuchKey
<Message>The resource you requested does not exist</Message> <Resource>/mybucket/myfoto.jpg</Resource> <RequestId>4442587FB7D0A2F9</RequestId> </Error>. - .error_no_such_key(name) ⇒ Object
Class Method Details
.acl(object = nil) ⇒ Object
ACL xml
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/fakes3/xml_adapter.rb', line 166 def self.acl(object = nil) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.AccessControlPolicy(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |acp| acp.Owner do |owner| owner.ID("abc") owner.DisplayName("You") end acp.AccessControlList do |acl| acl.Grant do |grant| grant.Grantee("xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:type" => "CanonicalUser") do |grantee| grantee.ID("abc") grantee.DisplayName("You") end grant.Permission("FULL_CONTROL") end end } output end |
.append_common_prefixes_to_list_bucket_result(lbr, prefixes) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/fakes3/xml_adapter.rb', line 140 def self.append_common_prefixes_to_list_bucket_result(lbr, prefixes) return if prefixes.nil? or prefixes.size == 0 prefixes.each do |common_prefix| lbr.CommonPrefixes { |contents| contents.Prefix(common_prefix) } end end |
.append_objects_to_list_bucket_result(lbr, objects) ⇒ Object
<LastModified>2006-01-01T12:00:00.000Z</LastModified>
<ETag>"828ef3fdfa96f00ad9f27c383fc9ac7f"</ETag>
<Size>5</Size>
<StorageClass>STANDARD</StorageClass>
<Owner>
<ID>bcaf161ca5fb16fd081034f</ID>
<DisplayName>webfile</DisplayName>
</Owner>
</Contents>
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/fakes3/xml_adapter.rb', line 115 def self.append_objects_to_list_bucket_result(lbr,objects) return if objects.nil? or objects.size == 0 if objects.index(nil) require 'ruby-debug' Debugger.start debugger end objects.each do |s3_object| lbr.Contents { |contents| contents.Key(s3_object.name) contents.LastModified(s3_object.modified_date) contents.ETag("\"#{s3_object.md5}\"") contents.Size(s3_object.size) contents.StorageClass("STANDARD") contents.Owner { |owner| owner.ID("abc") owner.DisplayName("You") } } end end |
.bucket(bucket) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/fakes3/xml_adapter.rb', line 88 def self.bucket(bucket) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.ListBucketResult(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |lbr| lbr.Name(bucket.name) lbr.Prefix lbr.Marker lbr.MaxKeys("1000") lbr.IsTruncated("false") } output end |
.bucket_query(bucket_query) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/fakes3/xml_adapter.rb', line 148 def self.bucket_query(bucket_query) output = "" bucket = bucket_query.bucket xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.ListBucketResult(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |lbr| lbr.Name(bucket.name) lbr.Prefix(bucket_query.prefix) lbr.Marker(bucket_query.marker) lbr.MaxKeys(bucket_query.max_keys) lbr.IsTruncated(bucket_query.is_truncated?) append_objects_to_list_bucket_result(lbr,bucket_query.matches) append_common_prefixes_to_list_bucket_result(lbr, bucket_query.common_prefixes) } output end |
.buckets(bucket_objects) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fakes3/xml_adapter.rb', line 6 def self.buckets(bucket_objects) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.ListAllMyBucketsResult(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |lam| lam.Owner { |owner| owner.ID("123") owner.DisplayName("FakeS3") } lam.Buckets { |buckets| bucket_objects.each do |bucket| buckets.Bucket do |b| b.Name(bucket.name) b.CreationDate(bucket.creation_date.strftime("%Y-%m-%dT%H:%M:%S.000Z")) end end } } output end |
.complete_multipart_result(object) ⇒ Object
<CompleteMultipartUploadResult>
<Location>http://Example-Bucket.s3.amazonaws.com/Example-Object</Location>
<Bucket>Example-Bucket</Bucket>
<Key>Example-Object</Key>
<ETag>"3858f62230ac3c915f300c664312c11f-9"</ETag>
</CompleteMultipartUploadResult>
209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/fakes3/xml_adapter.rb', line 209 def self.complete_multipart_result(object) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.CompleteMultipartUploadResult { |result| result.Location("TODO: implement") result.Bucket("TODO: implement") result.Key(object.name) result.ETag("\"#{object.md5}\"") } output end |
.copy_object_result(object) ⇒ Object
<CopyObjectResult>
<LastModified>2009-10-28T22:32:00</LastModified>
<ETag>"9b2cf535f27731c974343645a3985328"</ETag>
</CopyObjectResult>
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/fakes3/xml_adapter.rb', line 192 def self.copy_object_result(object) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.CopyObjectResult { |result| result.LastModified(object.modified_date) result.ETag("\"#{object.md5}\"") } output end |
.error(error) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fakes3/xml_adapter.rb', line 27 def self.error(error) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.Error { |err| err.Code(error.code) err.Message(error.) err.Resource(error.resource) err.RequestId(1) } output end |
.error_bucket_not_empty(name) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fakes3/xml_adapter.rb', line 61 def self.error_bucket_not_empty(name) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.Error { |err| err.Code("BucketNotEmpty") err.Message("The bucket you tried to delete is not empty.") err.Resource(name) err.RequestId(1) } output end |
.error_no_such_bucket(name) ⇒ Object
<?xml version=“1.0” encoding=“UTF-8”?> <Error>
<Code>NoSuchKey</Code>
<Message>The resource you requested does not exist</Message>
<Resource>/mybucket/myfoto.jpg</Resource>
<RequestId>4442587FB7D0A2F9</RequestId>
</Error>
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fakes3/xml_adapter.rb', line 48 def self.error_no_such_bucket(name) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.Error { |err| err.Code("NoSuchBucket") err.Message("The resource you requested does not exist") err.Resource(name) err.RequestId(1) } output end |
.error_no_such_key(name) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fakes3/xml_adapter.rb', line 74 def self.error_no_such_key(name) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.Error { |err| err.Code("NoSuchKey") err.Message("The specified key does not exist") err.Key(name) err.RequestId(1) err.HostId(2) } output end |