Api init.
This commit is contained in:
89
btripopen/src/BtripOpenClient.cc
Normal file
89
btripopen/src/BtripOpenClient.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/btripopen/BtripOpenClient.h>
|
||||
#include <alibabacloud/core/SimpleCredentialsProvider.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Location;
|
||||
using namespace AlibabaCloud::BtripOpen;
|
||||
using namespace AlibabaCloud::BtripOpen::Model;
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::string SERVICE_NAME = "btripOpen";
|
||||
}
|
||||
|
||||
BtripOpenClient::BtripOpenClient(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, "");
|
||||
}
|
||||
|
||||
BtripOpenClient::BtripOpenClient(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, "");
|
||||
}
|
||||
|
||||
BtripOpenClient::BtripOpenClient(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, "");
|
||||
}
|
||||
|
||||
BtripOpenClient::~BtripOpenClient()
|
||||
{}
|
||||
|
||||
BtripOpenClient::TakeAccessTokenOutcome BtripOpenClient::takeAccessToken(const TakeAccessTokenRequest &request) const
|
||||
{
|
||||
auto endpointOutcome = endpointProvider_->getEndpoint();
|
||||
if (!endpointOutcome.isSuccess())
|
||||
return TakeAccessTokenOutcome(endpointOutcome.error());
|
||||
|
||||
auto outcome = makeRequest(endpointOutcome.result(), request);
|
||||
|
||||
if (outcome.isSuccess())
|
||||
return TakeAccessTokenOutcome(TakeAccessTokenResult(outcome.result()));
|
||||
else
|
||||
return TakeAccessTokenOutcome(outcome.error());
|
||||
}
|
||||
|
||||
void BtripOpenClient::takeAccessTokenAsync(const TakeAccessTokenRequest& request, const TakeAccessTokenAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
|
||||
{
|
||||
auto fn = [this, request, handler, context]()
|
||||
{
|
||||
handler(this, request, takeAccessToken(request), context);
|
||||
};
|
||||
|
||||
asyncExecute(new Runnable(fn));
|
||||
}
|
||||
|
||||
BtripOpenClient::TakeAccessTokenOutcomeCallable BtripOpenClient::takeAccessTokenCallable(const TakeAccessTokenRequest &request) const
|
||||
{
|
||||
auto task = std::make_shared<std::packaged_task<TakeAccessTokenOutcome()>>(
|
||||
[this, request]()
|
||||
{
|
||||
return this->takeAccessToken(request);
|
||||
});
|
||||
|
||||
asyncExecute(new Runnable([task]() { (*task)(); }));
|
||||
return task->get_future();
|
||||
}
|
||||
|
||||
46
btripopen/src/model/TakeAccessTokenRequest.cc
Normal file
46
btripopen/src/model/TakeAccessTokenRequest.cc
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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/btripopen/model/TakeAccessTokenRequest.h>
|
||||
|
||||
using AlibabaCloud::BtripOpen::Model::TakeAccessTokenRequest;
|
||||
|
||||
TakeAccessTokenRequest::TakeAccessTokenRequest()
|
||||
: RoaServiceRequest("btripopen", "2022-05-17") {
|
||||
setResourcePath("/btrip/open/access-token/take"};
|
||||
setMethod(HttpRequest::Method::Get);
|
||||
}
|
||||
|
||||
TakeAccessTokenRequest::~TakeAccessTokenRequest() {}
|
||||
|
||||
std::string TakeAccessTokenRequest::getApp_key() const {
|
||||
return app_key_;
|
||||
}
|
||||
|
||||
void TakeAccessTokenRequest::setApp_key(const std::string &app_key) {
|
||||
app_key_ = app_key;
|
||||
setParameter(std::string("app_key"), app_key);
|
||||
}
|
||||
|
||||
std::string TakeAccessTokenRequest::getApp_secret() const {
|
||||
return app_secret_;
|
||||
}
|
||||
|
||||
void TakeAccessTokenRequest::setApp_secret(const std::string &app_secret) {
|
||||
app_secret_ = app_secret;
|
||||
setParameter(std::string("app_secret"), app_secret);
|
||||
}
|
||||
|
||||
82
btripopen/src/model/TakeAccessTokenResult.cc
Normal file
82
btripopen/src/model/TakeAccessTokenResult.cc
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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/btripopen/model/TakeAccessTokenResult.h>
|
||||
#include <json/json.h>
|
||||
|
||||
using namespace AlibabaCloud::BtripOpen;
|
||||
using namespace AlibabaCloud::BtripOpen::Model;
|
||||
|
||||
TakeAccessTokenResult::TakeAccessTokenResult() :
|
||||
ServiceResult()
|
||||
{}
|
||||
|
||||
TakeAccessTokenResult::TakeAccessTokenResult(const std::string &payload) :
|
||||
ServiceResult()
|
||||
{
|
||||
parse(payload);
|
||||
}
|
||||
|
||||
TakeAccessTokenResult::~TakeAccessTokenResult()
|
||||
{}
|
||||
|
||||
void TakeAccessTokenResult::parse(const std::string &payload)
|
||||
{
|
||||
Json::Reader reader;
|
||||
Json::Value value;
|
||||
reader.parse(payload, value);
|
||||
setRequestId(value["RequestId"].asString());
|
||||
auto dataNode = value["data"];
|
||||
if(!dataNode["access_token"].isNull())
|
||||
data_.access_token = dataNode["access_token"].asString();
|
||||
if(!dataNode["expire"].isNull())
|
||||
data_.expire = std::stol(dataNode["expire"].asString());
|
||||
if(!value["requestId"].isNull())
|
||||
requestId_ = value["requestId"].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();
|
||||
|
||||
}
|
||||
|
||||
std::string TakeAccessTokenResult::getRequestId()const
|
||||
{
|
||||
return requestId_;
|
||||
}
|
||||
|
||||
std::string TakeAccessTokenResult::getMessage()const
|
||||
{
|
||||
return message_;
|
||||
}
|
||||
|
||||
TakeAccessTokenResult::Data TakeAccessTokenResult::getData()const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
|
||||
std::string TakeAccessTokenResult::getCode()const
|
||||
{
|
||||
return code_;
|
||||
}
|
||||
|
||||
std::string TakeAccessTokenResult::getSuccess()const
|
||||
{
|
||||
return success_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user