-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.h
66 lines (59 loc) · 1.71 KB
/
api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @author Saef Taher
* @date 14/01/2018
*/
#ifndef API_H
#define API_H
#include <QString>
#include <memory>
#include <QObject>
/**
* @brief The API class is a contianer for the API url and API KEY
*/
class API
{
public:
/**
* @brief adress_ contains the url of the hue API.
*
* Example: http://localhost:80
* Atention no backslash at the end!
*
*/
QString adress_;
/**
* @brief api_key_ contains the API key to access the hue Bridge.
*
* This will not be detected by the App itself and must be set!
*/
QString api_key_;
/**
* @brief url
* @return concatenation of adress and api key to an valid url ending with /api.
*/
QString url();
/**
* @brief isAvailable check if the url retruns anything on a simple GET Request.
* @return true if the resources retruned something which is not an empty String
*
* This sends a synchronous Request to the url and may take some time to complete.
*/
bool isAvailable() const;
/**
* @brief get allows access to the current api object.
* @return weak ptr to the current api object. If there is none it will be a nullptr
*/
static std::weak_ptr<API> get();
/**
* @brief api allows to set the current api object.
* @param adress url of the API.
* @param api_key API key to hue bridge.
* @return returns the weak ptr to the current object simmilar to get().
*/
static std::weak_ptr<API> api(QString adress, QString api_key);
friend std::ostream& operator<< (std::ostream& stream, const std::weak_ptr<API>& m);
private:
API(QString adress, QString api_key);
static std::shared_ptr<API> api_;
};
#endif // API_H