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

firebase: restore set method #53

Merged
merged 2 commits into from
Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Firebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
Expand Down Expand Up @@ -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,
Expand Down
38 changes: 27 additions & 11 deletions Firebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,30 @@
#include <ESP8266HTTPClient.h>

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 json encoded `value` at `path`.
FirebaseGet get(const String& path);

// Add new value to list at "path", will return key for the new item.
FirebasePush push(const String& path, const String& value);
// Set json encoded `value` at `path`.
FirebaseSet set(const String& path, const String& json);

// Deletes value at "path" from firebase.
// Add new json encoded `value` to list at `path`.
FirebasePush push(const String& path, const String& json);

// 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:
Expand Down Expand Up @@ -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() {}
Expand Down Expand Up @@ -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 any event available to read.
bool available();

// event type.
// Event type.
enum Event {
UNKNOWN,
PUT,
PATCH
};

// Read next event in stream.
// Read next json encoded `event` from stream.
Event read(String& event);

const FirebaseError& error() const {
Expand Down