1 /*
2  * Copyright 2009-2017 Alibaba Cloud All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <alibabacloud/oss/model/DeleteObjectVersionsRequest.h>
19 #include <sstream>
20 #include "utils/Utils.h"
21 
22 using namespace AlibabaCloud::OSS;
23 
DeleteObjectVersionsRequest(const std::string & bucket)24 DeleteObjectVersionsRequest::DeleteObjectVersionsRequest(const std::string &bucket) :
25     OssBucketRequest(bucket),
26     quiet_(false),
27     encodingType_(),
28     requestPayer_(RequestPayer::NotSet)
29 {
30     setFlags(Flags() | REQUEST_FLAG_CONTENTMD5);
31 }
32 
Quiet() const33 bool DeleteObjectVersionsRequest::Quiet() const
34 {
35     return quiet_;
36 }
37 
EncodingType() const38 const std::string &DeleteObjectVersionsRequest::EncodingType() const
39 {
40     return encodingType_;
41 }
42 
addObject(const ObjectIdentifier & object)43 void DeleteObjectVersionsRequest::addObject(const ObjectIdentifier& object)
44 {
45     objects_.push_back(object);
46 }
47 
setObjects(const ObjectIdentifierList & objects)48 void DeleteObjectVersionsRequest::setObjects(const ObjectIdentifierList& objects)
49 {
50     objects_ = objects;
51 }
52 
Objects() const53 const ObjectIdentifierList& DeleteObjectVersionsRequest::Objects() const
54 {
55     return objects_;
56 }
57 
clearObjects()58 void DeleteObjectVersionsRequest::clearObjects()
59 {
60     objects_.clear();
61 }
62 
setQuiet(bool quiet)63 void DeleteObjectVersionsRequest::setQuiet(bool quiet)
64 {
65     quiet_ = quiet;
66 }
67 
setEncodingType(const std::string & value)68 void DeleteObjectVersionsRequest::setEncodingType(const std::string &value)
69 {
70     encodingType_ = value;
71 }
72 
setRequestPayer(RequestPayer value)73 void DeleteObjectVersionsRequest::setRequestPayer(RequestPayer value)
74 {
75     requestPayer_ = value;
76 }
77 
payload() const78 std::string DeleteObjectVersionsRequest::payload() const
79 {
80     std::stringstream ss;
81     ss << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
82     ss << "<Delete>" << std::endl;
83     ss << "  <Quiet>" << (quiet_ ? "true":"false") << "</Quiet>" << std::endl;
84     for (auto const& object : objects_) {
85     ss << "  <Object>" << std::endl << "";
86     ss << "    <Key>" << XmlEscape(object.Key()) << "</Key>" << std::endl;
87     if (!object.VersionId().empty()) {
88     ss << "    <VersionId>" << object.VersionId() << "</VersionId>" << std::endl;
89     }
90     ss << "  </Object>" << std::endl;
91     }
92     ss << "</Delete>" << std::endl;
93     return ss.str();
94 }
95 
specialParameters() const96 ParameterCollection DeleteObjectVersionsRequest::specialParameters() const
97 {
98     ParameterCollection parameters;
99     parameters["delete"] = "";
100     if (!encodingType_.empty()) {
101         parameters["encoding-type"] = encodingType_;
102     }
103     return parameters;
104 }
105 
specialHeaders() const106 HeaderCollection DeleteObjectVersionsRequest::specialHeaders() const
107 {
108     HeaderCollection headers;
109     if (requestPayer_ == RequestPayer::Requester) {
110         headers["x-oss-request-payer"] = ToLower(ToRequestPayerName(RequestPayer::Requester));
111     }
112     return headers;
113 }
114