CommonClient.h 3.4 KB

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