Skip to content

Commit 8f4baba

Browse files
authored
Merge pull request #134 from yvasyliev/dev
Dev
2 parents bee0fb7 + 853ebdd commit 8f4baba

File tree

7 files changed

+87
-71
lines changed

7 files changed

+87
-71
lines changed

README.md

Lines changed: 3 additions & 3 deletions
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.7</version>
34+
<version>3.5.0</version>
3535
</dependency>
3636
```
3737
4. Extend `LongPollBot` class and override necessary methods:
@@ -86,7 +86,7 @@ Find more examples of bot usage [here](https://github.com/yvasyliev/java-vk-bots
8686
## Async execution
8787
Each API method can be executed asynchronously:
8888
```java
89-
CompletableFuture<Send.Response> future = vk.messages.send()
89+
CompletableFuture<Send.ResponseBody> future = vk.messages.send()
9090
.setPeerId(peerId)
9191
.setMessage("Sending message asynchronously...")
9292
.executeAsync();
@@ -126,6 +126,7 @@ CompletableFuture<Send.Response> future = vk.messages.send()
126126
| `photo_comment_new` | `public void onPhotoCommentNew(PhotoComment photoComment)` |
127127
| `photo_comment_restore` | `public void onPhotoCommentRestore(PhotoComment photoComment)` |
128128
| `photo_comment_new` | `public void onPhotoNew(Photo photo)` |
129+
| `poll_vote_new` | `public void onPollVoteNew(PollVoteNew pollVoteNew)` |
129130
| `user_block` | `public void onUserBlock(UserBlock userBlock)` |
130131
| `user_unblock` | `public void onUserUnblock(UserUnblock userUnblock)` |
131132
| `video_comment_delete` | `public void onVideoCommentDelete(VideoCommentDelete videoCommentDelete)` |
@@ -140,7 +141,6 @@ CompletableFuture<Send.Response> future = vk.messages.send()
140141
| `wall_reply_new` | `public void onWallReplyNew(WallReply wallReply)` |
141142
| `wall_reply_restore` | `public void onWallReplyRestore(WallReply wallReply)` |
142143
| `wall_repost` | `public void onWallRepost(WallPost wallPost)` |
143-
| `poll_vote_new` | `public void onPollVoteNew(PollVoteNew pollVoteNew)` |
144144

145145
## Logging
146146
This library uses `SLF4J` API to log all events. You can add any `SLF4J` binding to your project to register events the way you want.

pom.xml

