Skip to content

Commit 5d50830

Browse files
committed
Added unique prefix to preprocessor macros and updated their usage
Using generic preprocessor macros like HOST opens the risk of another library or the user trying to define the same macro. To correct this, I prefixed all macros for the YouTubeAPI with YTAPI_ so they're unique. Also removed unused macros, replaced the hardcoded hostname with the existing macro, and pulled out the hardcoded timeout.
1 parent abcc3d2 commit 5d50830

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/YoutubeApi.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ String YoutubeApi::sendGetToYoutube(String command) {
3434
unsigned long now;
3535
bool avail;
3636
// Connect with youtube api over ssl
37-
if (client->connect(HOST, SSL_PORT)) {
37+
if (client->connect(YTAPI_HOST, YTAPI_SSL_PORT)) {
3838
// Serial.println(".... connected to server");
3939
String a="";
4040
char c;
4141
int ch_count=0;
4242
client->println("GET "+command+"&key="+_apiKey);
4343
now=millis();
4444
avail=false;
45-
while (millis()-now<1500) {
45+
while (millis() - now < YTAPI_TIMEOUT) {
4646
while (client->available()) {
4747
char c = client->read();
4848
//Serial.write(c);
@@ -83,7 +83,7 @@ String YoutubeApi::sendGetToYoutube(String command) {
8383
}
8484

8585
bool YoutubeApi::getChannelStatistics(String channelId){
86-
String command="https://www.googleapis.com/youtube/v3/channels?part=statistics&id="+channelId; //If you can't find it(for example if you have a custom url) look here: https://www.youtube.com/account_advanced
86+
String command="https://" YTAPI_HOST "/youtube/v3/channels?part=statistics&id="+channelId; //If you can't find it(for example if you have a custom url) look here: https://www.youtube.com/account_advanced
8787
String response = sendGetToYoutube(command); //recieve reply from youtube
8888
DynamicJsonBuffer jsonBuffer;
8989
JsonObject& root = jsonBuffer.parseObject(response);

src/YoutubeApi.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2626
#include <ArduinoJson.h>
2727
#include <Client.h>
2828

29-
#define HOST "www.googleapis.com"
30-
#define SSL_PORT 443
31-
#define HANDLE_MESSAGES 1
32-
#define MAX_BUFFER_SIZE 1250
33-
29+
#define YTAPI_HOST "www.googleapis.com"
30+
#define YTAPI_SSL_PORT 443
31+
#define YTAPI_TIMEOUT 1500
3432

3533

3634
struct channelStatistics{

0 commit comments

Comments
 (0)