File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
2627private:
2728 String _apiKey;
You can’t perform that action at this time.
0 commit comments