Lines changed: 19 additions & 20 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.7</version>
9+
<version>3.5.0</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>
@@ -34,18 +34,24 @@
3434
<dependency>
3535
<groupId>org.slf4j</groupId>
3636
<artifactId>slf4j-api</artifactId>
37-
<version>1.7.36</version>
37+
<version>2.0.3</version>
3838
</dependency>
3939
<dependency>
4040
<groupId>org.apache.logging.log4j</groupId>
41-
<artifactId>log4j-slf4j-impl</artifactId>
41+
<artifactId>log4j-slf4j2-impl</artifactId>
42+
<version>2.19.0</version>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.apache.logging.log4j</groupId>
47+
<artifactId>log4j-core</artifactId>
4248
<version>2.19.0</version>
4349
<scope>test</scope>
4450
</dependency>
4551
<dependency>
4652
<groupId>org.junit.jupiter</groupId>
4753
<artifactId>junit-jupiter-engine</artifactId>
48-
<version>5.9.0</version>
54+
<version>5.9.1</version>
4955
<scope>test</scope>
5056
</dependency>
5157
</dependencies>
@@ -67,17 +73,17 @@
6773
<plugin>
6874
<groupId>org.apache.maven.plugins</groupId>
6975
<artifactId>maven-resources-plugin</artifactId>
70-
<version>3.0.1</version>
76+
<version>3.3.0</version>
7177
</plugin>
7278
<plugin>
7379
<groupId>org.apache.maven.plugins</groupId>
7480
<artifactId>maven-compiler-plugin</artifactId>
75-
<version>3.8.1</version>
81+
<version>3.10.1</version>
7682
</plugin>
7783
<plugin>
7884
<groupId>org.sonatype.plugins</groupId>
7985
<artifactId>nexus-staging-maven-plugin</artifactId>
80-
<version>1.6.7</version>
86+
<version>1.6.13</version>
8187
<extensions>true</extensions>
8288
<configuration>
8389
<serverId>ossrh</serverId>
@@ -88,7 +94,7 @@
8894
<plugin>
8995
<groupId>org.apache.maven.plugins</groupId>
9096
<artifactId>maven-release-plugin</artifactId>
91-
<version>3.0.0-M1</version>
97+
<version>3.0.0-M6</version>
9298
<configuration>
9399
<autoVersionSubmodules>true</autoVersionSubmodules>
94100
<useReleaseProfile>false</useReleaseProfile>
@@ -99,7 +105,7 @@
99105
<plugin>
100106
<groupId>org.apache.maven.plugins</groupId>
101107
<artifactId>maven-source-plugin</artifactId>
102-
<version>2.2.1</version>
108+
<version>3.2.1</version>
103109
<executions>
104110
<execution>
105111
<id>attach-sources</id>
@@ -112,7 +118,7 @@
112118
<plugin>
113119
<groupId>org.apache.maven.plugins</groupId>
114120
<artifactId>maven-javadoc-plugin</artifactId>
115-
<version>2.9.1</version>
121+
<version>3.4.1</version>
116122
<executions>
117123
<execution>
118124
<id>attach-javadocs</id>
@@ -125,7 +131,7 @@
125131
<plugin>
126132
<groupId>org.apache.maven.plugins</groupId>
127133
<artifactId>maven-gpg-plugin</artifactId>
128-
<version>1.5</version>
134+
<version>3.0.1</version>
129135
<executions>
130136
<execution>
131137
<id>sign-artifacts</id>
@@ -140,7 +146,7 @@
140146
<plugin>
141147
<groupId>org.apache.maven.plugins</groupId>
142148
<artifactId>maven-assembly-plugin</artifactId>
143-
<version>3.3.0</version>
149+
<version>3.4.2</version>
144150
<executions>
145151
<execution>
146152
<phase>package</phase>
@@ -183,14 +189,7 @@
183189
<plugin>
184190
<groupId>org.apache.maven.plugins</groupId>
185191
<artifactId>maven-surefire-plugin</artifactId>
186-
<version>2.19.1</version>
187-
<dependencies>
188-
<dependency>
189-
<groupId>org.junit.platform</groupId>
190-
<artifactId>junit-platform-surefire-provider</artifactId>
191-
<version>1.1.0</version>
192-
</dependency>
193-
</dependencies>
192+
<version>3.0.0-M7</version>
194193
</plugin>
195194
</plugins>
196195
<resources>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
* Deserializes JSON objects to {@link Update}.
4646
*/
4747
public class UpdateDeserializer implements JsonDeserializer<Update> {
48+
/**
49+
* {@link Gson} object.
50+
*/
4851
private final Gson gson = new Gson();
4952

5053
@Override
@@ -55,7 +58,7 @@ public final Update deserialize(JsonElement jsonElement, Type type, JsonDeserial
5558
update.setType(context.deserialize(jsonUpdate.get("type"), Update.Type.class));
5659

5760
if (update.getType() == null) {
58-
throw new IllegalArgumentException("Cannot deserialize '" + jsonUpdate.get("type") + "'. JSON: " + gson.toJson(jsonElement));
61+
throw new IllegalArgumentException("There is no mapping for event '" + jsonUpdate.get("type") + "'. JSON: " + gson.toJson(jsonElement));
5962
}
6063

6164
update.setGroupId(jsonUpdate.get("group_id").getAsInt());

src/main/java/api/longpoll/bots/helpers/attachments/UploadableMessageDoc.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,11 @@ public UploadedFile uploadFile(String filename, InputStream inputStream) throws
3939

4040
Save.ResponseBody savedFile = save.setFile(uploadedDoc.getFile()).execute();
4141
Doc doc = savedFile.getResponse().getDoc();
42-
return new UploadedFile() {
43-
@Override
44-
public String getType() {
45-
return "doc";
46-
}
47-
48-
@Override
49-
public int getOwnerId() {
50-
return doc.getOwnerId();
51-
}
52-
53-
@Override
54-
public int getMediaId() {
55-
return doc.getId();
56-
}
57-
58-
@Override
59-
public String getAccessKey() {
60-
return doc.getAccessKey();
61-
}
62-
};
42+
return new UploadedFile(
43+
"doc",
44+
doc.getOwnerId(),
45+
doc.getId(),
46+
doc.getAccessKey()
47+
);
6348
}
6449
}

