Skip to content

Commit cb85962

Browse files
committed
Update Signer class.
1 parent 7187d1d commit cb85962

23 files changed

+3688
-2124
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 mobizt
3+
Copyright (c) 2022 mobizt
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
# Arduino Google Sheet Client Library for ESP8266 and ESP32
22

33

4-
Arduino Google Sheet Client Library for ESP8266 and ESP32 v1.0.0.
4+
Arduino Google Sheet Client Library for ESP8266 and ESP32 v1.0.1.
55

66
This library allows devices to authenticate and communicate with Google Sheet APIs using the Service Account.
77

88
Devices will be able to read, update, append and clear sheet values. Create, read, list, and delete the spreadsheet are also supported.
99

1010

11-
The spreadsheet that created using this library owned by the Service Account and shared access to the user.
11+
The spreadsheet that created using this library, owned by the Service Account and shared access to the user.
1212

1313

1414
You can create, edit and deploy the Apps Script code via extension of spreadsheet that created by this library except for run the script due to permission denied.
1515

1616

17-
Spreadsheet created or owned by you needed to share the access with Service Account's client email then library can read, edit except for delete the user's spreadsheet due to permission denied.
17+
Spreadsheet created or owned by you, needed to share the access with Service Account's client email then library can read, and edit except for delete the user's spreadsheet due to permission denied.
1818

1919

2020
## Important Note
2121

22-
The connection to Google Sheet API endpoint takes time and the time from sending request to complete response received can be as much as 3 seconds.
22+
The connection to Google Sheet API endpoint takes time and the time from sending request to the complete response received can be as much as 3 seconds.
2323

2424
The speed is not the library or device issue unless the server issue.
2525

