Skip to content

Commit ad17ca1

Browse files
committed
Merge pull request #1 from proppy/remove-ed
firebase: void return for send request and inline checkResponse
2 parents 102c84b + 17a0056 commit ad17ca1

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

Firebase.cpp

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

3030
String Firebase::get(const String& path) {
3131
sendRequest("GET", path);
32-
return getBody();
32+
return readBody();
3333
}
3434

3535
String Firebase::push(const String& path, const String& value) {
3636
sendRequest("POST", path, value);
37-
return getBody();
37+
return readBody();
3838
}
3939

40-
bool Firebase::remove(const String& path) {
41-
int status = sendRequest("DELETE", path);
42-
return status == HTTP_CODE_OK;
40+
void Firebase::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-
int Firebase::sendRequest(const char* method, const String& path, const String& value) {
83+
void Firebase::sendRequest(const char* 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-
String Firebase::getBody() {
95+
String Firebase::readBody() {
9396
if (_error.code() != 0) {
9497
return "";
9598
}
9699
// no _http.end() because of connection reuse.
97100
return _http.getString();
98101
}
99102

100-
void Firebase::checkResponse(const char* 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
bool Firebase::connected() {
110104
return _http.connected();
111105
}

Firebase.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Firebase {
5252
}
5353
String get(const String& path);
5454
String push(const String& path, const String& value);
55-
bool remove(const String& path);
55+
void remove(const String& path);
5656
bool connected();
5757
Firebase& stream(const String& path);
5858
bool available();
@@ -64,9 +64,8 @@ class Firebase {
6464
Event read(String& event);
6565
private:
6666
String makeURL(const String& path);
67-
int sendRequest(const char* method, const String& path, const String& value = "");
68-
String getBody();
69-
void checkResponse(const char* method, const String& url, int status_code);
67+
void sendRequest(const char* method, const String& path, const String& value = "");
68+
String readBody();
7069

7170
HTTPClient _http;
7271
String _host;

0 commit comments

Comments
 (0)