src/main/java/api/longpoll/bots/helpers/attachments/UploadableMessagePhoto.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,11 @@ public UploadedFile uploadFile(String filename, InputStream inputStream) throws
4242
.setHash(uploadedPhoto.getHash())
4343
.execute();
4444
SaveMessagesPhoto.ResponseBody.Response photo = savedPhoto.getResponse().get(0);
45-
return new UploadedFile() {
46-
@Override
47-
public String getType() {
48-
return "photo";
49-
}
50-
51-
@Override
52-
public int getOwnerId() {
53-
return photo.getOwnerId();
54-
}
55-
56-
@Override
57-
public int getMediaId() {
58-
return photo.getId();
59-
}
60-
61-
@Override
62-
public String getAccessKey() {
63-
return photo.getAccessKey();
64-
}
65-
};
45+
return new UploadedFile(
46+
"photo",
47+
photo.getOwnerId(),
48+
photo.getId(),
49+
photo.getAccessKey()
50+
);
6651
}
6752
}

src/main/java/api/longpoll/bots/http/impl/PostRequest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ public RequestBody getRequestBody() {
8989
return requestBody;
9090
}
9191

92+
@Override
93+
public String toString() {
94+
return "PostRequest{" +
95+
"uri='" + uri + '\'' +
96+
", headers=" + headers +
97+
", requestBody=" + requestBody +
98+
'}';
99+
}
100+
92101
/**
93102
* PostRequest builder.
94103
*/

src/main/java/api/longpoll/bots/model/objects/additional/UploadedFile.java

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,69 @@
33
/**
44
* An uploaded to VK server file.
55
*/
6-
public abstract class UploadedFile {
6+
public class UploadedFile {
7+
/**
8+
* File type.
9+
*/
10+
private final String type;
11+
12+
/**
13+
* Owner ID.
14+
*/
15+
private final int ownerId;
16+
17+
/**
18+
* File ID.
19+
*/
20+
private final int mediaId;
21+
22+
/**
23+
* file <i>access_key</i>.
24+
*/
25+
private final String accessKey;
26+
27+
public UploadedFile(String type, int ownerId, int mediaId, String accessKey) {
28+
this.type = type;
29+
this.ownerId = ownerId;
30+
this.mediaId = mediaId;
31+
this.accessKey = accessKey;
32+
}
33+
734
/**
835
* Gets file type.
936
*
1037
* @return file type.
1138
*/
12-
public abstract String getType();
39+
public String getType() {
40+
return type;
41+
}
1342

1443
/**
1544
* Gets owner ID.
1645
*
1746
* @return owner ID.
1847
*/
19-
public abstract int getOwnerId();
48+
public int getOwnerId() {
49+
return ownerId;
50+
}
2051

2152
/**
2253
* Gets file ID.
2354
*
2455
* @return file ID.
2556
*/
26-
public abstract int getMediaId();
57+
public int getMediaId() {
58+
return mediaId;
59+
}
2760

2861
/**
2962
* Gets file <i>access_key</i>.
3063
*
3164
* @return file <i>access_key</i>.
3265
*/
33-
public abstract String getAccessKey();
66+
public String getAccessKey() {
67+
return accessKey;
68+
}
3469

3570
@Override
3671
public String toString() {

0 commit comments

Comments
 (0)