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

Commit 18deb49

Browse files
committed
Merge pull request #40 from ed7coyne/master
Added remove() method.
2 parents 4acc510 + ad17ca1 commit 18deb49

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

Firebase.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ Firebase& Firebase::auth(const String& auth) {
2828
}
2929

3030
String Firebase::get(const String& path) {
31-
return sendRequest("GET", path);
31+
sendRequest("GET", path);
32+
return readBody();
3233
}
3334

3435
String Firebase::push(const String& path, const String& value) {
35-
return sendRequest("POST", path, value);
36+
sendRequest("POST", path, value);
37+
return readBody();
38+
}
39+
40+
void Firebase::remove(const String& path) {
41+
sendRequest("DELETE", path);
3642
}
3743

3844
Firebase& Firebase::stream(const String& path) {
@@ -74,15 +80,20 @@ String Firebase::makeURL(const String& path) {
7480
return url;
7581
}
7682

77-
String Firebase::sendRequest(const char* method, const String& path, const String& value) {
78-
_error.reset();
83+
void Firebase::sendRequest(const char* method, const String& path, const String& value) {
7984
String url = makeURL(path);
8085
_http.begin(_host.c_str(), firebasePort, url.c_str(), true, firebaseFingerprint);
81-
int statusCode = _http.sendRequest(method, (uint8_t*)value.c_str(), value.length());
86+
int statusCode = _http.sendRequest(method, (uint8_t*)value.c_str(), value.length());
87+
_error.reset();
8288
if (statusCode < 0) {
8389
_error.set(statusCode,
84-
String(method) + " " + url + ": "
85-
+ HTTPClient::errorToString(statusCode));
90+
String(method) + " " + url + ": "
91+
+ HTTPClient::errorToString(statusCode));
92+
}
93+
}
94+
95+
String Firebase::readBody() {
96+
if (_error.code() != 0) {
8697
return "";
8798
}
8899
// no _http.end() because of connection reuse.

Firebase.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Firebase {
5252
}
5353
String get(const String& path);
5454
String push(const String& path, const String& value);
55+
void remove(const String& path);
5556
bool connected();
5657
Firebase& stream(const String& path);
5758
bool available();
@@ -63,7 +64,9 @@ class Firebase {
6364
Event read(String& event);
6465
private:
6566
String makeURL(const String& path);
66-
String sendRequest(const char* method, const String& path, const String& value = "");
67+
void sendRequest(const char* method, const String& path, const String& value = "");
68+
String readBody();
69+
6770
HTTPClient _http;
6871
String _host;
6972
String _auth;

0 commit comments

Comments
 (0)