Skip to content

Commit e8338f2

Browse files
committed
added removeData function
1 parent 9f7bf27 commit e8338f2

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/PxServ.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,59 @@ PxServ::Callback PxServ::getData(String key)
110110
}
111111
}
112112

113+
delete client;
114+
return callback;
115+
}
116+
PxServ::Callback PxServ::removeData(String key)
117+
{
118+
WiFiClientSecure *client = new WiFiClientSecure;
119+
Callback callback;
120+
121+
callback.status = -1;
122+
callback.message = "failed to send request";
123+
callback.data = "";
124+
125+
if (client)
126+
{
127+
client->setInsecure();
128+
129+
HTTPClient https;
130+
131+
if (https.begin(*client, "https://api.pxserv.net/database/removeData"))
132+
{
133+
https.addHeader("Content-Type", "application/json");
134+
135+
JSONVar body;
136+
137+
body["key"] = key;
138+
body["apiKey"] = PxServ::_apiKey;
139+
140+
int httpCode = https.POST(JSON.stringify(body));
141+
if (httpCode > 0)
142+
{
143+
144+
String payload = https.getString();
145+
JSONVar result = JSON.parse(payload);
146+
147+
if (JSON.typeof(result) != "object")
148+
{
149+
callback.status = 400;
150+
callback.message = "Response format not appropriate";
151+
}
152+
else
153+
{
154+
int status = result["status"];
155+
String message = result["message"];
156+
157+
callback.status = status;
158+
callback.message = message;
159+
}
160+
161+
https.end();
162+
}
163+
}
164+
}
165+
113166
delete client;
114167
return callback;
115168
}

src/PxServ.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class PxServ
2222
PxServ(String apiKey);
2323
Callback setData(String key, String value);
2424
Callback getData(String key);
25+
Callback removeData(String key);
2526

2627
private:
2728
String _apiKey;

0 commit comments

Comments
 (0)