Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 52e7a7f

Browse files
committed
firebase: restore set method
1 parent 96f7d8e commit 52e7a7f

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

Firebase.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ FirebaseGet Firebase::get(const String& path) {
4646
return FirebaseGet(host_, auth_, path, &http_);
4747
}
4848

49+
FirebaseSet Firebase::set(const String& path, const String& value) {
50+
return FirebaseSet(host_, auth_, path, value, &http_);
51+
}
52+
4953
FirebasePush Firebase::push(const String& path, const String& value) {
5054
return FirebasePush(host_, auth_, path, value, &http_);
5155
}
@@ -115,6 +119,17 @@ FirebaseGet::FirebaseGet(const String& host, const String& auth,
115119
}
116120
}
117121

122+
// FirebaseSet
123+
FirebaseSet::FirebaseSet(const String& host, const String& auth,
124+
const String& path, const String& value,
125+
HTTPClient* http)
126+
: FirebaseCall(host, auth, "PUT", path, value, http) {
127+
128+
if (!error()) {
129+
// TODO: parse json
130+
json_ = response();
131+
}
132+
}
118133
// FirebasePush
119134
FirebasePush::FirebasePush(const String& host, const String& auth,
120135
const String& path, const String& value,

Firebase.h

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,30 @@
2626
#include <ESP8266HTTPClient.h>
2727

2828
class FirebaseGet;
29+
class FirebaseSet;
2930
class FirebasePush;
3031
class FirebaseRemove;
3132
class FirebaseStream;
3233

33-
// Primary client to the Firebase backend.
34+
// Firebase REST API client.
3435
class Firebase {
3536
public:
3637
Firebase(const String& host);
3738
Firebase& auth(const String& auth);
3839

39-
// Fetch result at "path".
40+
// Fetch value at "path".
4041
FirebaseGet get(const String& path);
4142

42-
// Add new value to list at "path", will return key for the new item.
43+
// Set value at "path".
44+
FirebaseSet set(const String& path, const String& value);
45+
46+
// Add new value to list at "path".
4347
FirebasePush push(const String& path, const String& value);
4448

45-
// Deletes value at "path" from firebase.
49+
// Delete value at "path".
4650
FirebaseRemove remove(const String& path);
4751

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".
5153
FirebaseStream stream(const String& path);
5254

5355
private:
@@ -102,6 +104,20 @@ class FirebaseGet : public FirebaseCall {
102104
String json_;
103105
};
104106

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+
105121
class FirebasePush : public FirebaseCall {
106122
public:
107123
FirebasePush() {}
@@ -130,17 +146,17 @@ class FirebaseStream : public FirebaseCall {
130146
FirebaseStream(const String& host, const String& auth,
131147
const String& path, HTTPClient* http = NULL);
132148

133-
// True if there is an event available.
149+
// Return if there is events available to read.
134150
bool available();
135151

136-
// event type.
152+
// Event type.
137153
enum Event {
138154
UNKNOWN,
139155
PUT,
140156
PATCH
141157
};
142158

143-
// Read next event in stream.
159+
// Read next event from the stream.
144160
Event read(String& event);
145161

146162
const FirebaseError& error() const {

0 commit comments

Comments
 (0)