From 0e7e4408aca96eb2a1b5291ca4a9581341d51711 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Mon, 25 Feb 2019 00:21:31 +0100 Subject: [PATCH] no update logging --- .../java/de/mrbesen/telegram/TelegramAPI.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/mrbesen/telegram/TelegramAPI.java b/src/main/java/de/mrbesen/telegram/TelegramAPI.java index 783eb1f..ab2139b 100644 --- a/src/main/java/de/mrbesen/telegram/TelegramAPI.java +++ b/src/main/java/de/mrbesen/telegram/TelegramAPI.java @@ -90,19 +90,15 @@ public class TelegramAPI implements Runnable { async.enque(task); } - public void request(String request, String parameter, boolean async) { - if(async) { - this.async.enque(request, parameter); - } else { - try { - request(request, parameter); - } catch(IOException e) { - e.printStackTrace(); - } - } + public void requestAsync(String request, String parameter) { + this.async.enque(request, parameter); + } + + public JSONObject request(String request, String parameter) throws IOException { + return request(request, parameter, true); } - public JSONObject request(String request, String parameter) throws IOException { + public JSONObject request(String request, String parameter, boolean logging) throws IOException { //do https stuff URL url = new URL(API_URL + apikey + "/" + request); HttpsURLConnection con = (HttpsURLConnection)url.openConnection(); @@ -112,7 +108,8 @@ public class TelegramAPI implements Runnable { wr.write(parameter); wr.flush(); - log.log( "request: " + request + " content " + parameter + " -> " + con.getResponseCode() + ", " + con.getResponseMessage()); + if(logging) + log.log( "request: " + request + " content " + parameter + " -> " + con.getResponseCode() + ", " + con.getResponseMessage()); if(con.getResponseCode() == 200) { return new JSONObject(readfromIS(con.getInputStream())); @@ -155,7 +152,7 @@ public class TelegramAPI implements Runnable { t.setExceptionhandl(asyncm.excpt == null ? IOE400supressor : asyncm.excpt); async.enque(t); } else { - JSONObject o = request(msg.getCommand(), msg.getQ()); + JSONObject o = request(msg.getCommand(), msg.getQ(), true); return new TMessage(o.getJSONObject("result"), this); } } catch(IOException e) { @@ -179,6 +176,15 @@ public class TelegramAPI implements Runnable { }).start(); } + /** + * creates internal APIEror, when message is not modyfied! TODO; run update Caption with MessageBuilder and catch that error + * @param newCaption + * @param chatid + * @param msg_id + * @param rm + * @param async + * @param clb + */ public void updateCaption(final String newCaption, int chatid, int msg_id, TReplyMarkup rm, boolean async, Callback clb) { try { String rply = ""; @@ -233,7 +239,7 @@ public class TelegramAPI implements Runnable { private void fetchUpdates() { try { - processUpdates(request("getUpdates", "offset=" + msg_offset)); + processUpdates(request("getUpdates", "offset=" + msg_offset, false)); } catch (IOException e) { log.log("error getting updates.", e); }