MotionLib  1.0.0
SamBuCa motion library
Client.hpp
1 /*
2 ** Copyright (C) 2022 CERN
3 **
4 ** This software is provided 'as-is', without any express or implied
5 ** warranty. In no event will the authors be held liable for any damages
6 ** arising from the use of this software.
7 **
8 ** Permission is granted to anyone to use this software for any purpose,
9 ** including commercial applications, and to alter it and redistribute it
10 ** freely, subject to the following restrictions:
11 **
12 ** 1. The origin of this software must not be misrepresented; you must not
13 ** claim that you wrote the original software. If you use this software
14 ** in a product, an acknowledgment in the product documentation would be
15 ** appreciated but is not required.
16 ** 2. Altered source versions must be plainly marked as such, and must not be
17 ** misrepresented as being the original software.
18 ** 3. This notice may not be removed or altered from any source distribution.
19 **
20 ** Created on: 2022-07-14T14:43:33
21 ** Author: Sylvain Fargier <sylvain.fargier@cern.ch>
22 */
23 
24 #ifndef CLIENT_HPP__
25 #define CLIENT_HPP__
26 
27 #include <unordered_map>
28 
29 #include <oatpp/core/macro/codegen.hpp>
30 #include <oatpp/network/Address.hpp>
31 #include <oatpp/web/client/ApiClient.hpp>
32 
33 #include "Environment.hpp"
34 
35 namespace smc {
36 namespace debug {
37 
38 #include OATPP_CODEGEN_BEGIN(ApiClient)
39 
40 class Client : public oatpp::web::client::ApiClient
41 {
42 public:
43  Client(const oatpp::network::Address &address);
44 
45  static std::shared_ptr<Client> createShared(
46  const oatpp::network::Address &address)
47  {
48  return std::make_shared<Client>(address);
49  }
50 
51  API_CLIENT_INIT(Client)
52 
53  API_CALL("GET", "devices", getDevices);
54 
55  API_CALL("GET", "devices/types", getDevicesTypes);
56 
57  API_CALL("GET", "api-docs/ui", getSwaggerUi);
58 
59  API_CALL("PUT",
60  "axis/{id}/position",
61  putAxisPosition,
62  BODY_DTO(Float64, position));
63  API_CALL("POST", "axis/{id}/position", postAxisPosition);
64 
65  API_CALL("GET", "alias", getAliasList);
66  API_CALL("GET", "alias/{id}", getAlias);
67  API_CALL("PUT", "alias/{id}", putAlias, BODY_DTO(String, target));
68  API_CALL("DELETE", "alias/{id}", deleteAlias);
69 
70  std::shared_ptr<Response> put(
71  const std::string &path,
72  const oatpp::Void &body,
73  const std::unordered_map<oatpp::String, oatpp::String> &pathParams =
74  std::unordered_map<oatpp::String, oatpp::String>{});
75 
76  std::shared_ptr<Response> post(
77  const std::string &path,
78  const oatpp::Void &body,
79  const std::unordered_map<oatpp::String, oatpp::String> &pathParams =
80  std::unordered_map<oatpp::String, oatpp::String>{});
81 
82  std::shared_ptr<Response> get(
83  const std::string &path,
84  const std::unordered_map<oatpp::String, oatpp::String> &queryParams =
85  std::unordered_map<oatpp::String, oatpp::String>{},
86  const std::unordered_map<oatpp::String, oatpp::String> &pathParams =
87  std::unordered_map<oatpp::String, oatpp::String>{});
88 
89  std::shared_ptr<Response> del(
90  const std::string &path,
91  const std::unordered_map<oatpp::String, oatpp::String> &queryParams =
92  std::unordered_map<oatpp::String, oatpp::String>{},
93  const std::unordered_map<oatpp::String, oatpp::String> &pathParams =
94  std::unordered_map<oatpp::String, oatpp::String>{});
95 
96  template<typename T>
97  T readBody(const std::shared_ptr<Response> &res)
98  {
99  return res->readBodyToDto<T>(m_objectMapper);
100  }
101 
102  inline std::shared_ptr<oatpp::data::mapping::ObjectMapper> &getObjectMapper()
103  {
104  return m_objectMapper;
105  }
106 
107 protected:
108  Environment::Shared m_env{Environment::instance()};
109 };
110 
111 #include OATPP_CODEGEN_END(ApiClient)
112 
113 } // namespace debug
114 } // namespace smc
115 
116 #endif
main motion-lib namespace
Definition: Client.cpp:30