Skip to content

Commit b6b1e29

Browse files
authored
Merge pull request #145 from yvasyliev/OkHttp_migration
Magrated to OkHttp. Global refactoring.
2 parents 1d4b0f6 + d6aeb33 commit b6b1e29

File tree

151 files changed

+1090
-2055
lines changed

Some content is hidden

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

151 files changed

+1090
-2055
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.5.3</version>
34+
<version>4.0.0</version>
3535
</dependency>
3636
```
3737
4. Extend `LongPollBot` class and override necessary methods:

pom.xml

Lines changed: 11 additions & 6 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.5.4-beta-1</version>
9+
<version>4.0.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>
@@ -29,12 +29,17 @@
2929
<dependency>
3030
<groupId>com.google.code.gson</groupId>
3131
<artifactId>gson</artifactId>
32-
<version>2.10</version>
32+
<version>2.10.1</version>
3333
</dependency>
3434
<dependency>
3535
<groupId>org.slf4j</groupId>
3636
<artifactId>slf4j-api</artifactId>
37-
<version>2.0.3</version>
37+
<version>2.0.6</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.squareup.okhttp3</groupId>
41+
<artifactId>okhttp</artifactId>
42+
<version>4.10.0</version>
3843
</dependency>
3944
<dependency>
4045
<groupId>org.apache.logging.log4j</groupId>
@@ -51,7 +56,7 @@
5156
<dependency>
5257
<groupId>org.junit.jupiter</groupId>
5358
<artifactId>junit-jupiter-engine</artifactId>
54-
<version>5.9.1</version>
59+
<version>5.9.2</version>
5560
<scope>test</scope>
5661
</dependency>
5762
</dependencies>
@@ -94,7 +99,7 @@
9499
<plugin>
95100
<groupId>org.apache.maven.plugins</groupId>
96101
<artifactId>maven-release-plugin</artifactId>
97-
<version>3.0.0-M6</version>
102+
<version>3.0.0-M7</version>
98103
<configuration>
99104
<autoVersionSubmodules>true</autoVersionSubmodules>
100105
<useReleaseProfile>false</useReleaseProfile>
@@ -189,7 +194,7 @@
189194
<plugin>
190195
<groupId>org.apache.maven.plugins</groupId>
191196
<artifactId>maven-surefire-plugin</artifactId>
192-
<version>3.0.0-M7</version>
197+
<version>3.0.0-M8</version>
193198
</plugin>
194199
</plugins>
195200
<resources>

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package api.longpoll.bots;
22

33
import api.longpoll.bots.exceptions.VkApiException;
4-
import api.longpoll.bots.exceptions.VkApiHttpException;
5-
import api.longpoll.bots.exceptions.VkApiResponseException;
4+
import api.longpoll.bots.exceptions.VkResponseException;
65
import api.longpoll.bots.methods.impl.events.GetUpdates;
76
import api.longpoll.bots.methods.impl.groups.GetLongPollServer;
8-
import org.slf4j.Logger;
9-
import org.slf4j.LoggerFactory;
107

118
import java.time.LocalDateTime;
129
import java.time.temporal.ChronoUnit;
@@ -15,11 +12,6 @@
1512
* Abstract bot to handle VK events.
1613
*/
1714
public abstract class LongPollBot extends VkBot {
18-
/**
19-
* {@link Logger} object.
20-
*/
21-
private static final Logger LOGGER = LoggerFactory.getLogger(LongPollBot.class);
22-
2315
/**
2416
* Default session time.
2517
*
@@ -40,7 +32,7 @@ public abstract class LongPollBot extends VkBot {
4032
/**
4133
* Gets VK updates.
4234
*/
43-
private final GetUpdates getUpdates = new GetUpdates();
35+
private GetUpdates getUpdates;
4436

4537
/**
4638
* Whether infinite loop should be continued.
@@ -73,9 +65,8 @@ public void startPolling() throws VkApiException {
7365
GetUpdates.ResponseBody updates = getUpdates.execute();
7466
getUpdates.setTs(updates.getTs());
7567
handle(updates.getEvents());
76-
} catch (VkApiHttpException | VkApiResponseException e) {
77-
LOGGER.warn("Failed to get events from VK Long Poll Server.", e);
78-
if (e instanceof VkApiResponseException && !e.getMessage().contains("failed")) {
68+
} catch (VkResponseException e) {
69+
if (!e.getMessage().contains("failed")) {
7970
throw e;
8071
}
8172
initialize();
@@ -111,7 +102,7 @@ public void initialize() throws VkApiException {
111102
}
112103

113104
GetLongPollServer.ResponseBody longPollServer = getLongPollServer.setGroupId(groupId).execute();
114-
getUpdates.setServer(longPollServer.getResponse().getServer())
105+
getUpdates = new GetUpdates(longPollServer.getResponse().getServer())
115106
.setKey(longPollServer.getResponse().getKey())
116107
.setTs(longPollServer.getResponse().getTs());
117108
}

src/main/java/api/longpoll/bots/async/AsyncCaller.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/main/java/api/longpoll/bots/async/DefaultAsyncCaller.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/java/api/longpoll/bots/async/package-info.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/main/java/api/longpoll/bots/exceptions/VkApiHttpException.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/main/java/api/longpoll/bots/exceptions/VkApiResponseException.java

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package api.longpoll.bots.exceptions;
2+
3+
/**
4+
* Occurs when VK returns "error" of "failed" response.
5+
*/
6+
public class VkResponseException extends VkApiException {
7+
public VkResponseException(String message) {
8+
super(message);
9+
}
10+
}

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

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)