Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a78932

Browse files
committed
Added remove() method.
1 parent615dfe4 commit6a78932

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

‎Firebase.cpp

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

3030
StringFirebase::get(const String& path) {
31-
returnsendRequest("GET", path);
31+
returnsendRequestGetBody("GET", path);
3232
}
3333

3434
StringFirebase::push(const String& path,const String& value) {
35-
returnsendRequest("POST", path, value);
35+
returnsendRequestGetBody("POST", path, value);
36+
}
37+
38+
boolFirebase::remove(const String& path) {
39+
int status =sendRequest("DELETE", path);
40+
return status == HTTP_CODE_OK;
3641
}
3742

3843
Firebase&Firebase::stream(const String& path) {
@@ -74,21 +79,32 @@ String Firebase::makeURL(const String& path) {
7479
return url;
7580
}
7681

77-
StringFirebase::sendRequest(constchar* method,const String& path,const String& value) {
78-
_error.reset();
82+
intFirebase::sendRequest(constchar* method,const String& path,const String& value) {
7983
String url =makeURL(path);
8084
_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+
StringFirebase::sendRequestGetBody(constchar* method,const String& path,const String& value) {
91+
sendRequest(method, path, value);
92+
if (_error.code() !=0) {
8693
return"";
8794
}
8895
// no _http.end() because of connection reuse.
8996
return _http.getString();
9097
}
9198

99+
voidFirebase::setError(constchar* 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+
92108
boolFirebase::connected() {
93109
return _http.connected();
94110
}

‎Firebase.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Firebase {
5252
}
5353
Stringget(const String& path);
5454
Stringpush(const String& path,const String& value);
55+
boolremove(const String& path);
5556
boolconnected();
5657
Firebase&stream(const String& path);
5758
boolavailable();
@@ -63,7 +64,10 @@ class Firebase {
6364
Eventread(String& event);
6465
private:
6566
StringmakeURL(const String& path);
66-
StringsendRequest(constchar* method,const String& path,const String& value ="");
67+
intsendRequest(constchar* method,const String& path,const String& value ="");
68+
StringsendRequestGetBody(constchar* method,const String& path,const String& value ="");
69+
voidsetError(constchar* method,const String& url,int status_code);
70+
6771
HTTPClient _http;
6872
String _host;
6973
String _auth;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp