Init.
This commit is contained in:
89
metering/src/MeteringClient.cc
Normal file
89
metering/src/MeteringClient.cc
Normal file
@@ -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
metering/src/model/SyncDataRequest.cc
Normal file
118
metering/src/model/SyncDataRequest.cc
Normal file
@@ -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
metering/src/model/SyncDataResult.cc
Normal file
79
metering/src/model/SyncDataResult.cc
Normal file
@@ -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_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user