Deprecate old methods, overload setNew... methods with InputStream arguments

This commit is contained in:
antonu17 2016-06-04 10:15:55 +06:00
parent 7b6a376976
commit 65d82076c2
6 changed files with 157 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package org.telegram.telegrambots.api.methods.send;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
import java.io.File;
import java.io.InputStream;
/**
* @author Ruben Bermudez
@ -40,7 +41,9 @@ public class SendAudio {
private String title; ///< Optional. Title of sent audio
private boolean isNewAudio; ///< True to upload a new audio, false to use a fileId
private String audioName;
private File newAudioFile; ///< New audio file
private InputStream newAudioStream; ///< New audio stream
public SendAudio() {
super();
@ -80,6 +83,20 @@ public class SendAudio {
return this;
}
/**
* Use this method to set the audio to a new file
*
* @param audio Path to the new file in your server
* @param audioName Name of the file itself
*/
@Deprecated
public SendAudio setNewAudio(String audio, String audioName) {
this.audio = audio;
this.isNewAudio = true;
this.audioName = audioName;
return this;
}
/**
* Use this method to set the audio to a new file
*
@ -92,6 +109,12 @@ public class SendAudio {
return this;
}
public SendAudio setNewAudio(InputStream inputStream) {
this.isNewAudio = true;
this.newAudioStream = inputStream;
return this;
}
public Integer getReplayToMessageId() {
return replayToMessageId;
}
@ -146,10 +169,18 @@ public class SendAudio {
return isNewAudio;
}
public String getAudioName() {
return audioName;
}
public File getNewAudioFile() {
return newAudioFile;
}
public InputStream getNewAudioStream() {
return newAudioStream;
}
@Override
public String toString() {
return "SendAudio{" +

View File

@ -3,6 +3,7 @@ package org.telegram.telegrambots.api.methods.send;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
import java.io.File;
import java.io.InputStream;
/**
* @author Ruben Bermudez
@ -31,7 +32,9 @@ public class SendDocument {
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private boolean isNewDocument; ///< True to upload a new document, false to use a fileId
private String documentName;
private File newDocumentFile; ///< New document file
private InputStream newDocumentStream; ///< New document stream
public SendDocument() {
super();
@ -56,6 +59,14 @@ public class SendDocument {
return this;
}
@Deprecated
public SendDocument setNewDocument(String document, String documentName) {
this.document = document;
this.isNewDocument = true;
this.documentName = documentName;
return this;
}
public SendDocument setNewDocument(File file) {
this.document = file.getName();
this.isNewDocument = true;
@ -63,14 +74,28 @@ public class SendDocument {
return this;
}
public SendDocument setNewDocument(InputStream inputStream) {
this.isNewDocument = true;
this.newDocumentStream = inputStream;
return this;
}
public boolean isNewDocument() {
return isNewDocument;
}
public String getDocumentName() {
return documentName;
}
public File getNewDocumentFile() {
return newDocumentFile;
}
public InputStream getNewDocumentStream() {
return newDocumentStream;
}
public Integer getReplayToMessageId() {
return replayToMessageId;
}

View File

@ -3,6 +3,7 @@ package org.telegram.telegrambots.api.methods.send;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
import java.io.File;
import java.io.InputStream;
/**
* @author Ruben Bermudez
@ -31,8 +32,9 @@ public class SendPhoto {
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private boolean isNewPhoto; ///< True if the photo must be uploaded from a file, file if it is a fileId
private String photoName; ///< Name of the photo
private File newPhotoFile; // New photo file
private InputStream newPhotoStream; // New photo stream
public SendPhoto() {
super();
@ -88,10 +90,18 @@ public class SendPhoto {
return isNewPhoto;
}
public String getPhotoName() {
return photoName;
}
public File getNewPhotoFile() {
return newPhotoFile;
}
public InputStream getNewPhotoStream() {
return newPhotoStream;
}
public Boolean getDisableNotification() {
return disableNotification;
}
@ -106,6 +116,14 @@ public class SendPhoto {
return this;
}
@Deprecated
public SendPhoto setNewPhoto(String photo, String photoName) {
this.photo = photo;
this.isNewPhoto = true;
this.photoName = photoName;
return this;
}
public SendPhoto setNewPhoto(File file) {
this.photo = file.getName();
this.newPhotoFile = file;
@ -113,6 +131,12 @@ public class SendPhoto {
return this;
}
public SendPhoto setNewPhoto(InputStream inputStream) {
this.newPhotoStream = inputStream;
this.isNewPhoto = true;
return this;
}
@Override
public String toString() {
return "SendPhoto{" +

View File

@ -3,6 +3,7 @@ package org.telegram.telegrambots.api.methods.send;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
import java.io.File;
import java.io.InputStream;
/**
* @author Ruben Bermudez
@ -29,7 +30,9 @@ public class SendSticker {
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private boolean isNewSticker; ///< True to upload a new sticker, false to use a fileId
private String stickerName;
private File newStickerFile; ///< New sticker file
private InputStream newStickerStream; ///< New sticker stream
public SendSticker() {
super();
@ -72,13 +75,27 @@ public class SendSticker {
return this;
}
public SendSticker setSticker(File file) {
@Deprecated
public SendSticker setSticker(String sticker, String stickerName) {
this.sticker = sticker;
this.isNewSticker = true;
this.stickerName = stickerName;
return this;
}
public SendSticker setNewSticker(File file) {
this.sticker = file.getName();
this.isNewSticker = true;
this.newStickerFile = file;
return this;
}
public SendSticker setNewSticker(InputStream inputStream) {
this.isNewSticker = true;
this.newStickerStream = inputStream;
return this;
}
public Boolean getDisableNotification() {
return disableNotification;
}
@ -97,10 +114,18 @@ public class SendSticker {
return isNewSticker;
}
public String getStickerName() {
return stickerName;
}
public File getNewStickerFile() {
return newStickerFile;
}
public InputStream getNewStickerStream() {
return newStickerStream;
}
@Override
public String toString() {
return "SendSticker{" +

View File

@ -3,6 +3,7 @@ package org.telegram.telegrambots.api.methods.send;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
import java.io.File;
import java.io.InputStream;
/**
* @author Ruben Bermudez
@ -38,7 +39,9 @@ public class SendVideo {
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
private boolean isNewVideo; ///< True to upload a new video, false to use a fileId
private String videoName; ///< Name of the video
private File newVideoFile; ///< New video file
private InputStream newVideoStream; ///< New video stream
public SendVideo() {
super();
@ -103,10 +106,18 @@ public class SendVideo {
return isNewVideo;
}
public String getVideoName() {
return videoName;
}
public File getNewVideoFile() {
return newVideoFile;
}
public InputStream getNewVideoStream() {
return newVideoStream;
}
public Boolean getDisableNotification() {
return disableNotification;
}
@ -139,6 +150,14 @@ public class SendVideo {
return this;
}
@Deprecated
public SendVideo setNewVideo(String video, String videoName) {
this.video = video;
this.isNewVideo = true;
this.videoName = videoName;
return this;
}
public SendVideo setNewVideo(File file) {
this.video = file.getName();
this.isNewVideo = true;
@ -146,6 +165,12 @@ public class SendVideo {
return this;
}
public SendVideo setNewVideo(InputStream inputStream) {
this.isNewVideo = true;
this.newVideoStream = inputStream;
return this;
}
@Override
public String toString() {
return "SendVideo{" +

View File

@ -3,6 +3,7 @@ package org.telegram.telegrambots.api.methods.send;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
import java.io.File;
import java.io.InputStream;
/**
* @author Ruben Bermudez
@ -33,7 +34,9 @@ public class SendVoice {
private Integer duration; ///< Optional. Duration of sent audio in seconds
private boolean isNewVoice; ///< True to upload a new voice note, false to use a fileId
private String voiceName; ///< Name of the voice note
private File newVoiceFile; ///< New voice note file
private InputStream newVoiceStream; ///< New voice note stream
public SendVoice() {
super();
@ -83,6 +86,14 @@ public class SendVoice {
return this;
}
@Deprecated
public SendVoice setNewAudio(String audio, String audioName) {
this.audio = audio;
this.isNewVoice = false;
this.voiceName = audioName;
return this;
}
public SendVoice setNewAudio(File file) {
this.audio = file.getName();
this.isNewVoice = true;
@ -90,6 +101,12 @@ public class SendVoice {
return this;
}
public SendVoice setNewAudio(InputStream inputStream) {
this.isNewVoice = true;
this.newVoiceStream = inputStream;
return this;
}
public Integer getReplayToMessageId() {
return replayToMessageId;
}
@ -121,7 +138,15 @@ public class SendVoice {
return isNewVoice;
}
public String getVoiceName() {
return voiceName;
}
public File getNewVoiceFile() {
return newVoiceFile;
}
public InputStream getNewVoiceStream() {
return newVoiceStream;
}
}