From 20774ebe3a1a8570a35b215df7650063de7f8c92 Mon Sep 17 00:00:00 2001 From: sdk-team Date: Fri, 10 Apr 2020 11:53:07 +0800 Subject: [PATCH] Support DescribeIpv4Location. --- CHANGELOG | 3 + VERSION | 2 +- geoip/CMakeLists.txt | 4 + .../include/alibabacloud/geoip/GeoipClient.h | 8 ++ .../geoip/model/DescribeIpv4LocationRequest.h | 54 ++++++++++++ .../geoip/model/DescribeIpv4LocationResult.h | 61 +++++++++++++ geoip/src/GeoipClient.cc | 36 ++++++++ .../src/model/DescribeIpv4LocationRequest.cc | 62 +++++++++++++ geoip/src/model/DescribeIpv4LocationResult.cc | 86 +++++++++++++++++++ 9 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 geoip/include/alibabacloud/geoip/model/DescribeIpv4LocationRequest.h create mode 100644 geoip/include/alibabacloud/geoip/model/DescribeIpv4LocationResult.h create mode 100644 geoip/src/model/DescribeIpv4LocationRequest.cc create mode 100644 geoip/src/model/DescribeIpv4LocationResult.cc diff --git a/CHANGELOG b/CHANGELOG index 65a3085d2..e4ebba429 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +2020-04-10 Version: 1.36.349 +- Support DescribeIpv4Location. + 2020-04-09 Version: 1.36.348 - Add prometheus api AddGrafana and AddIntegration. diff --git a/VERSION b/VERSION index cf2818ac3..4b53ed0f5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.36.348 \ No newline at end of file +1.36.349 \ No newline at end of file diff --git a/geoip/CMakeLists.txt b/geoip/CMakeLists.txt index 04b6aa409..d98affbc5 100644 --- a/geoip/CMakeLists.txt +++ b/geoip/CMakeLists.txt @@ -27,6 +27,8 @@ set(geoip_public_header_model include/alibabacloud/geoip/model/DescribeGeoipInstanceStatisticsResult.h include/alibabacloud/geoip/model/DescribeGeoipInstancesRequest.h include/alibabacloud/geoip/model/DescribeGeoipInstancesResult.h + include/alibabacloud/geoip/model/DescribeIpv4LocationRequest.h + include/alibabacloud/geoip/model/DescribeIpv4LocationResult.h include/alibabacloud/geoip/model/DescribeIpv6LocationRequest.h include/alibabacloud/geoip/model/DescribeIpv6LocationResult.h ) @@ -38,6 +40,8 @@ set(geoip_src src/model/DescribeGeoipInstanceStatisticsResult.cc src/model/DescribeGeoipInstancesRequest.cc src/model/DescribeGeoipInstancesResult.cc + src/model/DescribeIpv4LocationRequest.cc + src/model/DescribeIpv4LocationResult.cc src/model/DescribeIpv6LocationRequest.cc src/model/DescribeIpv6LocationResult.cc ) diff --git a/geoip/include/alibabacloud/geoip/GeoipClient.h b/geoip/include/alibabacloud/geoip/GeoipClient.h index 68116b954..b966647d2 100644 --- a/geoip/include/alibabacloud/geoip/GeoipClient.h +++ b/geoip/include/alibabacloud/geoip/GeoipClient.h @@ -28,6 +28,8 @@ #include "model/DescribeGeoipInstanceStatisticsResult.h" #include "model/DescribeGeoipInstancesRequest.h" #include "model/DescribeGeoipInstancesResult.h" +#include "model/DescribeIpv4LocationRequest.h" +#include "model/DescribeIpv4LocationResult.h" #include "model/DescribeIpv6LocationRequest.h" #include "model/DescribeIpv6LocationResult.h" @@ -48,6 +50,9 @@ namespace AlibabaCloud typedef Outcome DescribeGeoipInstancesOutcome; typedef std::future DescribeGeoipInstancesOutcomeCallable; typedef std::function&)> DescribeGeoipInstancesAsyncHandler; + typedef Outcome DescribeIpv4LocationOutcome; + typedef std::future DescribeIpv4LocationOutcomeCallable; + typedef std::function&)> DescribeIpv4LocationAsyncHandler; typedef Outcome DescribeIpv6LocationOutcome; typedef std::future DescribeIpv6LocationOutcomeCallable; typedef std::function&)> DescribeIpv6LocationAsyncHandler; @@ -65,6 +70,9 @@ namespace AlibabaCloud DescribeGeoipInstancesOutcome describeGeoipInstances(const Model::DescribeGeoipInstancesRequest &request)const; void describeGeoipInstancesAsync(const Model::DescribeGeoipInstancesRequest& request, const DescribeGeoipInstancesAsyncHandler& handler, const std::shared_ptr& context = nullptr) const; DescribeGeoipInstancesOutcomeCallable describeGeoipInstancesCallable(const Model::DescribeGeoipInstancesRequest& request) const; + DescribeIpv4LocationOutcome describeIpv4Location(const Model::DescribeIpv4LocationRequest &request)const; + void describeIpv4LocationAsync(const Model::DescribeIpv4LocationRequest& request, const DescribeIpv4LocationAsyncHandler& handler, const std::shared_ptr& context = nullptr) const; + DescribeIpv4LocationOutcomeCallable describeIpv4LocationCallable(const Model::DescribeIpv4LocationRequest& request) const; DescribeIpv6LocationOutcome describeIpv6Location(const Model::DescribeIpv6LocationRequest &request)const; void describeIpv6LocationAsync(const Model::DescribeIpv6LocationRequest& request, const DescribeIpv6LocationAsyncHandler& handler, const std::shared_ptr& context = nullptr) const; DescribeIpv6LocationOutcomeCallable describeIpv6LocationCallable(const Model::DescribeIpv6LocationRequest& request) const; diff --git a/geoip/include/alibabacloud/geoip/model/DescribeIpv4LocationRequest.h b/geoip/include/alibabacloud/geoip/model/DescribeIpv4LocationRequest.h new file mode 100644 index 000000000..187b6f6bc --- /dev/null +++ b/geoip/include/alibabacloud/geoip/model/DescribeIpv4LocationRequest.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_GEOIP_MODEL_DESCRIBEIPV4LOCATIONREQUEST_H_ +#define ALIBABACLOUD_GEOIP_MODEL_DESCRIBEIPV4LOCATIONREQUEST_H_ + +#include +#include +#include +#include + +namespace AlibabaCloud +{ + namespace Geoip + { + namespace Model + { + class ALIBABACLOUD_GEOIP_EXPORT DescribeIpv4LocationRequest : public RpcServiceRequest + { + + public: + DescribeIpv4LocationRequest(); + ~DescribeIpv4LocationRequest(); + + std::string getIp()const; + void setIp(const std::string& ip); + std::string getUserClientIp()const; + void setUserClientIp(const std::string& userClientIp); + std::string getLang()const; + void setLang(const std::string& lang); + + private: + std::string ip_; + std::string userClientIp_; + std::string lang_; + + }; + } + } +} +#endif // !ALIBABACLOUD_GEOIP_MODEL_DESCRIBEIPV4LOCATIONREQUEST_H_ \ No newline at end of file diff --git a/geoip/include/alibabacloud/geoip/model/DescribeIpv4LocationResult.h b/geoip/include/alibabacloud/geoip/model/DescribeIpv4LocationResult.h new file mode 100644 index 000000000..e411edd5b --- /dev/null +++ b/geoip/include/alibabacloud/geoip/model/DescribeIpv4LocationResult.h @@ -0,0 +1,61 @@ +/* + * 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_GEOIP_MODEL_DESCRIBEIPV4LOCATIONRESULT_H_ +#define ALIBABACLOUD_GEOIP_MODEL_DESCRIBEIPV4LOCATIONRESULT_H_ + +#include +#include +#include +#include +#include + +namespace AlibabaCloud +{ + namespace Geoip + { + namespace Model + { + class ALIBABACLOUD_GEOIP_EXPORT DescribeIpv4LocationResult : public ServiceResult + { + public: + + + DescribeIpv4LocationResult(); + explicit DescribeIpv4LocationResult(const std::string &payload); + ~DescribeIpv4LocationResult(); + std::string getIp()const; + std::string getIsp()const; + std::string getCountry()const; + std::string getCity()const; + std::string getCounty()const; + std::string getProvince()const; + + protected: + void parse(const std::string &payload); + private: + std::string ip_; + std::string isp_; + std::string country_; + std::string city_; + std::string county_; + std::string province_; + + }; + } + } +} +#endif // !ALIBABACLOUD_GEOIP_MODEL_DESCRIBEIPV4LOCATIONRESULT_H_ \ No newline at end of file diff --git a/geoip/src/GeoipClient.cc b/geoip/src/GeoipClient.cc index 5bc24a5dd..1a2e8b633 100644 --- a/geoip/src/GeoipClient.cc +++ b/geoip/src/GeoipClient.cc @@ -159,6 +159,42 @@ GeoipClient::DescribeGeoipInstancesOutcomeCallable GeoipClient::describeGeoipIns return task->get_future(); } +GeoipClient::DescribeIpv4LocationOutcome GeoipClient::describeIpv4Location(const DescribeIpv4LocationRequest &request) const +{ + auto endpointOutcome = endpointProvider_->getEndpoint(); + if (!endpointOutcome.isSuccess()) + return DescribeIpv4LocationOutcome(endpointOutcome.error()); + + auto outcome = makeRequest(endpointOutcome.result(), request); + + if (outcome.isSuccess()) + return DescribeIpv4LocationOutcome(DescribeIpv4LocationResult(outcome.result())); + else + return DescribeIpv4LocationOutcome(outcome.error()); +} + +void GeoipClient::describeIpv4LocationAsync(const DescribeIpv4LocationRequest& request, const DescribeIpv4LocationAsyncHandler& handler, const std::shared_ptr& context) const +{ + auto fn = [this, request, handler, context]() + { + handler(this, request, describeIpv4Location(request), context); + }; + + asyncExecute(new Runnable(fn)); +} + +GeoipClient::DescribeIpv4LocationOutcomeCallable GeoipClient::describeIpv4LocationCallable(const DescribeIpv4LocationRequest &request) const +{ + auto task = std::make_shared>( + [this, request]() + { + return this->describeIpv4Location(request); + }); + + asyncExecute(new Runnable([task]() { (*task)(); })); + return task->get_future(); +} + GeoipClient::DescribeIpv6LocationOutcome GeoipClient::describeIpv6Location(const DescribeIpv6LocationRequest &request) const { auto endpointOutcome = endpointProvider_->getEndpoint(); diff --git a/geoip/src/model/DescribeIpv4LocationRequest.cc b/geoip/src/model/DescribeIpv4LocationRequest.cc new file mode 100644 index 000000000..c72bea0c0 --- /dev/null +++ b/geoip/src/model/DescribeIpv4LocationRequest.cc @@ -0,0 +1,62 @@ +/* + * 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::Geoip::Model::DescribeIpv4LocationRequest; + +DescribeIpv4LocationRequest::DescribeIpv4LocationRequest() : + RpcServiceRequest("geoip", "2020-01-01", "DescribeIpv4Location") +{ + setMethod(HttpRequest::Method::Post); +} + +DescribeIpv4LocationRequest::~DescribeIpv4LocationRequest() +{} + +std::string DescribeIpv4LocationRequest::getIp()const +{ + return ip_; +} + +void DescribeIpv4LocationRequest::setIp(const std::string& ip) +{ + ip_ = ip; + setParameter("Ip", ip); +} + +std::string DescribeIpv4LocationRequest::getUserClientIp()const +{ + return userClientIp_; +} + +void DescribeIpv4LocationRequest::setUserClientIp(const std::string& userClientIp) +{ + userClientIp_ = userClientIp; + setParameter("UserClientIp", userClientIp); +} + +std::string DescribeIpv4LocationRequest::getLang()const +{ + return lang_; +} + +void DescribeIpv4LocationRequest::setLang(const std::string& lang) +{ + lang_ = lang; + setParameter("Lang", lang); +} + diff --git a/geoip/src/model/DescribeIpv4LocationResult.cc b/geoip/src/model/DescribeIpv4LocationResult.cc new file mode 100644 index 000000000..211ce945d --- /dev/null +++ b/geoip/src/model/DescribeIpv4LocationResult.cc @@ -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. + */ + +#include +#include + +using namespace AlibabaCloud::Geoip; +using namespace AlibabaCloud::Geoip::Model; + +DescribeIpv4LocationResult::DescribeIpv4LocationResult() : + ServiceResult() +{} + +DescribeIpv4LocationResult::DescribeIpv4LocationResult(const std::string &payload) : + ServiceResult() +{ + parse(payload); +} + +DescribeIpv4LocationResult::~DescribeIpv4LocationResult() +{} + +void DescribeIpv4LocationResult::parse(const std::string &payload) +{ + Json::Reader reader; + Json::Value value; + reader.parse(payload, value); + setRequestId(value["RequestId"].asString()); + if(!value["Ip"].isNull()) + ip_ = value["Ip"].asString(); + if(!value["Country"].isNull()) + country_ = value["Country"].asString(); + if(!value["Province"].isNull()) + province_ = value["Province"].asString(); + if(!value["City"].isNull()) + city_ = value["City"].asString(); + if(!value["County"].isNull()) + county_ = value["County"].asString(); + if(!value["Isp"].isNull()) + isp_ = value["Isp"].asString(); + +} + +std::string DescribeIpv4LocationResult::getIp()const +{ + return ip_; +} + +std::string DescribeIpv4LocationResult::getIsp()const +{ + return isp_; +} + +std::string DescribeIpv4LocationResult::getCountry()const +{ + return country_; +} + +std::string DescribeIpv4LocationResult::getCity()const +{ + return city_; +} + +std::string DescribeIpv4LocationResult::getCounty()const +{ + return county_; +} + +std::string DescribeIpv4LocationResult::getProvince()const +{ + return province_; +} +