@@ -28,11 +28,16 @@ Firebase& Firebase::auth(const String& auth) {
28
28
}
29
29
30
30
String Firebase::get (const String& path) {
31
- return sendRequest (" GET" , path);
31
+ return sendRequestGetBody (" GET" , path);
32
32
}
33
33
34
34
String Firebase::push (const String& path, const String& value) {
35
- return sendRequest (" POST" , path, value);
35
+ return sendRequestGetBody (" POST" , path, value);
36
+ }
37
+
38
+ bool Firebase::remove (const String& path) {
39
+ int status = sendRequest (" DELETE" , path);
40
+ return status == HTTP_CODE_OK;
36
41
}
37
42
38
43
Firebase& Firebase::stream (const String& path) {
@@ -74,21 +79,32 @@ String Firebase::makeURL(const String& path) {
74
79
return url;
75
80
}
76
81
77
- String Firebase::sendRequest (const char * method, const String& path, const String& value) {
78
- _error.reset ();
82
+ int Firebase::sendRequest (const char * method, const String& path, const String& value) {
79
83
String url = makeURL (path);
80
84
_http.begin (_host.c_str (), firebasePort, url.c_str (), true , firebaseFingerprint);
81
- int statusCode = _http.sendRequest (method, (uint8_t *)value.c_str (), value.length ());
82
- if (statusCode < 0 ) {
83
- _error.set (statusCode,
84
- String (method) + " " + url + " : "
85
- + HTTPClient::errorToString (statusCode));
85
+ int statusCode = _http.sendRequest (method, (uint8_t *)value.c_str (), value.length ());
86
+ setError (method, url, statusCode);
87
+ return statusCode;
88
+ }
89
+
90
+ String Firebase::sendRequestGetBody (const char * method, const String& path, const String& value) {
91
+ sendRequest (method, path, value);
92
+ if (_error.code () != 0 ) {
86
93
return " " ;
87
94
}
88
95
// no _http.end() because of connection reuse.
89
96
return _http.getString ();
90
97
}
91
98
99
+ void Firebase::setError (const char * method, const String& url, int statusCode) {
100
+ _error.reset ();
101
+ if (statusCode < 0 ) {
102
+ _error.set (statusCode,
103
+ String (method) + " " + url + " : "
104
+ + HTTPClient::errorToString (statusCode));
105
+ }
106
+ }
107
+
92
108
bool Firebase::connected () {
93
109
return _http.connected ();
94
110
}
0 commit comments