hueplusplus  1.0.0
Classes | Public Member Functions | List of all members
hueplusplus::HueCommandAPI Class Reference

#include <hueplusplus/HueCommandAPI.h>

Public Member Functions

 HueCommandAPI (const std::string &ip, int port, const std::string &username, std::shared_ptr< const IHttpHandler > httpHandler)
 Construct from ip, username and HttpHandler. More...
 
 HueCommandAPI (const HueCommandAPI &)=default
 Copy construct from other HueCommandAPI. More...
 
 HueCommandAPI (HueCommandAPI &&)=default
 Move construct from other HueCommandAPI. More...
 
HueCommandAPIoperator= (const HueCommandAPI &)=default
 Copy assign from other HueCommandAPI. More...
 
HueCommandAPIoperator= (HueCommandAPI &&)=default
 Move assign from other HueCommandAPI. More...
 
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. More...
 
nlohmann::json PUTRequest (const std::string &path, const nlohmann::json &request) const
 
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. More...
 
nlohmann::json GETRequest (const std::string &path, const nlohmann::json &request) const
 
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. More...
 
nlohmann::json DELETERequest (const std::string &path, const nlohmann::json &request) const
 
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. More...
 
nlohmann::json POSTRequest (const std::string &path, const nlohmann::json &request) const
 
std::string combinedPath (const std::string &path) const
 Combines path with api prefix and username. More...
 

Detailed Description

Handles communication to the bridge via IHttpHandler and enforces a timeout between each request

Constructor & Destructor Documentation

◆ HueCommandAPI() [1/3]

hueplusplus::HueCommandAPI::HueCommandAPI ( const std::string &  ip,
int  port,
const std::string &  username,
std::shared_ptr< const IHttpHandler httpHandler 
)

Construct from ip, username and HttpHandler.

Parameters
ipip address of the Hue bridge in dotted decimal notation like "192.168.2.1"
portof the hue bridge
usernameusername that is used to control the bridge
httpHandlerHttpHandler for communication with the bridge

◆ HueCommandAPI() [2/3]

hueplusplus::HueCommandAPI::HueCommandAPI ( const HueCommandAPI )
default

Copy construct from other HueCommandAPI.

Note
All copies refer to the same timeout data, so even calls from different objects will be delayed

◆ HueCommandAPI() [3/3]

hueplusplus::HueCommandAPI::HueCommandAPI ( HueCommandAPI &&  )
default

Move construct from other HueCommandAPI.

Note
All copies refer to the same timeout data, so even calls from different objects will be delayed

Member Function Documentation

◆ combinedPath()

std::string hueplusplus::HueCommandAPI::combinedPath ( const std::string &  path) const

Combines path with api prefix and username.

Returns
"/api/<username>/<path>"

◆ DELETERequest() [1/2]

nlohmann::json hueplusplus::HueCommandAPI::DELETERequest ( const std::string &  path,
const nlohmann::json &  request,
FileInfo  fileInfo 
) const

Sends a HTTP DELETE request to the bridge and returns the response.

This function will block until at least Config::getBridgeRequestDelay() has passed to any previous request

Parameters
pathAPI request path (appended after /api/{username})
requestRequest to the api, may be empty
fileInfoFile information for thrown exceptions.
Returns
The return value of the underlying IHttpHandler::DELETEJson call
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contains no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

◆ DELETERequest() [2/2]

nlohmann::json hueplusplus::HueCommandAPI::DELETERequest ( const std::string &  path,
const nlohmann::json &  request 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ GETRequest() [1/2]

nlohmann::json hueplusplus::HueCommandAPI::GETRequest ( const std::string &  path,
const nlohmann::json &  request,
FileInfo  fileInfo 
) const

Sends a HTTP GET request to the bridge and returns the response.

This function will block until at least Config::getBridgeRequestDelay() has passed to any previous request

Parameters
pathAPI request path (appended after /api/{username})
requestRequest to the api, may be empty
fileInfoFile information for thrown exceptions.
Returns
The return value of the underlying IHttpHandler::GETJson call
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contains no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

◆ GETRequest() [2/2]

nlohmann::json hueplusplus::HueCommandAPI::GETRequest ( const std::string &  path,
const nlohmann::json &  request 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator=() [1/2]

HueCommandAPI& hueplusplus::HueCommandAPI::operator= ( const HueCommandAPI )
default

Copy assign from other HueCommandAPI.

Note
All copies refer to the same timeout data, so even calls from different objects will be delayed

◆ operator=() [2/2]

HueCommandAPI& hueplusplus::HueCommandAPI::operator= ( HueCommandAPI &&  )
default

Move assign from other HueCommandAPI.

Note
All copies refer to the same timeout data, so even calls from different objects will be delayed

◆ POSTRequest() [1/2]

nlohmann::json hueplusplus::HueCommandAPI::POSTRequest ( const std::string &  path,
const nlohmann::json &  request,
FileInfo  fileInfo 
) const

Sends a HTTP POST request to the bridge and returns the response.

This function will block until at least Config::getBridgeRequestDelay() has passed to any previous request

Parameters
pathAPI request path (appended after /api/{username})
requestRequest to the api, may be empty
fileInfoFile information for thrown exceptions.
Returns
The return value of the underlying IHttpHandler::POSTJson call
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contains no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

◆ POSTRequest() [2/2]

nlohmann::json hueplusplus::HueCommandAPI::POSTRequest ( const std::string &  path,
const nlohmann::json &  request 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ PUTRequest() [1/2]

nlohmann::json hueplusplus::HueCommandAPI::PUTRequest ( const std::string &  path,
const nlohmann::json &  request,
FileInfo  fileInfo 
) const

Sends a HTTP PUT request to the bridge and returns the response.

This function will block until at least Config::getBridgeRequestDelay() has passed to any previous request

Parameters
pathAPI request path (appended after /api/{username})
requestRequest to the api, may be empty
fileInfoFile information for thrown exceptions.
Returns
The return value of the underlying IHttpHandler::PUTJson call
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contains no body
HueAPIResponseExceptionwhen response contains an error

◆ PUTRequest() [2/2]

nlohmann::json hueplusplus::HueCommandAPI::PUTRequest ( const std::string &  path,
const nlohmann::json &  request 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.


The documentation for this class was generated from the following files: