Skip to content

Commit 6034b7a

Browse files
committed
Merge branch 'api2'
2 parents 8004117 + 0115778 commit 6034b7a

File tree

96 files changed

+2353
-853
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2353
-853
lines changed

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ task copyTestResources(type: Copy) {
1414
processTestResources.dependsOn copyTestResources
1515

1616
dependencies {
17-
compile 'com.google.code.gson:gson:2.5'
18-
compile 'com.squareup.retrofit:retrofit:1.9.0'
17+
compile 'com.google.code.gson:gson:2.6.2'
18+
compile 'com.squareup.okhttp3:okhttp:3.2.0'
19+
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
1920

2021
testCompile 'junit:junit:4.12'
2122
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.pengrad.telegrambot;
2+
3+
import com.pengrad.telegrambot.request.BaseRequest;
4+
5+
import java.io.IOException;
6+
7+
/**
8+
* stas
9+
* 5/3/16.
10+
*/
11+
public interface Callback<T extends BaseRequest, R> {
12+
13+
void onResponse(T request, R response);
14+
15+
void onFailure(T request, IOException e);
16+
}
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
package com.pengrad.telegrambot;
2+
3+
import com.pengrad.telegrambot.impl.FileApi;
4+
import com.pengrad.telegrambot.model.request.*;
5+
import com.pengrad.telegrambot.request.*;
6+
import com.pengrad.telegrambot.response.*;
7+
8+
/**
9+
* stas
10+
* 5/1/16.
11+
*/
12+
@Deprecated
13+
public abstract class OldTelegramBot {
14+
15+
private final FileApi fileApi;
16+
17+
OldTelegramBot(FileApi file) {
18+
this.fileApi = file;
19+
}
20+
21+
abstract public <T extends BaseRequest, R> R execute(BaseRequest<T, R> request);
22+
23+
@Deprecated
24+
public GetFileResponse getFile(String fileId) {
25+
return execute(new GetFile(fileId));
26+
}
27+
28+
@Deprecated
29+
public String getFullFilePath(String fileId) {
30+
GetFileResponse fileResponse = execute(new GetFile(fileId));
31+
if (!fileResponse.isOk() || fileResponse.file() == null) {
32+
return null;
33+
}
34+
return fileApi.getFullFilePath(fileResponse.file().filePath());
35+
}
36+
37+
@Deprecated
38+
public GetMeResponse getMe() {
39+
return execute(new GetMe());
40+
}
41+
42+
@Deprecated
43+
public BaseResponse sendChatAction(Object chatId, ChatAction action) {
44+
return execute(new SendChatAction(chatId, action.name()));
45+
}
46+
47+
@Deprecated
48+
public SendResponse sendMessage(Object chatId, String text) {
49+
return execute(new SendMessage(chatId, text));
50+
}
51+
52+
@Deprecated
53+
public SendResponse sendMessage(Object chatId, String text, ParseMode parseMode, Boolean disableWebPagePreview, Integer replyToMessageId, Keyboard replyMarkup) {
54+
SendMessage request = new SendMessage(chatId, text);
55+
if (parseMode != null) request.parseMode(parseMode);
56+
if (disableWebPagePreview != null) request.disableWebPagePreview(disableWebPagePreview);
57+
if (replyToMessageId != null) request.replyToMessageId(replyToMessageId);
58+
if (replyMarkup != null) request.replyMarkup(replyMarkup);
59+
return execute(request);
60+
}
61+
62+
@Deprecated
63+
public SendResponse forwardMessage(Object chatId, Object fromChatId, Integer messageId) {
64+
return execute(new ForwardMessage(chatId, fromChatId, messageId));
65+
}
66+
67+
@Deprecated
68+
public SendResponse sendPhoto(Object chatId, String photo, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
69+
return sendPhoto(chatId, photo, caption, replyToMessageId, replyMarkup, false);
70+
}
71+
72+
@Deprecated
73+
public SendResponse sendPhoto(Object chatId, InputFile photo, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
74+
return sendPhoto(chatId, photo.getFile(), caption, replyToMessageId, replyMarkup, true);
75+
}
76+
77+
@Deprecated
78+
public SendResponse sendPhoto(Object chatId, InputFileBytes photo, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
79+
return sendPhoto(chatId, photo.getBytes(), caption, replyToMessageId, replyMarkup, true);
80+
}
81+
82+
private SendResponse sendPhoto(Object chatId, Object photo, String caption, Integer replyToMessageId, Keyboard replyMarkup, boolean isMultipart) {
83+
SendPhoto request = new SendPhoto(chatId, photo, isMultipart);
84+
if (caption != null) request.caption(caption);
85+
if (replyToMessageId != null) request.replyToMessageId(replyToMessageId);
86+
if (replyMarkup != null) request.replyMarkup(replyMarkup);
87+
return execute(request);
88+
}
89+
90+
@Deprecated
91+
public SendResponse sendAudio(Object chatId, String audio, Integer duration, String performer, String title, Integer replyToMessageId, Keyboard replyMarkup) {
92+
return sendAudio(chatId, audio, duration, performer, title, replyToMessageId, replyMarkup, false);
93+
}
94+
95+
@Deprecated
96+
public SendResponse sendAudio(Object chatId, InputFile audio, Integer duration, String performer, String title, Integer replyToMessageId, Keyboard replyMarkup) {
97+
return sendAudio(chatId, audio.getFile(), duration, performer, title, replyToMessageId, replyMarkup, true);
98+
}
99+
100+
@Deprecated
101+
public SendResponse sendAudio(Object chatId, InputFileBytes audio, Integer duration, String performer, String title, Integer replyToMessageId, Keyboard replyMarkup) {
102+
return sendAudio(chatId, audio.getBytes(), duration, performer, title, replyToMessageId, replyMarkup, true);
103+
}
104+
105+
private SendResponse sendAudio(Object chatId, Object audio, Integer duration, String performer, String title, Integer replyToMessageId, Keyboard replyMarkup, boolean isMultipart) {
106+
SendAudio request = new SendAudio(chatId, audio, isMultipart);
107+
if (duration != null) request.duration(duration);
108+
if (performer != null) request.performer(performer);
109+
if (title != null) request.title(title);
110+
if (replyToMessageId != null) request.replyToMessageId(replyToMessageId);
111+
if (replyMarkup != null) request.replyMarkup(replyMarkup);
112+
return execute(request);
113+
}
114+
115+
@Deprecated
116+
public SendResponse sendDocument(Object chatId, String document, Integer replyToMessageId, Keyboard replyMarkup) {
117+
return sendDocument(chatId, document, replyToMessageId, replyMarkup, false);
118+
}
119+
120+
@Deprecated
121+
public SendResponse sendDocument(Object chatId, InputFile document, Integer replyToMessageId, Keyboard replyMarkup) {
122+
return sendDocument(chatId, document.getFile(), replyToMessageId, replyMarkup, true);
123+
}
124+
125+
@Deprecated
126+
public SendResponse sendDocument(Object chatId, InputFileBytes document, Integer replyToMessageId, Keyboard replyMarkup) {
127+
return sendDocument(chatId, document.getBytes(), replyToMessageId, replyMarkup, true);
128+
}
129+
130+
private SendResponse sendDocument(Object chatId, Object document, Integer replyToMessageId, Keyboard replyMarkup, boolean isMultipart) {
131+
SendDocument request = new SendDocument(chatId, document, isMultipart);
132+
if (replyToMessageId != null) request.replyToMessageId(replyToMessageId);
133+
if (replyMarkup != null) request.replyMarkup(replyMarkup);
134+
return execute(request);
135+
}
136+
137+
@Deprecated
138+
public SendResponse sendSticker(Object chatId, String sticker, Integer replyToMessageId, Keyboard replyMarkup) {
139+
return sendSticker(chatId, sticker, replyToMessageId, replyMarkup, false);
140+
}
141+
142+
@Deprecated
143+
public SendResponse sendSticker(Object chatId, InputFile sticker, Integer replyToMessageId, Keyboard replyMarkup) {
144+
return sendSticker(chatId, sticker.getFile(), replyToMessageId, replyMarkup, true);
145+
}
146+
147+
@Deprecated
148+
public SendResponse sendSticker(Object chatId, InputFileBytes sticker, Integer replyToMessageId, Keyboard replyMarkup) {
149+
return sendSticker(chatId, sticker.getBytes(), replyToMessageId, replyMarkup, true);
150+
}
151+
152+
private SendResponse sendSticker(Object chatId, Object sticker, Integer replyToMessageId, Keyboard replyMarkup, boolean isMultipart) {
153+
SendSticker request = new SendSticker(chatId, sticker, isMultipart);
154+
if (replyToMessageId != null) request.replyToMessageId(replyToMessageId);
155+
if (replyMarkup != null) request.replyMarkup(replyMarkup);
156+
return execute(request);
157+
}
158+
159+
@Deprecated
160+
public SendResponse sendVideo(Object chatId, String video, Integer duration, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
161+
return sendVideo(chatId, video, duration, caption, replyToMessageId, replyMarkup, false);
162+
}
163+
164+
@Deprecated
165+
public SendResponse sendVideo(Object chatId, InputFile video, Integer duration, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
166+
return sendVideo(chatId, video.getFile(), duration, caption, replyToMessageId, replyMarkup, true);
167+
}
168+
169+
@Deprecated
170+
public SendResponse sendVideo(Object chatId, InputFileBytes video, Integer duration, String caption, Integer replyToMessageId, Keyboard replyMarkup) {
171+
return sendVideo(chatId, video.getBytes(), duration, caption, replyToMessageId, replyMarkup, true);
172+
}
173+
174+
private SendResponse sendVideo(Object chatId, Object video, Integer duration, String caption, Integer replyToMessageId, Keyboard replyMarkup, boolean isMultipart) {
175+
SendVideo request = new SendVideo(chatId, video, isMultipart);
176+
if (duration != null) request.duration(duration);
177+
if (caption != null) request.caption(caption);
178+
if (replyToMessageId != null) request.replyToMessageId(replyToMessageId);
179+
if (replyMarkup != null) request.replyMarkup(replyMarkup);
180+
return execute(request);
181+
}
182+
183+
@Deprecated
184+
public SendResponse sendVoice(Object chatId, String voice, Integer duration, Integer replyToMessageId, Keyboard replyMarkup) {
185+
return sendVoice(chatId, voice, duration, replyToMessageId, replyMarkup, false);
186+
}
187+
188+
@Deprecated
189+
public SendResponse sendVoice(Object chatId, InputFile voice, Integer duration, Integer replyToMessageId, Keyboard replyMarkup) {
190+
return sendVoice(chatId, voice.getFile(), duration, replyToMessageId, replyMarkup, true);
191+
}
192+
193+
@Deprecated
194+
public SendResponse sendVoice(Object chatId, InputFileBytes voice, Integer duration, Integer replyToMessageId, Keyboard replyMarkup) {
195+
return sendVoice(chatId, voice.getBytes(), duration, replyToMessageId, replyMarkup, true);
196+
}
197+
198+
private SendResponse sendVoice(Object chatId, Object voice, Integer duration, Integer replyToMessageId, Keyboard replyMarkup, boolean isMultipart) {
199+
SendVoice request = new SendVoice(chatId, voice, isMultipart);
200+
if (duration != null) request.duration(duration);
201+
if (replyToMessageId != null) request.replyToMessageId(replyToMessageId);
202+
if (replyMarkup != null) request.replyMarkup(replyMarkup);
203+
return execute(request);
204+
}
205+
206+
@Deprecated
207+
public SendResponse sendLocation(Object chatId, Float latitude, Float longitude, Integer replyToMessageId, Keyboard replyMarkup) {
208+
SendLocation request = new SendLocation(chatId, latitude, longitude);
209+
if (replyToMessageId != null) request.replyToMessageId(replyToMessageId);
210+
if (replyMarkup != null) request.replyMarkup(replyMarkup);
211+
return execute(request);
212+
}
213+
214+
@Deprecated
215+
public GetUserProfilePhotosResponse getUserProfilePhotos(Integer userId, Integer offset, Integer limit) {
216+
GetUserProfilePhotos request = new GetUserProfilePhotos(userId);
217+
if (offset != null) request.offset(offset);
218+
if (limit != null) request.limit(limit);
219+
return execute(request);
220+
}
221+
222+
@Deprecated
223+
public GetUpdatesResponse getUpdates(Integer offset, Integer limit, Integer timeout) {
224+
GetUpdates request = new GetUpdates();
225+
if (offset != null) request.offset(offset);
226+
if (limit != null) request.limit(limit);
227+
if (timeout != null) request.timeout(timeout);
228+
return execute(request);
229+
}
230+
231+
@Deprecated
232+
public BaseResponse setWebhook(String url) {
233+
SetWebhook request = new SetWebhook();
234+
if (url != null) request.url(url);
235+
return execute(request);
236+
}
237+
238+
@Deprecated
239+
public BaseResponse setWebhook(String url, InputFile certificate) {
240+
SetWebhook request = new SetWebhook();
241+
if (url != null) request.url(url);
242+
if (certificate != null) request.certificate(certificate.getFile());
243+
return execute(request);
244+
}
245+
246+
@Deprecated
247+
public BaseResponse setWebhook(String url, InputFileBytes certificate) {
248+
SetWebhook request = new SetWebhook();
249+
if (url != null) request.url(url);
250+
if (certificate != null) request.certificate(certificate.getBytes());
251+
return execute(request);
252+
}
253+
254+
@Deprecated
255+
public BaseResponse answerInlineQuery(String inlineQueryId, InlineQueryResult... results) {
256+
return answerInlineQuery(inlineQueryId, results, null, null, null);
257+
}
258+
259+
@Deprecated
260+
public BaseResponse answerInlineQuery(String inlineQueryId, InlineQueryResult[] results, Integer cacheTime, Boolean isPersonal, String nextOffset) {
261+
AnswerInlineQuery request = new AnswerInlineQuery(inlineQueryId, results);
262+
if (cacheTime != null) request.cacheTime(cacheTime);
263+
if (isPersonal != null) request.isPersonal(isPersonal);
264+
if (nextOffset != null) request.nextOffset(nextOffset);
265+
return execute(request);
266+
}
267+
268+
}

0 commit comments

Comments
 (0)