|
12 | 12 | #include "AdafruitIO_Dashboard.h"
|
13 | 13 | #include "AdafruitIO.h"
|
14 | 14 |
|
15 |
| -AdafruitIO_Dashboard::AdafruitIO_Dashboard(AdafruitIO *io, const char *k) |
| 15 | +AdafruitIO_Dashboard::AdafruitIO_Dashboard(AdafruitIO *io, const char *n) |
16 | 16 | {
|
17 | 17 | _io = io;
|
18 |
| - key = k; |
| 18 | + name = n; |
19 | 19 | }
|
20 | 20 |
|
21 | 21 | AdafruitIO_Dashboard::~AdafruitIO_Dashboard(){}
|
| 22 | + |
| 23 | +bool AdafruitIO_Dashboard::exists() |
| 24 | +{ |
| 25 | + String url = "/api/v2/"; |
| 26 | + url += _io->_username; |
| 27 | + url += "/dashboards/"; |
| 28 | + url += name; |
| 29 | + |
| 30 | + _io->_http->startRequest(url.c_str(), HTTP_METHOD_GET); |
| 31 | + _io->_http->sendHeader("X-AIO-Key", _io->_key); |
| 32 | + _io->_http->endRequest(); |
| 33 | + |
| 34 | + int status = _io->_http->responseStatusCode(); |
| 35 | + _io->_http->responseBody(); // needs to be read even if not used |
| 36 | + |
| 37 | + return status == 200; |
| 38 | +} |
| 39 | + |
| 40 | +bool AdafruitIO_Dashboard::create() |
| 41 | +{ |
| 42 | + String url = "/api/v2/"; |
| 43 | + url += _io->_username; |
| 44 | + url += "/dashboards"; |
| 45 | + |
| 46 | + String body = "name="; |
| 47 | + body += name; |
| 48 | + |
| 49 | + _io->_http->startRequest(url.c_str(), HTTP_METHOD_POST); |
| 50 | + _io->_http->sendHeader(HTTP_HEADER_CONTENT_TYPE, "application/x-www-form-urlencoded"); |
| 51 | + _io->_http->sendHeader(HTTP_HEADER_CONTENT_LENGTH, body.length()); |
| 52 | + _io->_http->sendHeader("X-AIO-Key", _io->_key); |
| 53 | + _io->_http->endRequest(); |
| 54 | + _io->_http->write((const byte*)body.c_str(), body.length()); |
| 55 | + |
| 56 | + int status = _io->_http->responseStatusCode(); |
| 57 | + _io->_http->responseBody(); // needs to be read even if not used |
| 58 | + |
| 59 | + return status == 201; |
| 60 | +} |
| 61 | + |
0 commit comments