Supported RequestDecision For YN.

This commit is contained in:
sdk-team
2021-12-01 05:43:33 +00:00
parent 37dde26ac1
commit e2a8813a1b
14 changed files with 313 additions and 12 deletions

View File

@@ -31,21 +31,21 @@ SafClient::SafClient(const Credentials &credentials, const ClientConfiguration &
RpcServiceClient(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, "saf");
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
}
SafClient::SafClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
{
auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "saf");
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
}
SafClient::SafClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
RpcServiceClient(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, "saf");
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
}
SafClient::~SafClient()
@@ -195,3 +195,39 @@ SafClient::ExecuteRequestSGOutcomeCallable SafClient::executeRequestSGCallable(c
return task->get_future();
}
SafClient::RequestDecisionOutcome SafClient::requestDecision(const RequestDecisionRequest &request) const
{
auto endpointOutcome = endpointProvider_->getEndpoint();
if (!endpointOutcome.isSuccess())
return RequestDecisionOutcome(endpointOutcome.error());
auto outcome = makeRequest(endpointOutcome.result(), request);
if (outcome.isSuccess())
return RequestDecisionOutcome(RequestDecisionResult(outcome.result()));
else
return RequestDecisionOutcome(outcome.error());
}
void SafClient::requestDecisionAsync(const RequestDecisionRequest& request, const RequestDecisionAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
{
auto fn = [this, request, handler, context]()
{
handler(this, request, requestDecision(request), context);
};
asyncExecute(new Runnable(fn));
}
SafClient::RequestDecisionOutcomeCallable SafClient::requestDecisionCallable(const RequestDecisionRequest &request) const
{
auto task = std::make_shared<std::packaged_task<RequestDecisionOutcome()>>(
[this, request]()
{
return this->requestDecision(request);
});
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
}

View File

@@ -42,14 +42,14 @@ void ExecuteExtendServiceResult::parse(const std::string &payload)
auto dataNode = value["Data"];
if(!dataNode["InvokeResult"].isNull())
data_.invokeResult = dataNode["InvokeResult"].asString();
if(!value["Code"].isNull())
code_ = value["Code"].asString();
if(!value["Success"].isNull())
success_ = value["Success"].asString() == "true";
if(!value["Message"].isNull())
message_ = value["Message"].asString();
if(!value["HttpStatusCode"].isNull())
httpStatusCode_ = value["HttpStatusCode"].asString();
if(!value["Code"].isNull())
code_ = value["Code"].asString();
if(!value["Message"].isNull())
message_ = value["Message"].asString();
if(!value["Success"].isNull())
success_ = value["Success"].asString() == "true";
}

View File

@@ -49,3 +49,14 @@ void ExecuteRequestMLRequest::setService(const std::string& service)
setParameter("Service", service);
}
std::string ExecuteRequestMLRequest::getLang()const
{
return lang_;
}
void ExecuteRequestMLRequest::setLang(const std::string& lang)
{
lang_ = lang;
setParameter("Lang", lang);
}

View File

@@ -49,3 +49,14 @@ void ExecuteRequestSGRequest::setService(const std::string& service)
setParameter("Service", service);
}
std::string ExecuteRequestSGRequest::getLang()const
{
return lang_;
}
void ExecuteRequestSGRequest::setLang(const std::string& lang)
{
lang_ = lang;
setParameter("Lang", lang);
}

View File

@@ -0,0 +1,51 @@
/*
* 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/saf/model/RequestDecisionRequest.h>
using AlibabaCloud::Saf::Model::RequestDecisionRequest;
RequestDecisionRequest::RequestDecisionRequest() :
RpcServiceRequest("saf", "2019-05-21", "RequestDecision")
{
setMethod(HttpRequest::Method::Post);
}
RequestDecisionRequest::~RequestDecisionRequest()
{}
std::string RequestDecisionRequest::getServiceParameters()const
{
return serviceParameters_;
}
void RequestDecisionRequest::setServiceParameters(const std::string& serviceParameters)
{
serviceParameters_ = serviceParameters;
setParameter("ServiceParameters", serviceParameters);
}
std::string RequestDecisionRequest::getEventCode()const
{
return eventCode_;
}
void RequestDecisionRequest::setEventCode(const std::string& eventCode)
{
eventCode_ = eventCode;
setParameter("EventCode", eventCode);
}

View File

@@ -0,0 +1,65 @@
/*
* 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/saf/model/RequestDecisionResult.h>
#include <json/json.h>
using namespace AlibabaCloud::Saf;
using namespace AlibabaCloud::Saf::Model;
RequestDecisionResult::RequestDecisionResult() :
ServiceResult()
{}
RequestDecisionResult::RequestDecisionResult(const std::string &payload) :
ServiceResult()
{
parse(payload);
}
RequestDecisionResult::~RequestDecisionResult()
{}
void RequestDecisionResult::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::stol(value["Code"].asString());
if(!value["Message"].isNull())
message_ = value["Message"].asString();
if(!value["Data"].isNull())
data_ = value["Data"].asString();
}
std::string RequestDecisionResult::getMessage()const
{
return message_;
}
std::string RequestDecisionResult::getData()const
{
return data_;
}
long RequestDecisionResult::getCode()const
{
return code_;
}