From 14ebba9911f4925782cb5538cf5cf592f02a6a73 Mon Sep 17 00:00:00 2001 From: sdk-team Date: Fri, 16 Oct 2020 14:25:12 +0000 Subject: [PATCH] Metering. --- CHANGELOG | 3 + metering/CMakeLists.txt | 4 + .../alibabacloud/metering/MeteringClient.h | 8 ++ .../metering/model/PostDataRequest.h | 69 ++++++++++ .../metering/model/PostDataResult.h | 57 +++++++++ metering/src/MeteringClient.cc | 36 ++++++ metering/src/model/PostDataRequest.cc | 118 ++++++++++++++++++ metering/src/model/PostDataResult.cc | 72 +++++++++++ 8 files changed, 367 insertions(+) create mode 100644 metering/include/alibabacloud/metering/model/PostDataRequest.h create mode 100644 metering/include/alibabacloud/metering/model/PostDataResult.h create mode 100644 metering/src/model/PostDataRequest.cc create mode 100644 metering/src/model/PostDataResult.cc diff --git a/CHANGELOG b/CHANGELOG index 6c37b9bd0..2e6aeef4b 100644 --- a/CHANGELOG +++ b/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. diff --git a/metering/CMakeLists.txt b/metering/CMakeLists.txt index 1919718bf..6676ab82c 100644 --- a/metering/CMakeLists.txt +++ b/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 ) diff --git a/metering/include/alibabacloud/metering/MeteringClient.h b/metering/include/alibabacloud/metering/MeteringClient.h index c2921704a..4441dc064 100644 --- a/metering/include/alibabacloud/metering/MeteringClient.h +++ b/metering/include/alibabacloud/metering/MeteringClient.h @@ -22,6 +22,8 @@ #include #include #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 PostDataOutcome; + typedef std::future PostDataOutcomeCallable; + typedef std::function&)> PostDataAsyncHandler; typedef Outcome SyncDataOutcome; typedef std::future SyncDataOutcomeCallable; typedef std::function&)> SyncDataAsyncHandler; @@ -41,6 +46,9 @@ namespace AlibabaCloud MeteringClient(const std::shared_ptr &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& 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& context = nullptr) const; SyncDataOutcomeCallable syncDataCallable(const Model::SyncDataRequest& request) const; diff --git a/metering/include/alibabacloud/metering/model/PostDataRequest.h b/metering/include/alibabacloud/metering/model/PostDataRequest.h new file mode 100644 index 000000000..2cca51e97 --- /dev/null +++ b/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 +#include +#include +#include + +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_ \ No newline at end of file diff --git a/metering/include/alibabacloud/metering/model/PostDataResult.h b/metering/include/alibabacloud/metering/model/PostDataResult.h new file mode 100644 index 000000000..bc2f2dd96 --- /dev/null +++ b/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 +#include +#include +#include +#include + +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_ \ No newline at end of file diff --git a/metering/src/MeteringClient.cc b/metering/src/MeteringClient.cc index 0d08cce88..7a027b26c 100644 --- a/metering/src/MeteringClient.cc +++ b/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& 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>( + [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(); diff --git a/metering/src/model/PostDataRequest.cc b/metering/src/model/PostDataRequest.cc new file mode 100644 index 000000000..92997a517 --- /dev/null +++ b/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 + +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); +} + diff --git a/metering/src/model/PostDataResult.cc b/metering/src/model/PostDataResult.cc new file mode 100644 index 000000000..0e0774302 --- /dev/null +++ b/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 +#include + +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_; +} +