From 86af7f0eb838b1a84bc999abfda2c876e0c81799 Mon Sep 17 00:00:00 2001 From: JDierkse Date: Sun, 14 Jun 2020 16:39:11 +0200 Subject: [PATCH] Update Http Library --- Application/PresenceDetection.cc | 2 +- Bluetooth/Device.cpp | 11 ++++++++--- UniFi/Device.cpp | 27 +++++++++++++++++++++------ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Application/PresenceDetection.cc b/Application/PresenceDetection.cc index afb0c10..45e53a7 100644 --- a/Application/PresenceDetection.cc +++ b/Application/PresenceDetection.cc @@ -19,7 +19,7 @@ int main(int argc, char** argv) try { Logging::OpenLog(); - Logging::SetLogMask(Logging::Severity::Debug); + Logging::SetLogMask(Logging::Severity::Info); bool daemon = false; clipp::group cli { diff --git a/Bluetooth/Device.cpp b/Bluetooth/Device.cpp index 34a9c93..e292a57 100644 --- a/Bluetooth/Device.cpp +++ b/Bluetooth/Device.cpp @@ -86,7 +86,8 @@ void Device::UpdateDevicesFromInventory() { try { - std::string devices = m_httpClient.GetUrlContents(m_inventoryURL); + Http::HttpRequest request(m_inventoryURL); + std::string devices = m_httpClient.Open(request); nlohmann::json json = nlohmann::json::parse(devices); m_dynamicDevices.clear(); @@ -229,7 +230,9 @@ void Device::SendStateChange(bool present, const std::string& macAddress) try { - m_httpClient.GetUrlSilent(url.str()); + Http::HttpRequest request(url.str()); + request.ReturnType(Http::HttpRequest::ReturnType::None); + m_httpClient.Open(request); } catch (const std::exception& e) { @@ -266,7 +269,9 @@ void Device::SendStateChange(bool present, const std::string& macAddress) { try { - m_httpClient.GetUrlSilent(url); + Http::HttpRequest request(url); + request.ReturnType(Http::HttpRequest::ReturnType::None); + m_httpClient.Open(request); } catch (const std::exception& e) { diff --git a/UniFi/Device.cpp b/UniFi/Device.cpp index b6780a4..100f35a 100644 --- a/UniFi/Device.cpp +++ b/UniFi/Device.cpp @@ -69,7 +69,12 @@ bool Device::Login() headers.push_back("Content-Type: application/json"); std::stringstream output; - output << m_httpClient.GetUrlPostContents(url.str(), headers, m_cookieFile, json.dump()); + Http::HttpRequest request(url.str()); + request.Method(Http::HttpRequest::Method::POST); + request.Headers(headers); + request.CookieFile(m_cookieFile); + request.Data(json.dump()); + output << m_httpClient.Open(request); nlohmann::json outputJSON = nlohmann::json::parse(output); @@ -105,7 +110,10 @@ void Device::Logout() try { - m_httpClient.GetUrlSilent(url.str(), m_cookieFile); + Http::HttpRequest request(url.str()); + request.ReturnType(Http::HttpRequest::ReturnType::None); + request.CookieFile(m_cookieFile); + m_httpClient.Open(request); } catch (const std::exception& e) { @@ -153,7 +161,8 @@ void Device::UpdateDevicesFromInventory() { try { - std::string devices = m_httpClient.GetUrlContents(m_inventoryURL); + Http::HttpRequest request(m_inventoryURL); + std::string devices = m_httpClient.Open(request); nlohmann::json json = nlohmann::json::parse(devices); m_devices.clear(); @@ -196,7 +205,9 @@ void Device::UpdatePresentDevices() try { std::stringstream output; - output << m_httpClient.GetUrlContents(url.str(), m_cookieFile); + Http::HttpRequest request(url.str()); + request.CookieFile(m_cookieFile); + output << m_httpClient.Open(request); nlohmann::json json = nlohmann::json::parse(output); @@ -296,7 +307,9 @@ void Device::SendStateChange(bool present, const std::string& macAddress) try { - m_httpClient.GetUrlSilent(url.str()); + Http::HttpRequest request(url.str()); + request.ReturnType(Http::HttpRequest::ReturnType::None); + m_httpClient.Open(request); } catch (const std::exception& e) { @@ -333,7 +346,9 @@ void Device::SendStateChange(bool present, const std::string& macAddress) { try { - m_httpClient.GetUrlSilent(url); + Http::HttpRequest request(url); + request.ReturnType(Http::HttpRequest::ReturnType::None); + m_httpClient.Open(request); } catch (const std::exception& e) {