sdk-team vor 6 Jahren
Ursprung
Commit
37fea59cb0

+ 3 - 0
CHANGELOG

@@ -1,3 +1,6 @@
+2020-10-12 Version: patch
+- Init.
+
 2020-10-12 Version: patch
 - ChatApp third version.
 - Add contack check api.

+ 86 - 0
metering/CMakeLists.txt

@@ -0,0 +1,86 @@
+#
+# 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.
+#
+
+set(public_header_dir ${CMAKE_CURRENT_SOURCE_DIR}/../include)
+
+set(metering_public_header 
+	include/alibabacloud/metering/MeteringClient.h
+	include/alibabacloud/metering/MeteringExport.h )
+
+set(metering_public_header_model 
+	include/alibabacloud/metering/model/SyncDataRequest.h
+	include/alibabacloud/metering/model/SyncDataResult.h )
+
+set(metering_src 
+	src/MeteringClient.cc
+	src/model/SyncDataRequest.cc
+	src/model/SyncDataResult.cc )
+
+add_library(metering ${LIB_TYPE}
+	${metering_public_header}
+	${metering_public_header_model}
+	${metering_src})
+
+set_target_properties(metering
+	PROPERTIES
+	LINKER_LANGUAGE CXX
+	ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
+	LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
+	RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
+	OUTPUT_NAME ${TARGET_OUTPUT_NAME_PREFIX}metering
+	)
+
+if(${LIB_TYPE} STREQUAL "SHARED")
+	set_target_properties(metering
+		PROPERTIES
+		DEFINE_SYMBOL ALIBABACLOUD_METERING_LIBRARY)
+endif()
+
+target_include_directories(metering
+	PRIVATE include
+		${CMAKE_SOURCE_DIR}/core/include
+	)
+target_link_libraries(metering
+	core)
+
+if(CMAKE_HOST_WIN32)
+	ExternalProject_Get_Property(jsoncpp INSTALL_DIR)
+	set(jsoncpp_install_dir ${INSTALL_DIR})
+	add_dependencies(metering
+		jsoncpp)
+	target_include_directories(metering
+		PRIVATE	${jsoncpp_install_dir}/include)
+	target_link_libraries(metering
+		${jsoncpp_install_dir}/lib/jsoncpp.lib)
+	set_target_properties(metering
+    	PROPERTIES
+    		COMPILE_OPTIONS "/bigobj")
+else()
+	target_include_directories(metering
+		PRIVATE /usr/include/jsoncpp)
+	target_link_libraries(metering
+		jsoncpp)
+endif()
+
+install(FILES ${metering_public_header}
+	DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/alibabacloud/metering)
+install(FILES ${metering_public_header_model}
+	DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/alibabacloud/metering/model)
+install(TARGETS metering
+	ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+	LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+	)

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

@@ -0,0 +1,54 @@
+/*
+ * 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_METERINGCLIENT_H_
+#define ALIBABACLOUD_METERING_METERINGCLIENT_H_
+
+#include <future>
+#include <alibabacloud/core/AsyncCallerContext.h>
+#include <alibabacloud/core/EndpointProvider.h>
+#include <alibabacloud/core/RoaServiceClient.h>
+#include "MeteringExport.h"
+#include "model/SyncDataRequest.h"
+#include "model/SyncDataResult.h"
+
+
+namespace AlibabaCloud
+{
+	namespace Metering
+	{
+		class ALIBABACLOUD_METERING_EXPORT MeteringClient : public RoaServiceClient
+		{
+		public:
+			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;
+
+			MeteringClient(const Credentials &credentials, const ClientConfiguration &configuration);
+			MeteringClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
+			MeteringClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
+			~MeteringClient();
+			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;
+	
+		private:
+			std::shared_ptr<EndpointProvider> endpointProvider_;
+		};
+	}
+}
+
+#endif // !ALIBABACLOUD_METERING_METERINGCLIENT_H_

+ 32 - 0
metering/include/alibabacloud/metering/MeteringExport.h

@@ -0,0 +1,32 @@
+/*
+ * 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_METERINGEXPORT_H_
+#define ALIBABACLOUD_METERING_METERINGEXPORT_H_
+
+#include <alibabacloud/core/Global.h>
+
+#if defined(ALIBABACLOUD_SHARED)
+#	if defined(ALIBABACLOUD_METERING_LIBRARY)
+#		define ALIBABACLOUD_METERING_EXPORT ALIBABACLOUD_DECL_EXPORT
+#	else
+#		define ALIBABACLOUD_METERING_EXPORT ALIBABACLOUD_DECL_IMPORT
+#	endif
+#else
+#	define ALIBABACLOUD_METERING_EXPORT
+#endif
+
+#endif // !ALIBABACLOUD_METERING_METERINGEXPORT_H_

+ 69 - 0
metering/include/alibabacloud/metering/model/SyncDataRequest.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_SYNCDATAREQUEST_H_
+#define ALIBABACLOUD_METERING_MODEL_SYNCDATAREQUEST_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 SyncDataRequest : public RoaServiceRequest
+			{
+
+			public:
+				SyncDataRequest();
+				~SyncDataRequest();
+
+				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_SYNCDATAREQUEST_H_

+ 59 - 0
metering/include/alibabacloud/metering/model/SyncDataResult.h

@@ -0,0 +1,59 @@
+/*
+ * 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_SYNCDATARESULT_H_
+#define ALIBABACLOUD_METERING_MODEL_SYNCDATARESULT_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 SyncDataResult : public ServiceResult
+			{
+			public:
+
+
+				SyncDataResult();
+				explicit SyncDataResult(const std::string &payload);
+				~SyncDataResult();
+				bool getData()const;
+				std::string getErrMessage()const;
+				int getCode()const;
+				bool getSuccess()const;
+				int getErrCode()const;
+
+			protected:
+				void parse(const std::string &payload);
+			private:
+				bool data_;
+				std::string errMessage_;
+				int code_;
+				bool success_;
+				int errCode_;
+
+			};
+		}
+	}
+}
+#endif // !ALIBABACLOUD_METERING_MODEL_SYNCDATARESULT_H_

+ 89 - 0
metering/src/MeteringClient.cc

@@ -0,0 +1,89 @@
+/*
+ * 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/MeteringClient.h>
+#include <alibabacloud/core/SimpleCredentialsProvider.h>
+
+using namespace AlibabaCloud;
+using namespace AlibabaCloud::Location;
+using namespace AlibabaCloud::Metering;
+using namespace AlibabaCloud::Metering::Model;
+
+namespace
+{
+	const std::string SERVICE_NAME = "Metering";
+}
+
+MeteringClient::MeteringClient(const Credentials &credentials, const ClientConfiguration &configuration) :
+	RoaServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
+{
+	auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
+	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "pai");
+}
+
+MeteringClient::MeteringClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
+	RoaServiceClient(SERVICE_NAME, credentialsProvider, configuration)
+{
+	auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
+	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "pai");
+}
+
+MeteringClient::MeteringClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
+	RoaServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
+{
+	auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
+	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "pai");
+}
+
+MeteringClient::~MeteringClient()
+{}
+
+MeteringClient::SyncDataOutcome MeteringClient::syncData(const SyncDataRequest &request) const
+{
+	auto endpointOutcome = endpointProvider_->getEndpoint();
+	if (!endpointOutcome.isSuccess())
+		return SyncDataOutcome(endpointOutcome.error());
+
+	auto outcome = makeRequest(endpointOutcome.result(), request);
+
+	if (outcome.isSuccess())
+		return SyncDataOutcome(SyncDataResult(outcome.result()));
+	else
+		return SyncDataOutcome(outcome.error());
+}
+
+void MeteringClient::syncDataAsync(const SyncDataRequest& request, const SyncDataAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
+{
+	auto fn = [this, request, handler, context]()
+	{
+		handler(this, request, syncData(request), context);
+	};
+
+	asyncExecute(new Runnable(fn));
+}
+
+MeteringClient::SyncDataOutcomeCallable MeteringClient::syncDataCallable(const SyncDataRequest &request) const
+{
+	auto task = std::make_shared<std::packaged_task<SyncDataOutcome()>>(
+			[this, request]()
+			{
+			return this->syncData(request);
+			});
+
+	asyncExecute(new Runnable([task]() { (*task)(); }));
+	return task->get_future();
+}
+

+ 118 - 0
metering/src/model/SyncDataRequest.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/SyncDataRequest.h>
+
+using AlibabaCloud::Metering::Model::SyncDataRequest;
+
+SyncDataRequest::SyncDataRequest() :
+	RoaServiceRequest("metering", "2020-09-21")
+{
+	setResourcePath("/api/dataSync");
+	setMethod(HttpRequest::Method::Post);
+}
+
+SyncDataRequest::~SyncDataRequest()
+{}
+
+std::string SyncDataRequest::getInstanceId()const
+{
+	return instanceId_;
+}
+
+void SyncDataRequest::setInstanceId(const std::string& instanceId)
+{
+	instanceId_ = instanceId;
+	setParameter("InstanceId", instanceId);
+}
+
+std::string SyncDataRequest::getData()const
+{
+	return data_;
+}
+
+void SyncDataRequest::setData(const std::string& data)
+{
+	data_ = data;
+	setParameter("Data", data);
+}
+
+std::string SyncDataRequest::getDataType()const
+{
+	return dataType_;
+}
+
+void SyncDataRequest::setDataType(const std::string& dataType)
+{
+	dataType_ = dataType;
+	setParameter("DataType", dataType);
+}
+
+std::string SyncDataRequest::getEndTime()const
+{
+	return endTime_;
+}
+
+void SyncDataRequest::setEndTime(const std::string& endTime)
+{
+	endTime_ = endTime;
+	setParameter("EndTime", endTime);
+}
+
+std::string SyncDataRequest::getStartTime()const
+{
+	return startTime_;
+}
+
+void SyncDataRequest::setStartTime(const std::string& startTime)
+{
+	startTime_ = startTime;
+	setParameter("StartTime", startTime);
+}
+
+std::string SyncDataRequest::getCommodityCode()const
+{
+	return commodityCode_;
+}
+
+void SyncDataRequest::setCommodityCode(const std::string& commodityCode)
+{
+	commodityCode_ = commodityCode;
+	setParameter("CommodityCode", commodityCode);
+}
+
+std::string SyncDataRequest::getRegion()const
+{
+	return region_;
+}
+
+void SyncDataRequest::setRegion(const std::string& region)
+{
+	region_ = region;
+	setParameter("Region", region);
+}
+
+std::string SyncDataRequest::getUserId()const
+{
+	return userId_;
+}
+
+void SyncDataRequest::setUserId(const std::string& userId)
+{
+	userId_ = userId;
+	setParameter("UserId", userId);
+}
+

+ 79 - 0
metering/src/model/SyncDataResult.cc

@@ -0,0 +1,79 @@
+/*
+ * 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/SyncDataResult.h>
+#include <json/json.h>
+
+using namespace AlibabaCloud::Metering;
+using namespace AlibabaCloud::Metering::Model;
+
+SyncDataResult::SyncDataResult() :
+	ServiceResult()
+{}
+
+SyncDataResult::SyncDataResult(const std::string &payload) :
+	ServiceResult()
+{
+	parse(payload);
+}
+
+SyncDataResult::~SyncDataResult()
+{}
+
+void SyncDataResult::parse(const std::string &payload)
+{
+	Json::Reader reader;
+	Json::Value value;
+	reader.parse(payload, value);
+	setRequestId(value["RequestId"].asString());
+	if(!value["Code"].isNull())
+		code_ = std::stoi(value["Code"].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 SyncDataResult::getData()const
+{
+	return data_;
+}
+
+std::string SyncDataResult::getErrMessage()const
+{
+	return errMessage_;
+}
+
+int SyncDataResult::getCode()const
+{
+	return code_;
+}
+
+bool SyncDataResult::getSuccess()const
+{
+	return success_;
+}
+
+int SyncDataResult::getErrCode()const
+{
+	return errCode_;
+}
+