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

Commit17a0056

Browse files
committed
firebase: void return for send request and inline checkResponse
1 parent102c84b commit17a0056

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

‎Firebase.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ Firebase& Firebase::auth(const String& auth) {
2929

3030
StringFirebase::get(const String& path) {
3131
sendRequest("GET", path);
32-
returngetBody();
32+
returnreadBody();
3333
}
3434

3535
StringFirebase::push(const String& path,const String& value) {
3636
sendRequest("POST", path, value);
37-
returngetBody();
37+
returnreadBody();
3838
}
3939

40-
boolFirebase::remove(const String& path) {
41-
int status =sendRequest("DELETE", path);
42-
return status == HTTP_CODE_OK;
40+
voidFirebase::remove(const String& path) {
41+
sendRequest("DELETE", path);
4342
}
4443

4544
Firebase&Firebase::stream(const String& path) {
@@ -81,31 +80,26 @@ String Firebase::makeURL(const String& path) {
8180
return url;
8281
}
8382

84-
intFirebase::sendRequest(constchar* method,const String& path,const String& value) {
83+
voidFirebase::sendRequest(constchar* method,const String& path,const String& value) {
8584
String url =makeURL(path);
8685
_http.begin(_host.c_str(), firebasePort, url.c_str(),true, firebaseFingerprint);
8786
int statusCode = _http.sendRequest(method, (uint8_t*)value.c_str(), value.length());
88-
checkResponse(method, url, statusCode);
89-
return statusCode;
87+
_error.reset();
88+
if (statusCode <0) {
89+
_error.set(statusCode,
90+
String(method) +"" + url +":"
91+
+HTTPClient::errorToString(statusCode));
92+
}
9093
}
9194

92-
StringFirebase::getBody() {
95+
StringFirebase::readBody() {
9396
if (_error.code() !=0) {
9497
return"";
9598
}
9699
// no _http.end() because of connection reuse.
97100
return _http.getString();
98101
}
99102

100-
voidFirebase::checkResponse(constchar* method,const String& url,int statusCode) {
101-
_error.reset();
102-
if (statusCode <0) {
103-
_error.set(statusCode,
104-
String(method) +"" + url +":"
105-
+HTTPClient::errorToString(statusCode));
106-
}
107-
}
108-
109103
boolFirebase::connected() {
110104
return _http.connected();
111105
}

‎Firebase.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Firebase {
5252
}
5353
Stringget(const String& path);
5454
Stringpush(const String& path,const String& value);
55-
boolremove(const String& path);
55+
voidremove(const String& path);
5656
boolconnected();
5757
Firebase&stream(const String& path);
5858
boolavailable();
@@ -64,9 +64,8 @@ class Firebase {
6464
Eventread(String& event);
6565
private:
6666
StringmakeURL(const String& path);
67-
intsendRequest(constchar* method,const String& path,const String& value ="");
68-
StringgetBody();
69-
voidcheckResponse(constchar* method,const String& url,int status_code);
67+
voidsendRequest(constchar* method,const String& path,const String& value ="");
68+
StringreadBody();
7069

7170
HTTPClient _http;
7271
String _host;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp