-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new methods for working with stickers: getStickerSet, uploadSti…
…ckerFile, createNewStickerSet, addStickerToSet, setStickerPositionInSet, and deleteStickerFromSet
- Loading branch information
Showing
17 changed files
with
251 additions
and
23 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
library/src/main/java/com/pengrad/telegrambot/request/AbstractUploadRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.pengrad.telegrambot.request; | ||
|
||
import com.pengrad.telegrambot.response.BaseResponse; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Stas Parshin | ||
* 23 July 2017 | ||
*/ | ||
abstract public class AbstractUploadRequest<T extends BaseRequest, R extends BaseResponse> extends BaseRequest<T, R> { | ||
|
||
private final boolean isMultipart; | ||
|
||
public AbstractUploadRequest(Class<? extends R> responseClass, String paramName, Object data) { | ||
super(responseClass); | ||
if (data instanceof String) { | ||
isMultipart = false; | ||
} else if (data instanceof File) { | ||
isMultipart = true; | ||
} else if (data instanceof byte[]) { | ||
isMultipart = true; | ||
} else { | ||
throw new IllegalArgumentException("Sending data should be String, File or byte[]"); | ||
} | ||
add(paramName, data); | ||
} | ||
|
||
@Override | ||
public boolean isMultipart() { | ||
return isMultipart; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
library/src/main/java/com/pengrad/telegrambot/request/AddStickerToSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.pengrad.telegrambot.request; | ||
|
||
import com.pengrad.telegrambot.response.BaseResponse; | ||
|
||
/** | ||
* Stas Parshin | ||
* 23 July 2017 | ||
*/ | ||
public class AddStickerToSet extends AbstractUploadRequest<AddStickerToSet, BaseResponse> { | ||
|
||
public AddStickerToSet(Integer userId, String name, Object pngSticker, String emojis) { | ||
super(BaseResponse.class, "png_sticker", pngSticker); | ||
add("user_id", userId); | ||
add("name", name); | ||
add("emojis", emojis); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
library/src/main/java/com/pengrad/telegrambot/request/CreateNewStickerSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.pengrad.telegrambot.request; | ||
|
||
import com.pengrad.telegrambot.model.MaskPosition; | ||
import com.pengrad.telegrambot.response.BaseResponse; | ||
|
||
/** | ||
* Stas Parshin | ||
* 23 July 2017 | ||
*/ | ||
public class CreateNewStickerSet extends AbstractUploadRequest<CreateNewStickerSet, BaseResponse> { | ||
|
||
public CreateNewStickerSet(Integer userId, String name, String title, Object pngSticker, String emojis) { | ||
super(BaseResponse.class, "png_sticker", pngSticker); | ||
add("user_id", userId); | ||
add("name", name); | ||
add("title", title); | ||
add("emojis", emojis); | ||
} | ||
|
||
public CreateNewStickerSet containsMasks(boolean containsMasks) { | ||
return add("contains_masks", containsMasks); | ||
} | ||
|
||
public CreateNewStickerSet maskPosition(MaskPosition maskPosition) { | ||
return add("mask_position", serialize(maskPosition)).containsMasks(true); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
library/src/main/java/com/pengrad/telegrambot/request/DeleteStickerFromSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.pengrad.telegrambot.request; | ||
|
||
import com.pengrad.telegrambot.response.BaseResponse; | ||
|
||
/** | ||
* Stas Parshin | ||
* 23 July 2017 | ||
*/ | ||
public class DeleteStickerFromSet extends BaseRequest<DeleteStickerFromSet, BaseResponse> { | ||
public DeleteStickerFromSet(String sticker) { | ||
super(BaseResponse.class); | ||
add("sticker", sticker); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
library/src/main/java/com/pengrad/telegrambot/request/GetStickerSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.pengrad.telegrambot.request; | ||
|
||
import com.pengrad.telegrambot.response.GetStickerSetResponse; | ||
|
||
/** | ||
* Stas Parshin | ||
* 23 July 2017 | ||
*/ | ||
public class GetStickerSet extends BaseRequest<GetStickerSet, GetStickerSetResponse> { | ||
|
||
public GetStickerSet(String name) { | ||
super(GetStickerSetResponse.class); | ||
add("name", name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
library/src/main/java/com/pengrad/telegrambot/request/SetStickerPositionInSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.pengrad.telegrambot.request; | ||
|
||
import com.pengrad.telegrambot.response.BaseResponse; | ||
|
||
/** | ||
* Stas Parshin | ||
* 23 July 2017 | ||
*/ | ||
public class SetStickerPositionInSet extends BaseRequest<SetStickerPositionInSet, BaseResponse> { | ||
|
||
public SetStickerPositionInSet(String sticker, int position) { | ||
super(BaseResponse.class); | ||
add("sticker", sticker).add("position", position); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
library/src/main/java/com/pengrad/telegrambot/request/UploadStickerFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.pengrad.telegrambot.request; | ||
|
||
import com.pengrad.telegrambot.response.GetFileResponse; | ||
|
||
/** | ||
* Stas Parshin | ||
* 23 July 2017 | ||
*/ | ||
public class UploadStickerFile extends AbstractUploadRequest<UploadStickerFile, GetFileResponse> { | ||
|
||
public UploadStickerFile(Integer userId, Object pngSticker) { | ||
super(GetFileResponse.class, "png_sticker", pngSticker); | ||
add("user_id", userId); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
library/src/main/java/com/pengrad/telegrambot/response/GetStickerSetResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.pengrad.telegrambot.response; | ||
|
||
import com.pengrad.telegrambot.model.StickerSet; | ||
|
||
/** | ||
* Stas Parshin | ||
* 23 July 2017 | ||
*/ | ||
public class GetStickerSetResponse extends BaseResponse { | ||
|
||
private StickerSet result; | ||
|
||
public StickerSet stickerSet() { | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "GetStickerSetResponse{" + | ||
"result=" + result + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.