Skip to content

Commit

Permalink
Merge pull request #94 from yvasyliev/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
yvasyliev committed Mar 6, 2022
2 parents 0d68f1d + 100d71e commit 1e26313
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 141 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This library uses the next third-party dependencies:
<dependency>
<groupId>com.github.yvasyliev</groupId>
<artifactId>java-vk-bots-longpoll-api</artifactId>
<version>3.2.6</version>
<version>3.2.7</version>
</dependency>
```
4. Extend `LongPollBot` class and override necessary methods:
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.github.yvasyliev</groupId>
<artifactId>java-vk-bots-longpoll-api</artifactId>
<packaging>jar</packaging>
<version>3.2.6</version>
<version>3.2.7</version>
<name>Java VK Bots Long Poll API</name>
<description>A Java library to create VK bots using Bots Long Poll API</description>
<url>https://github.com/yvasyliev/java-vk-bots-long-poll-api</url>
Expand All @@ -29,12 +29,12 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.35</version>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/api/longpoll/bots/LongPollBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class LongPollBot extends VkBot {
/**
* Gets VK long poll server.
*/
private final GetLongPollServer getLongPollServer = new GetLongPollServer(getAccessToken());
private GetLongPollServer getLongPollServer;

/**
* Gets VK updates.
Expand All @@ -51,6 +51,10 @@ public void startPolling() throws VkApiException {
.getId();
}

if (getLongPollServer == null) {
getLongPollServer = new GetLongPollServer(getAccessToken());
}

resetGetUpdates();
while (polling) {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/api/longpoll/bots/VkBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public abstract class VkBot {
/**
* VK Bots API methods.
*/
protected VkBotsMethods vk = new VkBotsMethods(getAccessToken());
protected VkBotsMethods vk = new VkBotsMethods(this::getAccessToken);

/**
* Gets bot access token.
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/api/longpoll/bots/methods/BoardMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
import api.longpoll.bots.methods.impl.board.DeleteComment;
import api.longpoll.bots.methods.impl.board.RestoreComment;

import java.util.function.Supplier;

/**
* Provides Board methods.
*/
public class BoardMethods {
/**
* Access token.
*/
private final String accessToken;
private final Supplier<String> accessTokenSupplier;

public BoardMethods(String accessToken) {
this.accessToken = accessToken;
public BoardMethods(Supplier<String> accessTokenSupplier) {
this.accessTokenSupplier = accessTokenSupplier;
}

public DeleteComment deleteComment() {
return new DeleteComment(accessToken);
return new DeleteComment(accessTokenSupplier.get());
}

public RestoreComment restoreComment() {
return new RestoreComment(accessToken);
return new RestoreComment(accessTokenSupplier.get());
}
}
16 changes: 9 additions & 7 deletions src/main/java/api/longpoll/bots/methods/DocsMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,34 @@
import api.longpoll.bots.methods.impl.docs.Save;
import api.longpoll.bots.methods.impl.docs.Search;

import java.util.function.Supplier;

/**
* Provides Docs methods.
*/
public class DocsMethods {
/**
* Access token.
*/
private final String accessToken;
private final Supplier<String> accessTokenSupplier;

public DocsMethods(String accessToken) {
this.accessToken = accessToken;
public DocsMethods(Supplier<String> accessTokenSupplier) {
this.accessTokenSupplier = accessTokenSupplier;
}

public GetMessagesUploadServer getMessagesUploadServer() {
return new GetMessagesUploadServer(accessToken);
return new GetMessagesUploadServer(accessTokenSupplier.get());
}

public GetWallUploadServer getWallUploadServer() {
return new GetWallUploadServer(accessToken);
return new GetWallUploadServer(accessTokenSupplier.get());
}

public Save save() {
return new Save(accessToken);
return new Save(accessTokenSupplier.get());
}

public Search search() {
return new Search(accessToken);
return new Search(accessTokenSupplier.get());
}
}
52 changes: 27 additions & 25 deletions src/main/java/api/longpoll/bots/methods/GroupsMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,104 +23,106 @@
import api.longpoll.bots.methods.impl.groups.SetLongPollSettings;
import api.longpoll.bots.methods.impl.groups.SetSettings;

import java.util.function.Supplier;

/**
* Provides Groups methods.
*/
public class GroupsMethods {
/**
* Access token.
*/
private final String accessToken;
private final Supplier<String> accessTokenSupplier;

public GroupsMethods(String accessToken) {
this.accessToken = accessToken;
public GroupsMethods(Supplier<String> accessTokenSupplier) {
this.accessTokenSupplier = accessTokenSupplier;
}

public AddAddress addAddress() {
return new AddAddress(accessToken);
return new AddAddress(accessTokenSupplier.get());
}

public AddCallbackServer addCallbackServer() {
return new AddCallbackServer(accessToken);
return new AddCallbackServer(accessTokenSupplier.get());
}

public DeleteAddress deleteAddress() {
return new DeleteAddress(accessToken);
return new DeleteAddress(accessTokenSupplier.get());
}

public DeleteCallbackServer deleteCallbackServer() {
return new DeleteCallbackServer(accessToken);
return new DeleteCallbackServer(accessTokenSupplier.get());
}

public DisableOnline disableOnline() {
return new DisableOnline(accessToken);
return new DisableOnline(accessTokenSupplier.get());
}

public EditAddress editAddress() {
return new EditAddress(accessToken);
return new EditAddress(accessTokenSupplier.get());
}

public EditCallbackServer editCallbackServer() {
return new EditCallbackServer(accessToken);
return new EditCallbackServer(accessTokenSupplier.get());
}

public EnableOnline enableOnline() {
return new EnableOnline(accessToken);
return new EnableOnline(accessTokenSupplier.get());
}

public GetBanned getBanned() {
return new GetBanned(accessToken);
return new GetBanned(accessTokenSupplier.get());
}

public GetById getById() {
return new GetById(accessToken);
return new GetById(accessTokenSupplier.get());
}

public GetCallbackConfirmationCode getCallbackConfirmationCode() {
return new GetCallbackConfirmationCode(accessToken);
return new GetCallbackConfirmationCode(accessTokenSupplier.get());
}

public GetCallbackServers getCallbackServers() {
return new GetCallbackServers(accessToken);
return new GetCallbackServers(accessTokenSupplier.get());
}

public GetCallbackSettings getCallbackSettings() {
return new GetCallbackSettings(accessToken);
return new GetCallbackSettings(accessTokenSupplier.get());
}

public GetLongPollServer getLongPollServer() {
return new GetLongPollServer(accessToken);
return new GetLongPollServer(accessTokenSupplier.get());
}

public GetLongPollSettings getLongPollSettings() {
return new GetLongPollSettings(accessToken);
return new GetLongPollSettings(accessTokenSupplier.get());
}

public GetMembers getMembers() {
return new GetMembers(accessToken);
return new GetMembers(accessTokenSupplier.get());
}

public GetOnlineStatus getOnlineStatus() {
return new GetOnlineStatus(accessToken);
return new GetOnlineStatus(accessTokenSupplier.get());
}

public GetTokenPermissions getTokenPermissions() {
return new GetTokenPermissions(accessToken);
return new GetTokenPermissions(accessTokenSupplier.get());
}

public IsMember isMember() {
return new IsMember(accessToken);
return new IsMember(accessTokenSupplier.get());
}

public SetCallbackSettings setCallbackSettings() {
return new SetCallbackSettings(accessToken);
return new SetCallbackSettings(accessTokenSupplier.get());
}

public SetLongPollSettings setLongPollSettings() {
return new SetLongPollSettings(accessToken);
return new SetLongPollSettings(accessTokenSupplier.get());
}

public SetSettings setSettings() {
return new SetSettings(accessToken);
return new SetSettings(accessTokenSupplier.get());
}
}
16 changes: 9 additions & 7 deletions src/main/java/api/longpoll/bots/methods/MarketMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,34 @@
import api.longpoll.bots.methods.impl.market.GetOrderById;
import api.longpoll.bots.methods.impl.market.GetOrderItems;

import java.util.function.Supplier;

/**
* Provides Market methods.
*/
public class MarketMethods {
/**
* Access token.
*/
private final String accessToken;
private final Supplier<String> accessTokenSupplier;

public MarketMethods(String accessToken) {
this.accessToken = accessToken;
public MarketMethods(Supplier<String> accessTokenSupplier) {
this.accessTokenSupplier = accessTokenSupplier;
}

public EditOrder editOrder() {
return new EditOrder(accessToken);
return new EditOrder(accessTokenSupplier.get());
}

public GetGroupOrders getGroupOrders() {
return new GetGroupOrders(accessToken);
return new GetGroupOrders(accessTokenSupplier.get());
}

public GetOrderById getOrderById() {
return new GetOrderById(accessToken);
return new GetOrderById(accessTokenSupplier.get());
}

public GetOrderItems getOrderItems() {
return new GetOrderItems(accessToken);
return new GetOrderItems(accessTokenSupplier.get());
}
}
Loading

0 comments on commit 1e26313

Please sign in to comment.