From 58d59da9b988a99e369a93aa9d54d304896ad7dd Mon Sep 17 00:00:00 2001 From: Stefan Date: Sun, 4 Mar 2018 15:42:16 +0100 Subject: [PATCH] load pdfcrowd api key --- .../at/chaoticbits/render/HtmlImageService.java | 2 +- .../updateshandlers/CryptoHandler.java | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/at/chaoticbits/render/HtmlImageService.java b/src/main/java/at/chaoticbits/render/HtmlImageService.java index 6b99fb0..d10af26 100644 --- a/src/main/java/at/chaoticbits/render/HtmlImageService.java +++ b/src/main/java/at/chaoticbits/render/HtmlImageService.java @@ -79,7 +79,7 @@ public InputStream generateCryptoDetailsImage(CurrencyDetails currencyDetails) { try { // create the API client instance - Pdfcrowd.HtmlToImageClient client = new Pdfcrowd.HtmlToImageClient("yashino", "f87ad728dca1d05ad348a431c6bcc249"); + Pdfcrowd.HtmlToImageClient client = new Pdfcrowd.HtmlToImageClient("yashino", System.getenv("PDF_CROWD_API_KEY")); // configure the conversion client.setOutputFormat("png"); diff --git a/src/main/java/at/chaoticbits/updateshandlers/CryptoHandler.java b/src/main/java/at/chaoticbits/updateshandlers/CryptoHandler.java index 2281ab9..61915de 100644 --- a/src/main/java/at/chaoticbits/updateshandlers/CryptoHandler.java +++ b/src/main/java/at/chaoticbits/updateshandlers/CryptoHandler.java @@ -67,10 +67,17 @@ public void onUpdateReceived(Update update) { InputStream imageInputStream = CoinMarketCapService.getInstance().getCurrencyDetailsImage(command.substring(1, command.length())); - SendPhoto photo = new SendPhoto(); - photo.setChatId(message.getChatId()); - photo.setNewPhoto(command, imageInputStream); - sendPhoto(photo); + if (imageInputStream == null) { + BotLogger.error(LOGTAG, "Error creating image input stream"); + sendMessageRequest.setText("Error creating image input stream"); + sendMessage(sendMessageRequest); + } else { + + SendPhoto photo = new SendPhoto(); + photo.setChatId(message.getChatId()); + photo.setNewPhoto(command, imageInputStream); + sendPhoto(photo); + } } } catch (IllegalStateException e) {