CommonClient.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #ifndef ALIBABACLOUD_CORE_COMMONCLIENT_H_
  17. #define ALIBABACLOUD_CORE_COMMONCLIENT_H_
  18. #include <future>
  19. #include "AsyncCallerContext.h"
  20. #include "ClientConfiguration.h"
  21. #include "CoreExport.h"
  22. #include "CoreClient.h"
  23. #include "CommonRequest.h"
  24. #include "CommonResponse.h"
  25. #include "CredentialsProvider.h"
  26. namespace AlibabaCloud
  27. {
  28. class ALIBABACLOUD_CORE_EXPORT CommonClient : public CoreClient
  29. {
  30. public:
  31. typedef Outcome<Error, CommonResponse> CommonResponseOutcome;
  32. typedef std::future<CommonResponseOutcome> CommonResponseOutcomeCallable;
  33. typedef std::function<void(const CommonClient*, const CommonRequest&, const CommonResponseOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> CommonResponseAsyncHandler;
  34. typedef Outcome<Error, std::string> JsonOutcome;
  35. CommonClient(const Credentials &credentials, const ClientConfiguration &configuration);
  36. CommonClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
  37. CommonClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
  38. ~CommonClient();
  39. CommonResponseOutcome commonResponse(const CommonRequest &request)const;
  40. void commonResponseAsync(const CommonRequest& request, const CommonResponseAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
  41. CommonResponseOutcomeCallable commonResponseCallable(const CommonRequest& request) const;
  42. protected:
  43. virtual HttpRequest buildHttpRequest(const std::string & endpoint, const ServiceRequest & msg, HttpRequest::Method method) const override;
  44. HttpRequest buildHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const;
  45. HttpRequest buildRoaHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const;
  46. HttpRequest buildRpcHttpRequest(const std::string & endpoint, const CommonRequest &msg, HttpRequest::Method method) const;
  47. JsonOutcome makeRequest(const std::string &endpoint, const CommonRequest &msg, HttpRequest::Method method = HttpRequest::Method::Get)const;
  48. using CoreClient::asyncExecute;
  49. private:
  50. std::shared_ptr<CredentialsProvider> credentialsProvider_;
  51. std::shared_ptr<Signer> signer_;
  52. };
  53. }
  54. #endif // !ALIBABACLOUD_CORE_COMMONCLIENT_H_