#include "rest_request.h"
#include "logging.h"
#include "samonitor_tag.h"
-#include "sysinfo.h"
namespace
{
const std::string REGISTER_REST_API{"/api/device-service/register-device"};
const std::string UPDATES_REST_API{"/api/device-service/get-updates"};
-void restResultGuard(NetworkManager::RestRequest::Result result)
+void restResultGuard(communication::RestRequest::Result result)
{
- if (result != NetworkManager::RestRequest::HTTP_OK) {
+ if (result != communication::RestRequest::HTTP_OK) {
throw std::runtime_error("RestService: Http error " + std::to_string(static_cast<int>(result)));
}
}
}
-namespace NetworkManager
+namespace communication
{
RestService::RestService(const std::string& server_address)
: host(server_address)
{
-
}
RestService::~RestService()
{
-
}
std::string RestService::getUpdates(const SessionInfo& info)
RestRequest::QueryParameters params{{"duid", info.duid}};
std::string response_body;
auto result = request.get(params, UPDATES_REST_API, response_body);
- switch(result) {
+ switch (result) {
case RestRequest::HTTP_OK:
LOG_D(TAG, "HTTP_OK");
break;
return response_body;
}
-std::string RestService::registerDevice(const SessionInfo& info)
+std::string RestService::registerDevice(const SessionInfo& info, const Json::Value& data)
{
RestRequest request(host);
- Json::Value root;
- root["sn"] = SysInfo::tizenId();
- root["model"] = SysInfo::model();
- root["type"] = SysInfo::type();
- root["sw"] = SysInfo::swVersion();
- root["osname"] = SysInfo::osName();
- root["osver"] = SysInfo::osVersion();
Json::FastWriter writer;
- std::string payload = writer.write(root);
- LOG_D(TAG, "Request body: %s", payload.c_str());
+ std::string payload = writer.write(data);
+ LOG_D(TAG, "Request body: %.511s", payload.c_str());
request.addHeader("Content-Type", "application/json");
restResultGuard(request.post(RestRequest::QueryParameters{}, REGISTER_REST_API, payload));
- LOG_D(TAG, "Response: %s", request.body().c_str());
+ LOG_D(TAG, "Response: %.511s", request.body().c_str());
return request.body();
}
request.addHeader("Content-Type", "application/json");
std::string response;
restResultGuard(request.get(RestRequest::QueryParameters{}, uri, response));
- LOG_D(TAG, "Response: %s", response.c_str());
+ LOG_D(TAG, "Response: %.511s", response.c_str());
return response;
}
void RestService::sendData(const SessionInfo& info, const std::string& data)
{
- LOG_D(TAG, "Request body: %s", data.c_str());
+ LOG_D(TAG, "Request body: %.511s", data.c_str());
RestRequest request(host);
request.addHeader("Content-Type", "application/json");
restResultGuard(request.post(RestRequest::QueryParameters{{"duid", info.duid}}, SEND_DATA_REST_API, data));
- LOG_D(TAG, "Response: %s", request.body().c_str());
+ LOG_D(TAG, "Response: %.511s", request.body().c_str());
}
void RestService::sendData(const SessionInfo& info, const Json::Value& data)