|
26 | 26 | #include <ESP8266HTTPClient.h> |
27 | 27 |
|
28 | 28 | class FirebaseGet; |
| 29 | +class FirebaseSet; |
29 | 30 | class FirebasePush; |
30 | 31 | class FirebaseRemove; |
31 | 32 | class FirebaseStream; |
32 | 33 |
|
33 | | -// Primary client to the Firebase backend. |
| 34 | +// Firebase REST API client. |
34 | 35 | class Firebase { |
35 | 36 | public: |
36 | 37 | Firebase(const String& host); |
37 | 38 | Firebase& auth(const String& auth); |
38 | 39 |
|
39 | | - // Fetch result at "path". |
| 40 | + // Fetch json encoded `value` at `path`. |
40 | 41 | FirebaseGet get(const String& path); |
41 | 42 |
|
42 | | - // Add new value to list at "path", will return key for the new item. |
43 | | - FirebasePush push(const String& path, const String& value); |
| 43 | + // Set json encoded `value` at `path`. |
| 44 | + FirebaseSet set(const String& path, const String& json); |
44 | 45 |
|
45 | | - // Deletes value at "path" from firebase. |
| 46 | + // Add new json encoded `value` to list at `path`. |
| 47 | + FirebasePush push(const String& path, const String& json); |
| 48 | + |
| 49 | + // Delete value at `path`. |
46 | 50 | FirebaseRemove remove(const String& path); |
47 | 51 |
|
48 | | - // Starts a stream of events that affect object at "path". |
49 | | - // TODO: fix FirebaseStream lifecycle |
50 | | - // https://github.com/esp8266/Arduino/issues/500 |
| 52 | + // Start a stream of events that affect value at `path`. |
51 | 53 | FirebaseStream stream(const String& path); |
52 | 54 |
|
53 | 55 | private: |
@@ -102,6 +104,20 @@ class FirebaseGet : public FirebaseCall { |
102 | 104 | String json_; |
103 | 105 | }; |
104 | 106 |
|
| 107 | +class FirebaseSet: public FirebaseCall { |
| 108 | + public: |
| 109 | + FirebaseSet() {} |
| 110 | + FirebaseSet(const String& host, const String& auth, |
| 111 | + const String& path, const String& value, HTTPClient* http = NULL); |
| 112 | + |
| 113 | + const String& json() const { |
| 114 | + return json_; |
| 115 | + } |
| 116 | + |
| 117 | + private: |
| 118 | + String json_; |
| 119 | +}; |
| 120 | + |
105 | 121 | class FirebasePush : public FirebaseCall { |
106 | 122 | public: |
107 | 123 | FirebasePush() {} |
@@ -130,17 +146,17 @@ class FirebaseStream : public FirebaseCall { |
130 | 146 | FirebaseStream(const String& host, const String& auth, |
131 | 147 | const String& path, HTTPClient* http = NULL); |
132 | 148 |
|
133 | | - // True if there is an event available. |
| 149 | + // Return if there is any event available to read. |
134 | 150 | bool available(); |
135 | 151 |
|
136 | | - // event type. |
| 152 | + // Event type. |
137 | 153 | enum Event { |
138 | 154 | UNKNOWN, |
139 | 155 | PUT, |
140 | 156 | PATCH |
141 | 157 | }; |
142 | 158 |
|
143 | | - // Read next event in stream. |
| 159 | + // Read next json encoded `event` from stream. |
144 | 160 | Event read(String& event); |
145 | 161 |
|
146 | 162 | const FirebaseError& error() const { |
|
0 commit comments