Class: Aliyun::Oss::XmlGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyun/oss/xml_generator.rb

Class Method Summary collapse

Class Method Details

.generate_complete_multipart_xml(parts) ⇒ Object

Generate xml for complete multipart from parts

Examples:

<CompleteMultipartUpload>
 <Part>
   <PartNumber>PartNumber</PartNumber>
   <ETag>ETag</ETag>
 </Part>
 ...
</CompleteMultipartUpload>


86
87
88
89
90
91
# File 'lib/aliyun/oss/xml_generator.rb', line 86

def self.generate_complete_multipart_xml(parts)
  Utils.to_xml(
    'CompleteMultipartUpload' => {
      'Part' => parts.map(&:to_hash)
    })
end

.generate_cors_rules(rules) ⇒ Object

Generate xml for cors from rules

Examples:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration>
    <CORSRule>
      <AllowedOrigin>the origin you want allow CORS request from</AllowedOrigin>
      <AllowedOrigin>...AllowedOrigin>
      <AllowedMethod>HTTP method</AllowedMethod>
      <AllowedMethod>...AllowedMethod>
        <AllowedHeader> headers that allowed browser to send</AllowedHeader>
          <AllowedHeader>...AllowedHeader>
          <ExposeHeader> headers in response that can access from client app</ExposeHeader>
          <ExposeHeader>...ExposeHeader>
          <MaxAgeSeconds>time to cache pre-fight response</MaxAgeSeconds>
    </CORSRule>
    <CORSRule>
    ...
    </CORSRule>
...
</CORSConfiguration >


47
48
49
50
51
52
# File 'lib/aliyun/oss/xml_generator.rb', line 47

def self.generate_cors_rules(rules)
  Utils.to_xml(
    'CORSConfiguration' => {
      'CORSRule' => rules.map(&:to_hash)
    })
end

.generate_create_bucket_xml(location) ⇒ Object

Generate xml for #bucket_create with location

Examples:

<?xml version="1.0" encoding="UTF-8"?>
<CreateBucketConfiguration>
 <LocationConstraint>BucketRegion</LocationConstraint>
</CreateBucketConfiguration>


101
102
103
104
105
106
107
108
# File 'lib/aliyun/oss/xml_generator.rb', line 101

def self.generate_create_bucket_xml(location)
  configuration = {
    'CreateBucketConfiguration' => {
      'LocationConstraint' => location
    }
  }
  Utils.to_xml(configuration)
end

.generate_delete_objects_xml(keys, quiet) ⇒ Object

Generate xml for delete objects

Examples:

<?xml version="1.0" encoding="UTF-8"?>
<Delete>
  <Quiet>true</Quiet>
  <Object>
    <Key>key</Key>
  </Object>
...
</Delete>


66
67
68
69
70
71
72
73
# File 'lib/aliyun/oss/xml_generator.rb', line 66

def self.generate_delete_objects_xml(keys, quiet)
  key_objects = keys.map { |key| { 'Key' => key } }
  Utils.to_xml(
    'Delete' => {
      'Object' => key_objects,
      'Quiet' => quiet
    })
end

.generate_enable_logging_xml(target_bucket, target_prefix) ⇒ Object

Generate xml for enable logging

Examples:

<?xml version="1.0" encoding="UTF-8"?>
<BucketLoggingStatus>
  <LoggingEnabled>
   <TargetBucket>TargetBucket</TargetBucket>
   <TargetPrefix>TargetPrefix</TargetPrefix>
  </LoggingEnabled>
</BucketLoggingStatus>


121
122
123
124
125
126
127
128
# File 'lib/aliyun/oss/xml_generator.rb', line 121

def self.generate_enable_logging_xml(target_bucket, target_prefix)
  logging = { 'TargetBucket' => target_bucket }
  logging.merge!('TargetPrefix' => target_prefix) if target_prefix
  Utils.to_xml(
    'BucketLoggingStatus' => {
      'LoggingEnabled' => logging
    })
end

.generate_enable_website_xml(suffix, key) ⇒ Object

Generate xml for enable website

Examples:

<?xml version="1.0" encoding="UTF-8"?>
<WebsiteConfiguration>
  <IndexDocument>
   <Suffix>index.html</Suffix>
  </IndexDocument>
  <ErrorDocument>
   <Key>errorDocument.html</Key>
  </ErrorDocument>
</WebsiteConfiguration>


143
144
145
146
147
# File 'lib/aliyun/oss/xml_generator.rb', line 143

def self.generate_enable_website_xml(suffix, key)
  website_configuration = { 'IndexDocument' => { 'Suffix' => suffix } }
  website_configuration.merge!('ErrorDocument' => { 'Key' => key }) if key
  Utils.to_xml('WebsiteConfiguration' => website_configuration)
end

.generate_lifecycle_rules(rules) ⇒ Object

Generate xml from rules

Examples:

<?xml version="1.0" encoding="UTF-8"?>
<LifecycleConfiguration>
  <Rule>
    <ID>RuleID</ID>
    <Prefix>Prefix</Prefix>
    <Status>Status</Status>
    <Expiration>
      <Days>Days</Days>
    </Expiration>
  </Rule>
</LifecycleConfiguration>


18
19
20
21
22
23
# File 'lib/aliyun/oss/xml_generator.rb', line 18

def self.generate_lifecycle_rules(rules)
  Utils.to_xml(
    'LifecycleConfiguration' => {
      'Rule' => rules.map(&:to_hash)
    })
end

.generate_set_referer_xml(referers, allowed_empty) ⇒ Object

Generate xml for set referer

Examples:

<?xml version="1.0" encoding="UTF-8"?>
<RefererConfiguration>
  <AllowEmptyReferer>true</AllowEmptyReferer >
  <RefererList>
   <Referer> http://www.aliyun.com</Referer>
   <Referer> https://www.aliyun.com</Referer>
   <Referer> http://www.*.com</Referer>
   <Referer> https://www.?.aliyuncs.com</Referer>
  </ RefererList>
</RefererConfiguration>


163
164
165
166
167
168
169
170
171
# File 'lib/aliyun/oss/xml_generator.rb', line 163

def self.generate_set_referer_xml(referers, allowed_empty)
  Utils.to_xml(
    'RefererConfiguration' => {
      'AllowEmptyReferer' => allowed_empty,
      'RefererList' => {
        'Referer' => referers
      }
    })
end