sdk-team 6 år sedan
förälder
incheckning
14ebba9911

+ 3 - 0
CHANGELOG

@@ -1,3 +1,6 @@
+2020-10-16 Version: patch
+- Metering.
+
 2020-10-16 Version: patch
 - Supported AndroidNotificationNotifyId for Push and MassPush.
 - Supported iOSNotificationCollapseId for Push and MassPush.

+ 4 - 0
metering/CMakeLists.txt

@@ -21,11 +21,15 @@ set(metering_public_header
 	include/alibabacloud/metering/MeteringExport.h )
 
 set(metering_public_header_model 
+	include/alibabacloud/metering/model/PostDataRequest.h
+	include/alibabacloud/metering/model/PostDataResult.h
 	include/alibabacloud/metering/model/SyncDataRequest.h
 	include/alibabacloud/metering/model/SyncDataResult.h )
 
 set(metering_src 
 	src/MeteringClient.cc
+	src/model/PostDataRequest.cc
+	src/model/PostDataResult.cc
 	src/model/SyncDataRequest.cc
 	src/model/SyncDataResult.cc )
 

+ 8 - 0
metering/include/alibabacloud/metering/MeteringClient.h

@@ -22,6 +22,8 @@
 #include <alibabacloud/core/EndpointProvider.h>
 #include <alibabacloud/core/RoaServiceClient.h>
 #include "MeteringExport.h"
+#include "model/PostDataRequest.h"
+#include "model/PostDataResult.h"
 #include "model/SyncDataRequest.h"
 #include "model/SyncDataResult.h"
 
