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 #include <alibabacloud/oss/model/SetBucketStorageCapacityRequest.h>
18 #include "utils/Utils.h"
19 #include "ModelError.h"
20 #include <sstream>
21 
22 using namespace AlibabaCloud::OSS;
23 
SetBucketStorageCapacityRequest(const std::string & bucket,int64_t storageCapacity)24 SetBucketStorageCapacityRequest::SetBucketStorageCapacityRequest(const std::string &bucket, int64_t storageCapacity) :
25     OssBucketRequest(bucket),
26     storageCapacity_(storageCapacity)
27 {
28     setFlags(Flags() | REQUEST_FLAG_CONTENTMD5);
29 }
30 
specialParameters() const31 ParameterCollection SetBucketStorageCapacityRequest::specialParameters() const
32 {
33     ParameterCollection parameters;
34     parameters["qos"] = "";
35     return parameters;
36 }
37 
payload() const38 std::string SetBucketStorageCapacityRequest::payload() const
39 {
40     std::stringstream ss;
41     ss << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
42     ss << "<BucketUserQos>" << std::endl;
43     ss << "  <StorageCapacity>" << std::to_string(storageCapacity_) << "</StorageCapacity>" << std::endl;
44     ss << "</BucketUserQos>" << std::endl;
45     return ss.str();
46 }
47 
validate() const48 int SetBucketStorageCapacityRequest::validate() const
49 {
50     int ret;
51     if ((ret = OssBucketRequest::validate()) != 0) {
52         return ret;
53     }
54 
55     if (storageCapacity_ < 0)
56         return ARG_ERROR_STORAGECAPACITY_INVALID;
57 
58     return 0;
59 }
60 
61 
62