Class: Shuck::XmlAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/shuck/xml_adapter.rb

Class Method Summary collapse

Class Method Details

.acl(object = nil) ⇒ Object

ACL xml



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/shuck/xml_adapter.rb', line 76

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

.bucket(bucket) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/shuck/xml_adapter.rb', line 61

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

.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/shuck/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("Shuck")
    }
    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

.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>



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/shuck/xml_adapter.rb', line 34

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



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/shuck/xml_adapter.rb', line 47

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