From 52e7a7f4d3de82ce969b9d89e0f6d742030603ed Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Tue, 2 Feb 2016 12:28:17 -0800 Subject: [PATCH 1/2] firebase: restore set method --- Firebase.cpp | 15 +++++++++++++++ Firebase.h | 36 ++++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Firebase.cpp b/Firebase.cpp index 6752811a..ef27bd35 100644 --- a/Firebase.cpp +++ b/Firebase.cpp @@ -46,6 +46,10 @@ FirebaseGet Firebase::get(const String& path) { return FirebaseGet(host_, auth_, path, &http_); } +FirebaseSet Firebase::set(const String& path, const String& value) { + return FirebaseSet(host_, auth_, path, value, &http_); +} + FirebasePush Firebase::push(const String& path, const String& value) { return FirebasePush(host_, auth_, path, value, &http_); } @@ -115,6 +119,17 @@ FirebaseGet::FirebaseGet(const String& host, const String& auth, } } +// FirebaseSet +FirebaseSet::FirebaseSet(const String& host, const String& auth, + const String& path, const String& value, + HTTPClient* http) + : FirebaseCall(host, auth, "PUT", path, value, http) { + + if (!error()) { + // TODO: parse json + json_ = response(); + } +} // FirebasePush FirebasePush::FirebasePush(const String& host, const String& auth, const String& path, const String& value, diff --git a/Firebase.h b/Firebase.h index aac4e86c..25a96177 100644 --- a/Firebase.h +++ b/Firebase.h @@ -26,28 +26,30 @@ #include class FirebaseGet; +class FirebaseSet; class FirebasePush; class FirebaseRemove; class FirebaseStream; -// Primary client to the Firebase backend. +// Firebase REST API client. class Firebase { public: Firebase(const String& host); Firebase& auth(const String& auth); - // Fetch result at "path". + // Fetch value at "path". FirebaseGet get(const String& path); - // Add new value to list at "path", will return key for the new item. + // Set value at "path". + FirebaseSet set(const String& path, const String& value); + + // Add new value to list at "path". FirebasePush push(const String& path, const String& value); - // Deletes value at "path" from firebase. + // Delete value at "path". FirebaseRemove remove(const String& path); - // Starts a stream of events that affect object at "path". - // TODO: fix FirebaseStream lifecycle - // https://github.com/esp8266/Arduino/issues/500 + // Start a stream of events that affect value at "path". FirebaseStream stream(const String& path); private: @@ -102,6 +104,20 @@ class FirebaseGet : public FirebaseCall { String json_; }; +class FirebaseSet: public FirebaseCall { + public: + FirebaseSet() {} + FirebaseSet(const String& host, const String& auth, + const String& path, const String& value, HTTPClient* http = NULL); + + const String& json() const { + return json_; + } + + private: + String json_; +}; + class FirebasePush : public FirebaseCall { public: FirebasePush() {} @@ -130,17 +146,17 @@ class FirebaseStream : public FirebaseCall { FirebaseStream(const String& host, const String& auth, const String& path, HTTPClient* http = NULL); - // True if there is an event available. + // Return if there is events available to read. bool available(); - // event type. + // Event type. enum Event { UNKNOWN, PUT, PATCH }; - // Read next event in stream. + // Read next event from the stream. Event read(String& event); const FirebaseError& error() const { From 65ec1bf30b373988d86b2db0b6392e29f459c26e Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Tue, 2 Feb 2016 12:41:42 -0800 Subject: [PATCH 2/2] firebase: better docstrings --- Firebase.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Firebase.h b/Firebase.h index 25a96177..f82a0376 100644 --- a/Firebase.h +++ b/Firebase.h @@ -37,19 +37,19 @@ class Firebase { Firebase(const String& host); Firebase& auth(const String& auth); - // Fetch value at "path". + // Fetch json encoded `value` at `path`. FirebaseGet get(const String& path); - // Set value at "path". - FirebaseSet set(const String& path, const String& value); + // Set json encoded `value` at `path`. + FirebaseSet set(const String& path, const String& json); - // Add new value to list at "path". - FirebasePush push(const String& path, const String& value); + // Add new json encoded `value` to list at `path`. + FirebasePush push(const String& path, const String& json); - // Delete value at "path". + // Delete value at `path`. FirebaseRemove remove(const String& path); - // Start a stream of events that affect value at "path". + // Start a stream of events that affect value at `path`. FirebaseStream stream(const String& path); private: @@ -146,7 +146,7 @@ class FirebaseStream : public FirebaseCall { FirebaseStream(const String& host, const String& auth, const String& path, HTTPClient* http = NULL); - // Return if there is events available to read. + // Return if there is any event available to read. bool available(); // Event type. @@ -156,7 +156,7 @@ class FirebaseStream : public FirebaseCall { PATCH }; - // Read next event from the stream. + // Read next json encoded `event` from stream. Event read(String& event); const FirebaseError& error() const {