@@ -33,6 +35,9 @@ namespace AlibabaCloud
 		class ALIBABACLOUD_METERING_EXPORT MeteringClient : public RoaServiceClient
 		{
 		public:
+			typedef Outcome<Error, Model::PostDataResult> PostDataOutcome;
+			typedef std::future<PostDataOutcome> PostDataOutcomeCallable;
+			typedef std::function<void(const MeteringClient*, const Model::PostDataRequest&, const PostDataOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> PostDataAsyncHandler;
 			typedef Outcome<Error, Model::SyncDataResult> SyncDataOutcome;
 			typedef std::future<SyncDataOutcome> SyncDataOutcomeCallable;
 			typedef std::function<void(const MeteringClient*, const Model::SyncDataRequest&, const SyncDataOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> SyncDataAsyncHandler;
@@ -41,6 +46,9 @@ namespace AlibabaCloud
 			MeteringClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
 			MeteringClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
 			~MeteringClient();
+			PostDataOutcome postData(const Model::PostDataRequest &request)const;
+			void postDataAsync(const Model::PostDataRequest& request, const PostDataAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
+			PostDataOutcomeCallable postDataCallable(const Model::PostDataRequest& request) const;
 			SyncDataOutcome syncData(const Model::SyncDataRequest &request)const;
 			void syncDataAsync(const Model::SyncDataRequest& request, const SyncDataAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
 			SyncDataOutcomeCallable syncDataCallable(const Model::SyncDataRequest& request) const;

+ 69 - 0
metering/include/alibabacloud/metering/model/PostDataRequest.h

@@ -0,0 +1,69 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ALIBABACLOUD_METERING_MODEL_POSTDATAREQUEST_H_
+#define ALIBABACLOUD_METERING_MODEL_POSTDATAREQUEST_H_
+
+#include <string>
+#include <vector>
+#include <alibabacloud/core/RoaServiceRequest.h>
+#include <alibabacloud/metering/MeteringExport.h>
+
+namespace AlibabaCloud
+{
+	namespace Metering
+	{
+		namespace Model
+		{
+			class ALIBABACLOUD_METERING_EXPORT PostDataRequest : public RoaServiceRequest
+			{
+
+			public:
+				PostDataRequest();
+				~PostDataRequest();
+
+				std::string getInstanceId()const;
+				void setInstanceId(const std::string& instanceId);
+				std::string getData()const;
+				void setData(const std::string& data);
+				std::string getDataType()const;
+				void setDataType(const std::string& dataType);
+				std::string getEndTime()const;
+				void setEndTime(const std::string& endTime);
+				std::string getStartTime()const;
+				void setStartTime(const std::string& startTime);
+				std::string getCommodityCode()const;
+				void setCommodityCode(const std::string& commodityCode);
+				std::string getRegion()const;
+				void setRegion(const std::string& region);
+				std::string getUserId()const;
+				void setUserId(const std::string& userId);
+
+            private:
+				std::string instanceId_;
+				std::string data_;
+				std::string dataType_;
+				std::string endTime_;
+				std::string startTime_;
+				std::string commodityCode_;
+				std::string region_;
+				std::string userId_;
+
+			};
+		}
+	}
+}
+#endif // !ALIBABACLOUD_METERING_MODEL_POSTDATAREQUEST_H_

+ 57 - 0
metering/include/alibabacloud/metering/model/PostDataResult.h

@@ -0,0 +1,57 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ALIBABACLOUD_METERING_MODEL_POSTDATARESULT_H_
+#define ALIBABACLOUD_METERING_MODEL_POSTDATARESULT_H_
+
+#include <string>
+#include <vector>
+#include <utility>
+#include <alibabacloud/core/ServiceResult.h>
+#include <alibabacloud/metering/MeteringExport.h>
+
+namespace AlibabaCloud
+{
+	namespace Metering
+	{
+		namespace Model
+		{
+			class ALIBABACLOUD_METERING_EXPORT PostDataResult : public ServiceResult
+			{
+			public:
+
+
+				PostDataResult();
+				explicit PostDataResult(const std::string &payload);
+				~PostDataResult();
+				bool getData()const;
+				std::string getErrMessage()const;
+				bool getSuccess()const;
+				int getErrCode()const;
+
+			protected:
+				void parse(const std::string &payload);
+			private:
+				bool data_;
+				std::string errMessage_;
+				bool success_;
+				int errCode_;
+
+			};
+		}
+	}
+}
+#endif // !ALIBABACLOUD_METERING_MODEL_POSTDATARESULT_H_

+ 36 - 0
metering/src/MeteringClient.cc

@@ -51,6 +51,42 @@ MeteringClient::MeteringClient(const std::string & accessKeyId, const std::strin
 MeteringClient::~MeteringClient()
 {}
 
+MeteringClient::PostDataOutcome MeteringClient::postData(const PostDataRequest &request) const
+{
+	auto endpointOutcome = endpointProvider_->getEndpoint();
+	if (!endpointOutcome.isSuccess())
+		return PostDataOutcome(endpointOutcome.error());
+
+	auto outcome = makeRequest(endpointOutcome.result(), request);
+
+	if (outcome.isSuccess())
+		return PostDataOutcome(PostDataResult(outcome.result()));
+	else
+		return PostDataOutcome(outcome.error());
+}
+
+void MeteringClient::postDataAsync(const PostDataRequest& request, const PostDataAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
+{
+	auto fn = [this, request, handler, context]()
+	{
+		handler(this, request, postData(request), context);
+	};
+
+	asyncExecute(new Runnable(fn));
+}
+
+MeteringClient::PostDataOutcomeCallable MeteringClient::postDataCallable(const PostDataRequest &request) const
+{
+	auto task = std::make_shared<std::packaged_task<PostDataOutcome()>>(
+			[this, request]()
+			{
+			return this->postData(request);
+			});
+
+	asyncExecute(new Runnable([task]() { (*task)(); }));
+	return task->get_future();
+}
+
 MeteringClient::SyncDataOutcome MeteringClient::syncData(const SyncDataRequest &request) const
 {
 	auto endpointOutcome = endpointProvider_->getEndpoint();

+ 118 - 0
metering/src/model/PostDataRequest.cc

@@ -0,0 +1,118 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <alibabacloud/metering/model/PostDataRequest.h>
+
+using AlibabaCloud::Metering::Model::PostDataRequest;
+
+PostDataRequest::PostDataRequest() :
+	RoaServiceRequest("metering", "2020-09-21")
+{
+	setResourcePath("/api/dataPost");
+	setMethod(HttpRequest::Method::Post);
+}
+
+PostDataRequest::~PostDataRequest()
+{}
+
+std::string PostDataRequest::getInstanceId()const
+{
+	return instanceId_;
+}
+
+void PostDataRequest::setInstanceId(const std::string& instanceId)
+{
+	instanceId_ = instanceId;
+	setBodyParameter("InstanceId", instanceId);
+}
+
+std::string PostDataRequest::getData()const
+{
+	return data_;
+}
+
+void PostDataRequest::setData(const std::string& data)
+{
+	data_ = data;
+	setBodyParameter("Data", data);
+}
+
+std::string PostDataRequest::getDataType()const
+{
+	return dataType_;
+}
+
+void PostDataRequest::setDataType(const std::string& dataType)
+{
+	dataType_ = dataType;
+	setBodyParameter("DataType", dataType);
+}
+
+std::string PostDataRequest::getEndTime()const
+{
+	return endTime_;
+}
+
+void PostDataRequest::setEndTime(const std::string& endTime)
+{
+	endTime_ = endTime;
+	setBodyParameter("EndTime", endTime);
+}
+
+std::string PostDataRequest::getStartTime()const
+{
+	return startTime_;
+}
+
+void PostDataRequest::setStartTime(const std::string& startTime)
+{
+	startTime_ = startTime;
+	setBodyParameter("StartTime", startTime);
+}
+
+std::string PostDataRequest::getCommodityCode()const
+{
+	return commodityCode_;
+}
+
+void PostDataRequest::setCommodityCode(const std::string& commodityCode)
+{
+	commodityCode_ = commodityCode;
+	setBodyParameter("CommodityCode", commodityCode);
+}
+
+std::string PostDataRequest::getRegion()const
+{
+	return region_;
+}
+
+void PostDataRequest::setRegion(const std::string& region)
+{
+	region_ = region;
+	setBodyParameter("Region", region);
+}
+
+std::string PostDataRequest::getUserId()const
+{
+	return userId_;
+}
+
+void PostDataRequest::setUserId(const std::string& userId)
+{
+	userId_ = userId;
+	setBodyParameter("UserId", userId);
+}
+

+ 72 - 0
metering/src/model/PostDataResult.cc

@@ -0,0 +1,72 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <alibabacloud/metering/model/PostDataResult.h>
+#include <json/json.h>
+
+using namespace AlibabaCloud::Metering;
+using namespace AlibabaCloud::Metering::Model;
+
+PostDataResult::PostDataResult() :
+	ServiceResult()
+{}
+
+PostDataResult::PostDataResult(const std::string &payload) :
+	ServiceResult()
+{
+	parse(payload);
+}
+
+PostDataResult::~PostDataResult()
+{}
+
+void PostDataResult::parse(const std::string &payload)
+{
+	Json::Reader reader;
+	Json::Value value;
+	reader.parse(payload, value);
+	setRequestId(value["RequestId"].asString());
+	if(!value["Success"].isNull())
+		success_ = value["Success"].asString() == "true";
+	if(!value["Data"].isNull())
+		data_ = value["Data"].asString() == "true";
+	if(!value["ErrCode"].isNull())
+		errCode_ = std::stoi(value["ErrCode"].asString());
+	if(!value["ErrMessage"].isNull())
+		errMessage_ = value["ErrMessage"].asString();
+
+}
+
+bool PostDataResult::getData()const
+{
+	return data_;
+}
+
+std::string PostDataResult::getErrMessage()const
+{
+	return errMessage_;
+}
+
+bool PostDataResult::getSuccess()const
+{
+	return success_;
+}
+
+int PostDataResult::getErrCode()const
+{
+	return errCode_;
+}
+