@@ -1232,7 +1232,7 @@ bool search(FirebaseJson *response, <string> spreadsheetId, FirebaseJsonArray *d
12321232

12331233
The MIT License (MIT)
12341234

1235-
Copyright (C) 2021 K. Suwatchai (Mobizt)
1235+
Copyright (C) 2022 K. Suwatchai (Mobizt)
12361236

12371237

12381238
Permission is hereby granted, free of charge, to any person returning a copy of

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ESP-Google-Sheet-Client",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"keywords": "communication, REST, esp32, esp8266, arduino",
55
"description": "Arduino Google Sheet REST client library for ESP8266 and ESP32. This library allows devices to communicate with Google Sheet API to read, edit and delete the spreadsheets",
66
"repository": {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name=ESP-Google-Sheet-Client
22

3-
version=1.0.0
3+
version=1.0.1
44

55
author=Mobizt
66

src/ESP_Google_Sheet_Client.cpp

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
/**
2-
* Google Sheet Client, ESP_Google_Sheet_Client.cpp v1.0.0
2+
* Google Sheet Client, ESP_Google_Sheet_Client.cpp v1.0.1
33
*
44
* This library supports Espressif ESP8266 and ESP32 MCUs
55
*
6-
* Created December 19, 2021
6+
* Created April 18, 2022
77
*
8-
*
9-
*
10-
* This work is a part of Firebase ESP Client library
11-
* Copyright (c) 2021 K. Suwatchai (Mobizt)
12-
*
138
* The MIT License (MIT)
14-
* Copyright (c) 2021 K. Suwatchai (Mobizt)
9+
* Copyright (c) 2022 K. Suwatchai (Mobizt)
1510
*
1611
*
1712
* Permission is hereby granted, free of charge, to any person returning a copy of
@@ -114,7 +109,7 @@ bool GSheetClass::setClock(float gmtOffset)
114109
return config._int.esp_signer_clock_rdy;
115110
}
116111

117-
void GSheetClass::beginRequest(FirebaseJson *response, MBSTRING &req, host_type_t host_type)
112+
void GSheetClass::beginRequest(FirebaseJson *response, MB_String &req, host_type_t host_type)
118113
{
119114

120115
if (response)
@@ -141,7 +136,7 @@ void GSheetClass::beginRequest(FirebaseJson *response, MBSTRING &req, host_type_
141136
setSecure();
142137
}
143138

144-
void GSheetClass::addHeader(MBSTRING &req, host_type_t host_type, int len)
139+
void GSheetClass::addHeader(MB_String &req, host_type_t host_type, int len)
145140
{
146141
req += FPSTR(" HTTP/1.1\r\n");
147142
if (host_type == host_type_sheet)
@@ -155,7 +150,7 @@ void GSheetClass::addHeader(MBSTRING &req, host_type_t host_type, int len)
155150
if (len > -1)
156151
{
157152
req += FPSTR("Content-Length: ");
158-
req += NUM2S(len).get();
153+
req += len;
159154
req += FPSTR("\r\n");
160155

161156
req += FPSTR("Content-Type: application/json\r\n");
@@ -232,7 +227,7 @@ void GSheetClass::setSecure()
232227
}
233228
}
234229

235-
bool GSheetClass::processRequest(FirebaseJson *response, MBSTRING &req, int &httpcode)
230+
bool GSheetClass::processRequest(FirebaseJson *response, MB_String &req, int &httpcode)
236231
{
237232

238233
config.signer.json = new FirebaseJson();
@@ -242,7 +237,7 @@ bool GSheetClass::processRequest(FirebaseJson *response, MBSTRING &req, int &htt
242237

243238
if (ret == 0)
244239
{
245-
if (this->handleServerResponse(httpcode))
240+
if (this->handleTokenResponse(httpcode))
246241
{
247242
ret = 1;
248243
if (parseJsonResponse(esp_signer_pgm_str_68) || parseJsonResponse(esp_signer_pgm_str_113))
@@ -264,7 +259,7 @@ bool GSheetClass::mGet(FirebaseJson *response, const char *spreadsheetId, const
264259
if (!checkToken())
265260
return false;
266261

267-
MBSTRING req;
262+
MB_String req;
268263
int httpcode = 0;
269264

270265
beginRequest(response, req, host_type_sheet);
@@ -285,14 +280,14 @@ bool GSheetClass::mGet(FirebaseJson *response, const char *spreadsheetId, const
285280
req += spreadsheetId;
286281
req += FPSTR("/values:batchGet");
287282

288-
std::vector<MBSTRING> rngs = std::vector<MBSTRING>();
289-
MBSTRING rng = ranges;
283+
std::vector<MB_String> rngs = std::vector<MB_String>();
284+
MB_String rng = ranges;
290285
ut->splitTk(rng, rngs, ",");
291286

292287
if (rngs.size() == 0)
293288
return false;
294289

295-
MBSTRING s;
290+
MB_String s;
296291

297292
for (size_t i = 0; i < rngs.size(); i++)
298293
{
@@ -438,7 +433,7 @@ bool GSheetClass::mUpdate(bool append, operation_type_t type, FirebaseJson *resp
438433
if (!checkToken())
439434
return false;
440435

441-
MBSTRING req;
436+
MB_String req;
442437
int httpcode = 0;
443438

444439
beginRequest(response, req, host_type_sheet);
@@ -528,7 +523,7 @@ bool GSheetClass::mClear(FirebaseJson *response, const char *spreadsheetId, cons
528523
if (!checkToken())
529524
return false;
530525

531-
MBSTRING req;
526+
MB_String req;
532527
int httpcode = 0;
533528

534529
beginRequest(response, req, host_type_sheet);
@@ -554,20 +549,20 @@ bool GSheetClass::mClear(FirebaseJson *response, const char *spreadsheetId, cons
554549
if (type == operation_type_batch)
555550
{
556551
req += FPSTR("/values:batchClear");
557-
std::vector<MBSTRING> rngs = std::vector<MBSTRING>();
558-
MBSTRING rng = ranges;
552+
std::vector<MB_String> rngs = std::vector<MB_String>();
553+
MB_String rng = ranges;
559554
ut->splitTk(rng, rngs, ",");
560555

561556
if (rngs.size() == 0)
562557
return false;
563558

564559
FirebaseJson r;
565-
MBSTRING tmp;
560+
MB_String tmp;
566561

567562
for (size_t i = 0; i < rngs.size(); i++)
568563
{
569564
tmp = (const char *)FPSTR("ranges/[");
570-
tmp += NUM2S(i).get();
565+
tmp += i;
571566
tmp += (const char *)FPSTR("]");
572567

573568
r.set(tmp.c_str(), rngs[i].c_str());
@@ -602,7 +597,7 @@ bool GSheetClass::copyTo(FirebaseJson *response, const char *spreadsheetId, uint
602597
if (!checkToken())
603598
return false;
604599

605-
MBSTRING req;
600+
MB_String req;
606601
int httpcode = 0;
607602

608603
beginRequest(response, req, host_type_sheet);
@@ -611,10 +606,10 @@ bool GSheetClass::copyTo(FirebaseJson *response, const char *spreadsheetId, uint
611606
req += spreadsheetId;
612607

613608
req += FPSTR("/sheets/");
614-
req += NUM2S(sheetId).get();
609+
req += sheetId;
615610
req += FPSTR(":copyTo");
616611

617-
MBSTRING s;
612+
MB_String s;
618613
s = FPSTR("{\"destinationSpreadsheetId\":\"");
619614
s += destinationSpreadsheetId;
620615
s += "\"}";
@@ -632,7 +627,7 @@ bool GSheetClass::batchUpdate(FirebaseJson *response, const char *spreadsheetId,
632627
if (!checkToken())
633628
return false;
634629

635-
MBSTRING req;
630+
MB_String req;
636631
int httpcode = 0;
637632

638633
beginRequest(response, req, host_type_sheet);
@@ -666,18 +661,18 @@ bool GSheetClass::batchUpdate(FirebaseJson *response, const char *spreadsheetId,
666661

667662
if (strlen(responseRanges) > 0)
668663
{
669-
std::vector<MBSTRING> rngs = std::vector<MBSTRING>();
670-
MBSTRING rng = responseRanges;
664+
std::vector<MB_String> rngs = std::vector<MB_String>();
665+
MB_String rng = responseRanges;
671666
ut->splitTk(rng, rngs, ",");
672667

673668
if (rngs.size() == 0)
674669
return false;
675-
MBSTRING tmp;
670+
MB_String tmp;
676671

677672
for (size_t i = 0; i < rngs.size(); i++)
678673
{
679674
tmp = (const char *)FPSTR("responseRanges/[");
680-
tmp += NUM2S(i).get();
675+
tmp += i;
681676
tmp += (const char *)FPSTR("]");
682677

683678
js.set(tmp.c_str(), rngs[i].c_str());
@@ -702,7 +697,7 @@ bool GSheetClass::create(FirebaseJson *response, FirebaseJson *spreadsheet, cons
702697
if (!checkToken())
703698
return false;
704699

705-
MBSTRING req;
700+
MB_String req;
706701
int httpcode = 0;
707702

708703
beginRequest(response, req, host_type_sheet);
@@ -737,15 +732,15 @@ bool GSheetClass::getMetadata(FirebaseJson *response, const char *spreadsheetId,
737732
if (!checkToken())
738733
return false;
739734

740-
MBSTRING req;
735+
MB_String req;
741736
int httpcode = 0;
742737

743738
beginRequest(response, req, host_type_sheet);
744739

745740
req = FPSTR("GET /v4/spreadsheets/");
746741
req += spreadsheetId;
747742
req += FPSTR("/developerMetadata/");
748-
req += NUM2S(metadataId).get();
743+
req += metadataId;
749744

750745
addHeader(req, host_type_sheet);
751746

@@ -761,7 +756,7 @@ bool GSheetClass::searchMetadata(FirebaseJson *response, const char *spreadsheet
761756

762757
if (dataFiltersArray)
763758
{
764-
MBSTRING req;
759+
MB_String req;
765760
int httpcode = 0;
766761

767762
beginRequest(response, req, host_type_sheet);
@@ -790,20 +785,20 @@ bool GSheetClass::getSpreadsheet(FirebaseJson *response, const char *spreadsheet
790785
if (!checkToken())
791786
return false;
792787

793-
MBSTRING req;
788+
MB_String req;
794789
int httpcode = 0;
795790

796791
beginRequest(response, req, host_type_drive);
797792

798793
req = FPSTR("GET /v4/spreadsheets/");
799794
req += spreadsheetId;
800795

801-
MBSTRING s;
796+
MB_String s;
802797

803798
if (strlen(ranges) > 0)
804799
{
805-
std::vector<MBSTRING> rngs = std::vector<MBSTRING>();
806-
MBSTRING rng = ranges;
800+
std::vector<MB_String> rngs = std::vector<MB_String>();
801+
MB_String rng = ranges;
807802
ut->splitTk(rng, rngs, ",");
808803

809804
if (rngs.size() == 0)
@@ -852,7 +847,7 @@ bool GSheetClass::getSpreadsheetByDataFilter(FirebaseJson *response, const char
852847

853848
if (dataFiltersArray)
854849
{
855-
MBSTRING req;
850+
MB_String req;
856851
int httpcode = 0;
857852

858853
beginRequest(response, req, host_type_drive);
@@ -891,7 +886,7 @@ bool GSheetClass::deleteFile(FirebaseJson *response, const char *spreadsheetId,
891886
config.signer.wcs = NULL;
892887
}
893888

894-
MBSTRING req;
889+
MB_String req;
895890
int httpcode = 0;
896891

897892
beginRequest(response, req, host_type_drive);
@@ -973,7 +968,7 @@ bool GSheetClass::listFiles(FirebaseJson *response, uint32_t pageSize, const cha
973968
delete config.signer.wcs;
974969
config.signer.wcs = NULL;
975970

976-
MBSTRING req;
971+
MB_String req;
977972
int httpcode = 0;
978973

979974
if (pageSize == 0 || pageSize > 10)
@@ -982,7 +977,7 @@ bool GSheetClass::listFiles(FirebaseJson *response, uint32_t pageSize, const cha
982977
beginRequest(response, req, host_type_drive);
983978

984979
req = FPSTR("GET /drive/v3/files?pageSize=");
985-
req += NUM2S(pageSize).get();
980+
req += pageSize;
986981

987982
if (strlen(orderBy) > 0)
988983
{
@@ -1015,7 +1010,7 @@ bool GSheetClass::createPermission(FirebaseJson *response, const char *fileid, c
10151010
delete config.signer.wcs;
10161011
config.signer.wcs = NULL;
10171012

1018-
MBSTRING req;
1013+
MB_String req;
10191014
int httpcode = 0;
10201015

10211016
beginRequest(response, req, host_type_drive);

0 commit comments

Comments
 (0)