diff options
author | 2018-02-09 12:57:27 +0300 | |
---|---|---|
committer | 2018-02-09 12:57:27 +0300 | |
commit | eb8c9d95bfbd7e664c9de2767850ec4c465b520b (patch) | |
tree | f555c3ff83c0383920c64948128a2c6d3c5107fe /juick-server/src/main/java/com/juick/server/VKWallManager.java | |
parent | d85787b7aa2b8f41fe1579ea553a3ca86f0b3c98 (diff) |
vk top
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/VKWallManager.java')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/VKWallManager.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/server/VKWallManager.java b/juick-server/src/main/java/com/juick/server/VKWallManager.java new file mode 100644 index 00000000..364087eb --- /dev/null +++ b/juick-server/src/main/java/com/juick/server/VKWallManager.java @@ -0,0 +1,57 @@ +package com.juick.server; + +import com.juick.User; +import com.juick.service.CrosspostService; +import com.juick.service.UserService; +import com.vk.api.sdk.client.TransportClient; +import com.vk.api.sdk.client.VkApiClient; +import com.vk.api.sdk.client.actors.UserActor; +import com.vk.api.sdk.exceptions.ApiException; +import com.vk.api.sdk.exceptions.ClientException; +import com.vk.api.sdk.httpclient.HttpTransportClient; +import com.vk.api.sdk.objects.apps.responses.GetResponse; +import com.vk.api.sdk.objects.wall.responses.PostResponse; +import org.apache.commons.lang3.tuple.Pair; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +@Component +public class VKWallManager { + @Value("${vk_appid}") + private String VK_APPID; + @Value("${vk_secret}") + private String VK_SECRET; + @Inject + private UserService userService; + @Inject + private CrosspostService crosspostService; + @Value("${vk_user:juick}") + private String serviceUsername; + @Value("${vk_group:-1}") + private String vkGroup; + + private User serviceUser; + private VkApiClient vk; + private UserActor actor; + + + @PostConstruct + public void init() throws ClientException, ApiException { + serviceUser = userService.getUserByName(serviceUsername); + TransportClient transportClient = HttpTransportClient.getInstance(); + vk = new VkApiClient(transportClient); + Pair<String, String> tokens = crosspostService.getVkTokens(serviceUser.getUid()).get(); + actor = new UserActor(Integer.valueOf(tokens.getLeft()), tokens.getRight()); + } + public void post(String status, String link) throws ClientException, ApiException { + vk.wall().post(actor) + .ownerId(Integer.valueOf(vkGroup)) + .fromGroup(true) + .message(status) + .attachments(link) + .execute(); + } +} |