|
20 | 20 | #include "Firebase.h"
|
21 | 21 | #include "FirebaseObject.h"
|
22 | 22 |
|
| 23 | +/** |
| 24 | + * Main class for Arduino clients to interact with Firebase. |
| 25 | + * This implementation is designed to follow Arduino best practices and favor |
| 26 | + * simplicity over all else. |
| 27 | + * For more complicated usecases and more control see the Firebase class in |
| 28 | + * Firebase.h. |
| 29 | + */ |
23 | 30 | class FirebaseArduino {
|
24 | 31 | public:
|
| 32 | + /** |
| 33 | + * Must be called first. This initialize the client with the given |
| 34 | + * firebase host and credentials. |
| 35 | + * \param host Your firebase db host, usually X.firebaseio.com. |
| 36 | + * \param auth Optional credentials for the db, a secret or token. |
| 37 | + */ |
25 | 38 | void begin(const char* host, const char* auth = "");
|
| 39 | + |
| 40 | + /** |
| 41 | + * Writes data to a new child location under the parent at path. |
| 42 | + * Equivalent to the REST API's POST. |
| 43 | + * You should check success() after calling. |
| 44 | + * \param path The path inside of your db to the parent object. |
| 45 | + * \param value Data that you wish to add under the parent. |
| 46 | + * \return The unique child key where the data was written. |
| 47 | + */ |
26 | 48 | String push(const String& path, const JsonVariant& value);
|
| 49 | + |
| 50 | + /** |
| 51 | + * Writes the data in value to the node located at path equivalent to the |
| 52 | + * REST API's PUT. |
| 53 | + * You should check success() after calling. |
| 54 | + * \param path The path inside of your db to the node you wish to update. |
| 55 | + * \param value Data that you wish to write. |
| 56 | + */ |
27 | 57 | void set(const String& path, const JsonVariant& value);
|
| 58 | + |
| 59 | + |
| 60 | + /** |
| 61 | + * Gets the value located at path. |
| 62 | + * You should check success() after calling. |
| 63 | + * \param path The path to the node you wish to retrieve. |
| 64 | + * \return The data located at that path. This may either be a single element |
| 65 | + * or it may be a json structure. Will only be populated if success() is true. |
| 66 | + */ |
28 | 67 | FirebaseObject get(const char* path);
|
| 68 | + |
| 69 | + /** |
| 70 | + * Remove the node, and possibly entire tree, located at path. |
| 71 | + * You should check success() after calling. |
| 72 | + * \param path The path to the node you wish to remove, |
| 73 | + * including all of its children. |
| 74 | + */ |
29 | 75 | void remove(const char* path);
|
| 76 | + |
| 77 | + /** |
| 78 | + * Starts streaming any changes made to the node located at path, including |
| 79 | + * any of its children. |
| 80 | + * You should check success() after calling. |
| 81 | + * This changes the state of this object. Once this is called you may start |
| 82 | + * monitoring available() and calling readEvent() to get new events. |
| 83 | + * \param path The path inside of your db to the node you wish to monitor. |
| 84 | + */ |
30 | 85 | void stream(const char* path);
|
| 86 | + |
| 87 | + /** |
| 88 | + * Checks if there are new events available. This is only meaningful once |
| 89 | + * stream() has been called. |
| 90 | + * \return If a new event is ready. |
| 91 | + */ |
31 | 92 | bool available();
|
| 93 | + |
| 94 | + /** |
| 95 | + * Reads the next event in a stream. This is only meaningful once stream() has |
| 96 | + * been called. |
| 97 | + * \return Object will have ["type"] that describes the event type, ["path"] |
| 98 | + * that describes the effected path and ["data"] that was updated. |
| 99 | + */ |
32 | 100 | FirebaseObject readEvent();
|
| 101 | + |
| 102 | + /** |
| 103 | + * \return Whether the last command was successful. |
| 104 | + */ |
33 | 105 | bool success();
|
| 106 | + |
| 107 | + /** |
| 108 | + * \return Whether the last command failed. |
| 109 | + */ |
34 | 110 | bool failed();
|
| 111 | + |
| 112 | + /** |
| 113 | + * \return Error message from last command if failed() is true. |
| 114 | + */ |
35 | 115 | const String& error();
|
36 | 116 | private:
|
37 | 117 | String host_;
|
|
0 commit comments