hueplusplus  1.0.0
HueCommandAPI.h
Go to the documentation of this file.
1 
23 #ifndef INCLUDE_HUEPLUSPLUS_HUECOMMANDAPI_H
24 #define INCLUDE_HUEPLUSPLUS_HUECOMMANDAPI_H
25 
26 #include <atomic>
27 #include <chrono>
28 #include <mutex>
29 
30 #include "HueException.h"
31 #include "IHttpHandler.h"
32 
33 namespace hueplusplus
34 {
38 {
39 public:
47  const std::string& ip, int port, const std::string& username, std::shared_ptr<const IHttpHandler> httpHandler);
48 
51  HueCommandAPI(const HueCommandAPI&) = default;
54  HueCommandAPI(HueCommandAPI&&) = default;
55 
58  HueCommandAPI& operator=(const HueCommandAPI&) = default;
62 
73  nlohmann::json PUTRequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const;
75  nlohmann::json PUTRequest(const std::string& path, const nlohmann::json& request) const;
76 
88  nlohmann::json GETRequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const;
90  nlohmann::json GETRequest(const std::string& path, const nlohmann::json& request) const;
91 
103  nlohmann::json DELETERequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const;
105  nlohmann::json DELETERequest(const std::string& path, const nlohmann::json& request) const;
106 
118  nlohmann::json POSTRequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const;
120  nlohmann::json POSTRequest(const std::string& path, const nlohmann::json& request) const;
121 
124  std::string combinedPath(const std::string& path) const;
125 private:
126  struct TimeoutData
127  {
128  std::chrono::steady_clock::time_point timeout;
129  std::mutex mutex;
130  };
131 
135  nlohmann::json HandleError(FileInfo fileInfo, const nlohmann::json& response) const;
136 
137 private:
138  std::string ip;
139  int port;
140  std::string username;
141  std::shared_ptr<const IHttpHandler> httpHandler;
142  std::shared_ptr<TimeoutData> timeout;
143 };
144 } // namespace hueplusplus
145 
146 #endif
Definition: HueCommandAPI.h:37
Namespace for the hueplusplus library.
Definition: Action.h:27
nlohmann::json PUTRequest(const std::string &path, const nlohmann::json &request, FileInfo fileInfo) const
Sends a HTTP PUT request to the bridge and returns the response.
Definition: HueCommandAPI.cpp:80
HueCommandAPI & operator=(const HueCommandAPI &)=default
Copy assign from other HueCommandAPI.
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition: HueException.h:34
std::string combinedPath(const std::string &path) const
Combines path with api prefix and username.
Definition: HueCommandAPI.cpp:146
nlohmann::json POSTRequest(const std::string &path, const nlohmann::json &request, FileInfo fileInfo) const
Sends a HTTP POST request to the bridge and returns the response.
Definition: HueCommandAPI.cpp:119
HueCommandAPI(const std::string &ip, int port, const std::string &username, std::shared_ptr< const IHttpHandler > httpHandler)
Construct from ip, username and HttpHandler.
Definition: HueCommandAPI.cpp:66
nlohmann::json DELETERequest(const std::string &path, const nlohmann::json &request, FileInfo fileInfo) const
Sends a HTTP DELETE request to the bridge and returns the response.
Definition: HueCommandAPI.cpp:106
nlohmann::json GETRequest(const std::string &path, const nlohmann::json &request, FileInfo fileInfo) const
Sends a HTTP GET request to the bridge and returns the response.
Definition: HueCommandAPI.cpp:93