1 /* 2 * Copyright 1999-2019 Alibaba Cloud All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_CORECLIENT_H_ 18 #define CORE_INCLUDE_ALIBABACLOUD_CORE_CORECLIENT_H_ 19 20 #include "ClientConfiguration.h" 21 #include "CoreExport.h" 22 #include "HttpClient.h" 23 #include "HttpRequest.h" 24 #include "HttpResponse.h" 25 #include "Outcome.h" 26 #include "Runnable.h" 27 #include "ServiceRequest.h" 28 #include <functional> 29 #include <memory> 30 #include <string> 31 32 namespace AlibabaCloud { 33 class ALIBABACLOUD_CORE_EXPORT CoreClient { 34 public: 35 CoreClient(const std::string &servicename, 36 const ClientConfiguration &configuration); 37 virtual ~CoreClient(); 38 39 ClientConfiguration configuration() const; 40 std::string serviceName() const; 41 42 protected: 43 virtual HttpClient::HttpResponseOutcome 44 AttemptRequest(const std::string &endpoint, const ServiceRequest &request, 45 HttpRequest::Method method) const; 46 Error buildCoreError(const HttpResponse &response) const; 47 bool hasResponseError(const HttpResponse &response) const; 48 virtual HttpRequest buildHttpRequest(const std::string &endpoint, 49 const ServiceRequest &msg, 50 HttpRequest::Method method) const = 0; 51 void asyncExecute(Runnable *r) const; 52 53 private: 54 std::string serviceName_; 55 ClientConfiguration configuration_; 56 std::shared_ptr<CredentialsProvider> credentialsProvider_; 57 HttpClient *httpClient_; 58 }; 59 } // namespace AlibabaCloud 60 #endif // CORE_INCLUDE_ALIBABACLOUD_CORE_CORECLIENT_H_ 61