Skip to content

Commit 8bb70c7

Browse files
authored
Merge pull request #131 from yvasyliev/dev
Fixed #130
2 parents 60d6669 + 2888802 commit 8bb70c7

File tree

6 files changed

+105
-4
lines changed

6 files changed

+105
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This library uses the next third-party dependencies:
3131
<dependency>
3232
<groupId>com.github.yvasyliev</groupId>
3333
<artifactId>java-vk-bots-longpoll-api</artifactId>
34-
<version>3.4.6</version>
34+
<version>3.4.7</version>
3535
</dependency>
3636
```
3737
4. Extend `LongPollBot` class and override necessary methods:

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>com.github.yvasyliev</groupId>
77
<artifactId>java-vk-bots-longpoll-api</artifactId>
88
<packaging>jar</packaging>
9-
<version>3.4.6</version>
9+
<version>3.4.7</version>
1010
<name>Java VK Bots Long Poll API</name>
1111
<description>A Java library to create VK bots using Bots Long Poll API</description>
1212
<url>https://github.com/yvasyliev/java-vk-bots-long-poll-api</url>
@@ -39,7 +39,7 @@
3939
<dependency>
4040
<groupId>org.apache.logging.log4j</groupId>
4141
<artifactId>log4j-slf4j-impl</artifactId>
42-
<version>2.18.0</version>
42+
<version>2.19.0</version>
4343
<scope>test</scope>
4444
</dependency>
4545
<dependency>

src/main/java/api/longpoll/bots/VkBot.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import api.longpoll.bots.model.events.other.VkpayTransaction;
1515
import api.longpoll.bots.model.events.photos.PhotoComment;
1616
import api.longpoll.bots.model.events.photos.PhotoCommentDelete;
17+
import api.longpoll.bots.model.events.poll.PollVoteNew;
1718
import api.longpoll.bots.model.events.users.GroupJoin;
1819
import api.longpoll.bots.model.events.users.GroupLeave;
1920
import api.longpoll.bots.model.events.users.UserBlock;
@@ -239,6 +240,10 @@ public void handle(List<Update> updates) {
239240
onMessageDeny((MessageDeny) update.getObject());
240241
break;
241242

243+
case POLL_VOTE_NEW:
244+
onPollVoteNew((PollVoteNew) update.getObject());
245+
break;
246+
242247
default:
243248
LOGGER.warn("No update handler found update updateType: {}", updateType);
244249
break;
@@ -597,4 +602,12 @@ public void onMessageAllow(MessageAllow messageAllow) {
597602
*/
598603
public void onMessageDeny(MessageDeny messageDeny) {
599604
}
605+
606+
/**
607+
* Handles <b>poll_vote_new</b> events.
608+
*
609+
* @param pollVoteNew event object.
610+
*/
611+
public void onPollVoteNew(PollVoteNew pollVoteNew) {
612+
}
600613
}

src/main/java/api/longpoll/bots/adapters/deserializers/UpdateDeserializer.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import api.longpoll.bots.model.events.other.VkpayTransaction;
1818
import api.longpoll.bots.model.events.photos.PhotoComment;
1919
import api.longpoll.bots.model.events.photos.PhotoCommentDelete;
20+
import api.longpoll.bots.model.events.poll.PollVoteNew;
2021
import api.longpoll.bots.model.events.users.GroupJoin;
2122
import api.longpoll.bots.model.events.users.GroupLeave;
2223
import api.longpoll.bots.model.events.users.UserBlock;
@@ -31,6 +32,7 @@
3132
import api.longpoll.bots.model.objects.media.Audio;
3233
import api.longpoll.bots.model.objects.media.Photo;
3334
import api.longpoll.bots.model.objects.media.Video;
35+
import com.google.gson.Gson;
3436
import com.google.gson.JsonDeserializationContext;
3537
import com.google.gson.JsonDeserializer;
3638
import com.google.gson.JsonElement;
@@ -43,12 +45,19 @@
4345
* Deserializes JSON objects to {@link Update}.
4446
*/
4547
public class UpdateDeserializer implements JsonDeserializer<Update> {
48+
private final Gson gson = new Gson();
49+
4650
@Override
4751
public final Update deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
4852
JsonObject jsonUpdate = jsonElement.getAsJsonObject();
4953

5054
Update update = new Update();
5155
update.setType(context.deserialize(jsonUpdate.get("type"), Update.Type.class));
56+
57+
if (update.getType() == null) {
58+
throw new IllegalArgumentException("Cannot deserialize '" + jsonUpdate.get("type") + "'. JSON: " + gson.toJson(jsonElement));
59+
}
60+
5261
update.setGroupId(jsonUpdate.get("group_id").getAsInt());
5362
update.setEventId(jsonUpdate.get("event_id").getAsString());
5463
update.setObject(context.deserialize(jsonUpdate.get("object"), getObjectClass(update.getType())));
@@ -131,6 +140,9 @@ private Class<? extends Update.Object> getObjectClass(Update.Type type) {
131140
case PHOTO_NEW:
132141
return Photo.class;
133142

143+
case POLL_VOTE_NEW:
144+
return PollVoteNew.class;
145+
134146
case USER_BLOCK:
135147
return UserBlock.class;
136148

@@ -166,7 +178,7 @@ private Class<? extends Update.Object> getObjectClass(Update.Type type) {
166178
return VkpayTransaction.class;
167179

168180
default:
169-
throw new RuntimeException("Update type '" + type + "' is not handled.");
181+
throw new IllegalArgumentException("Update type '" + type + "' is not handled.");
170182
}
171183
}
172184
}

src/main/java/api/longpoll/bots/model/events/Update.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public enum Type {
111111
@SerializedName("photo_comment_new") PHOTO_COMMENT_NEW,
112112
@SerializedName("photo_comment_restore") PHOTO_COMMENT_RESTORE,
113113
@SerializedName("photo_new") PHOTO_NEW,
114+
@SerializedName("poll_vote_new") POLL_VOTE_NEW,
114115
@SerializedName("user_block") USER_BLOCK,
115116
@SerializedName("user_unblock") USER_UNBLOCK,
116117
@SerializedName("video_comment_delete") VIDEO_COMMENT_DELETE,
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package api.longpoll.bots.model.events.poll;
2+
3+
import api.longpoll.bots.model.events.Update;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
/**
7+
* A new vote in a public poll.
8+
*/
9+
public class PollVoteNew implements Update.Object {
10+
/**
11+
* Poll owner ID.
12+
*/
13+
@SerializedName("owner_id")
14+
private Integer ownerId;
15+
16+
/**
17+
* Poll ID.
18+
*/
19+
@SerializedName("poll_id")
20+
private Integer pollId;
21+
22+
/**
23+
* Poll option ID.
24+
*/
25+
@SerializedName("option_id")
26+
private Integer optionId;
27+
28+
/**
29+
* User ID.
30+
*/
31+
@SerializedName("user_id")
32+
private Integer userId;
33+
34+
public Integer getOwnerId() {
35+
return ownerId;
36+
}
37+
38+
public void setOwnerId(Integer ownerId) {
39+
this.ownerId = ownerId;
40+
}
41+
42+
public Integer getPollId() {
43+
return pollId;
44+
}
45+
46+
public void setPollId(Integer pollId) {
47+
this.pollId = pollId;
48+
}
49+
50+
public Integer getOptionId() {
51+
return optionId;
52+
}
53+
54+
public void setOptionId(Integer optionId) {
55+
this.optionId = optionId;
56+
}
57+
58+
public Integer getUserId() {
59+
return userId;
60+
}
61+
62+
public void setUserId(Integer userId) {
63+
this.userId = userId;
64+
}
65+
66+
@Override
67+
public String toString() {
68+
return "PollVoteNew{" +
69+
"ownerId=" + ownerId +
70+
", pollId=" + pollId +
71+
", optionId=" + optionId +
72+
", userId=" + userId +
73+
'}';
74+
}
75+
}

0 commit comments

Comments
 (0)