Pārlūkot izejas kodu

Update Http Library

JDierkse 5 gadi atpakaļ
vecāks
revīzija
86af7f0eb8
3 mainītis faili ar 30 papildinājumiem un 10 dzēšanām
  1. 1 1
      Application/PresenceDetection.cc
  2. 8 3
      Bluetooth/Device.cpp
  3. 21 6
      UniFi/Device.cpp

+ 1 - 1
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 {

+ 8 - 3
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)
 				{

+ 21 - 6
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)
 				{