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

Added remove() method. #40

Merged
merged 5 commits into from
Jan 20, 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
25 changes: 18 additions & 7 deletions Firebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ Firebase& Firebase::auth(const String& auth) {
}

String Firebase::get(const String& path) {
return sendRequest("GET", path);
sendRequest("GET", path);
return readBody();
}

String Firebase::push(const String& path, const String& value) {
return sendRequest("POST", path, value);
sendRequest("POST", path, value);
return readBody();
}

void Firebase::remove(const String& path) {
sendRequest("DELETE", path);
}

Firebase& Firebase::stream(const String& path) {
Expand Down Expand Up @@ -74,15 +80,20 @@ String Firebase::makeURL(const String& path) {
return url;
}

String Firebase::sendRequest(const char* method, const String& path, const String& value) {
_error.reset();
void Firebase::sendRequest(const char* method, const String& path, const String& value) {
String url = makeURL(path);
_http.begin(_host.c_str(), firebasePort, url.c_str(), true, firebaseFingerprint);
int statusCode = _http.sendRequest(method, (uint8_t*)value.c_str(), value.length());
int statusCode = _http.sendRequest(method, (uint8_t*)value.c_str(), value.length());
_error.reset();
if (statusCode < 0) {
_error.set(statusCode,
String(method) + " " + url + ": "
+ HTTPClient::errorToString(statusCode));
String(method) + " " + url + ": "
+ HTTPClient::errorToString(statusCode));
}
}

String Firebase::readBody() {
if (_error.code() != 0) {
return "";
}
// no _http.end() because of connection reuse.
Expand Down
5 changes: 4 additions & 1 deletion Firebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Firebase {
}
String get(const String& path);
String push(const String& path, const String& value);
void remove(const String& path);
bool connected();
Firebase& stream(const String& path);
bool available();
Expand All @@ -63,7 +64,9 @@ class Firebase {
Event read(String& event);
private:
String makeURL(const String& path);
String sendRequest(const char* method, const String& path, const String& value = "");
void sendRequest(const char* method, const String& path, const String& value = "");
String readBody();

HTTPClient _http;
String _host;
String _auth;
Expand Down