From 17a00560c76b9891a79963e5ff5d67c698e20eb2 Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Wed, 20 Jan 2016 12:44:37 -0800 Subject: [PATCH] firebase: void return for send request and inline checkResponse --- Firebase.cpp | 30 ++++++++++++------------------ Firebase.h | 7 +++---- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/Firebase.cpp b/Firebase.cpp index 37da0e57..40f8dfe1 100644 --- a/Firebase.cpp +++ b/Firebase.cpp @@ -29,17 +29,16 @@ Firebase& Firebase::auth(const String& auth) { String Firebase::get(const String& path) { sendRequest("GET", path); - return getBody(); + return readBody(); } String Firebase::push(const String& path, const String& value) { sendRequest("POST", path, value); - return getBody(); + return readBody(); } -bool Firebase::remove(const String& path) { - int status = sendRequest("DELETE", path); - return status == HTTP_CODE_OK; +void Firebase::remove(const String& path) { + sendRequest("DELETE", path); } Firebase& Firebase::stream(const String& path) { @@ -81,15 +80,19 @@ String Firebase::makeURL(const String& path) { return url; } -int Firebase::sendRequest(const char* method, const String& path, const String& value) { +void Firebase::sendRequest(const char* method, const String& path, const String& value) { String url = makeURL(path); _http.begin(_host.c_str(), firebasePort, url.c_str(), true, firebaseFingerprint); int statusCode = _http.sendRequest(method, (uint8_t*)value.c_str(), value.length()); - checkResponse(method, url, statusCode); - return statusCode; + _error.reset(); + if (statusCode < 0) { + _error.set(statusCode, + String(method) + " " + url + ": " + + HTTPClient::errorToString(statusCode)); + } } -String Firebase::getBody() { +String Firebase::readBody() { if (_error.code() != 0) { return ""; } @@ -97,15 +100,6 @@ String Firebase::getBody() { return _http.getString(); } -void Firebase::checkResponse(const char* method, const String& url, int statusCode) { - _error.reset(); - if (statusCode < 0) { - _error.set(statusCode, - String(method) + " " + url + ": " - + HTTPClient::errorToString(statusCode)); - } -} - bool Firebase::connected() { return _http.connected(); } diff --git a/Firebase.h b/Firebase.h index 3c48da11..ac7ff6ca 100644 --- a/Firebase.h +++ b/Firebase.h @@ -52,7 +52,7 @@ class Firebase { } String get(const String& path); String push(const String& path, const String& value); - bool remove(const String& path); + void remove(const String& path); bool connected(); Firebase& stream(const String& path); bool available(); @@ -64,9 +64,8 @@ class Firebase { Event read(String& event); private: String makeURL(const String& path); - int sendRequest(const char* method, const String& path, const String& value = ""); - String getBody(); - void checkResponse(const char* method, const String& url, int status_code); + void sendRequest(const char* method, const String& path, const String& value = ""); + String readBody(); HTTPClient _http; String _host;