diff --git a/library/src/main/java/com/pengrad/telegrambot/Bot.java b/library/src/main/java/com/pengrad/telegrambot/Bot.java new file mode 100644 index 00000000..0acc0416 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/Bot.java @@ -0,0 +1,32 @@ +package com.pengrad.telegrambot; + +import com.pengrad.telegrambot.model.File; +import com.pengrad.telegrambot.request.BaseRequest; +import com.pengrad.telegrambot.request.GetUpdates; +import com.pengrad.telegrambot.response.BaseResponse; + +import java.io.IOException; + +public interface Bot { + , R extends BaseResponse> R execute(BaseRequest request); + + , R extends BaseResponse> void execute(T request, Callback callback); + + String getToken(); + + String getFullFilePath(File file); + + byte[] getFileContent(File file) throws IOException; + + void setUpdatesListener(UpdatesListener listener); + + void setUpdatesListener(UpdatesListener listener, GetUpdates request); + + void setUpdatesListener(UpdatesListener listener, ExceptionHandler exceptionHandler); + + void setUpdatesListener(UpdatesListener listener, ExceptionHandler exceptionHandler, GetUpdates request); + + void removeGetUpdatesListener(); + + void shutdown(); +} diff --git a/library/src/main/java/com/pengrad/telegrambot/TelegramBot.java b/library/src/main/java/com/pengrad/telegrambot/TelegramBot.java index fbecdad8..7bf1b7c8 100644 --- a/library/src/main/java/com/pengrad/telegrambot/TelegramBot.java +++ b/library/src/main/java/com/pengrad/telegrambot/TelegramBot.java @@ -22,7 +22,7 @@ * Stas Parshin * 16 October 2015 */ -public class TelegramBot { +public class TelegramBot implements Bot { private final String token; private final TelegramBotClient api; @@ -40,22 +40,27 @@ public TelegramBot(String botToken) { this.updatesHandler = builder.updatesHandler; } + @Override public , R extends BaseResponse> R execute(BaseRequest request) { return api.send(request); } + @Override public , R extends BaseResponse> void execute(T request, Callback callback) { api.send(request, callback); } + @Override public String getToken() { return token; } + @Override public String getFullFilePath(File file) { return fileApi.getFullFilePath(file.filePath()); } + @Override public byte[] getFileContent(File file) throws IOException { String fileUrl = getFullFilePath(file); URLConnection connection = new URL(fileUrl).openConnection(); @@ -64,26 +69,32 @@ public byte[] getFileContent(File file) throws IOException { } } + @Override public void setUpdatesListener(UpdatesListener listener) { setUpdatesListener(listener, new GetUpdates()); } + @Override public void setUpdatesListener(UpdatesListener listener, GetUpdates request) { setUpdatesListener(listener, null, request); } + @Override public void setUpdatesListener(UpdatesListener listener, ExceptionHandler exceptionHandler) { setUpdatesListener(listener, exceptionHandler, new GetUpdates()); } + @Override public void setUpdatesListener(UpdatesListener listener, ExceptionHandler exceptionHandler, GetUpdates request) { updatesHandler.start(this, listener, exceptionHandler, request); } + @Override public void removeGetUpdatesListener() { updatesHandler.stop(); } + @Override public void shutdown() { api.shutdown(); }