aboutsummaryrefslogtreecommitdiff
path: root/juick-crosspost/src/main/java/com/juick/service/rest
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-10-24 17:18:29 +0300
committerGravatar Vitaly Takmazov2017-10-24 22:34:41 +0300
commitde2cc2db73a5de42d9bfaeb92604f28abe2a328a (patch)
tree352a3d76fcbc987f068527ff043174308a666654 /juick-crosspost/src/main/java/com/juick/service/rest
parent881a546bf7a56550eec1e38ce839f47a1cb1a750 (diff)
crosspost: refactoring
* spring-social * get tokens via service api
Diffstat (limited to 'juick-crosspost/src/main/java/com/juick/service/rest')
-rw-r--r--juick-crosspost/src/main/java/com/juick/service/rest/CrosspostRestService.java143
1 files changed, 143 insertions, 0 deletions
diff --git a/juick-crosspost/src/main/java/com/juick/service/rest/CrosspostRestService.java b/juick-crosspost/src/main/java/com/juick/service/rest/CrosspostRestService.java
new file mode 100644
index 00000000..52b72c3f
--- /dev/null
+++ b/juick-crosspost/src/main/java/com/juick/service/rest/CrosspostRestService.java
@@ -0,0 +1,143 @@
+package com.juick.service.rest;
+
+import com.juick.ExternalToken;
+import com.juick.User;
+import com.juick.server.helpers.ApplicationStatus;
+import com.juick.service.CrosspostService;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import javax.inject.Inject;
+import java.util.Optional;
+
+@Component
+public class CrosspostRestService implements CrosspostService {
+ @Inject
+ private RestTemplate rest;
+
+ @Override
+ public Optional<ExternalToken> getTwitterToken(int uid) {
+ User user = rest.getForObject("https://api.juick.com/tokens?uid={uid}", User.class, uid);
+ if (user != null) {
+ return user.getTokens().stream()
+ .filter(t -> t.getType().equals("twitter")).findFirst();
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public boolean deleteTwitterToken(Integer uid) {
+ return false;
+ }
+
+ @Override
+ public Optional<String> getFacebookToken(int uid) {
+ return null;
+ }
+
+ @Override
+ public ApplicationStatus getFbCrossPostStatus(int uid) {
+ return null;
+ }
+
+ @Override
+ public boolean enableFBCrosspost(Integer uid) {
+ return false;
+ }
+
+ @Override
+ public void disableFBCrosspost(Integer uid) {
+
+ }
+
+ @Override
+ public String getTwitterName(int uid) {
+ ExternalToken token = getTwitterToken(uid).orElse(null);
+ if (token != null) {
+ return token.getName();
+ }
+ return StringUtils.EMPTY;
+ }
+
+ @Override
+ public String getTelegramName(int uid) {
+ return null;
+ }
+
+ @Override
+ public Optional<Pair<String, String>> getVkTokens(int uid) {
+ return null;
+ }
+
+ @Override
+ public void deleteVKUser(Integer uid) {
+
+ }
+
+ @Override
+ public int getUIDbyFBID(long fbID) {
+ return 0;
+ }
+
+ @Override
+ public boolean createFacebookUser(long fbID, String loginhash, String token, String fbName, String fbLink) {
+ return false;
+ }
+
+ @Override
+ public boolean updateFacebookUser(long fbID, String token, String fbName, String fbLink) {
+ return false;
+ }
+
+ @Override
+ public int getUIDbyVKID(long vkID) {
+ return 0;
+ }
+
+ @Override
+ public boolean createVKUser(long vkID, String loginhash, String token, String vkName, String vkLink) {
+ return false;
+ }
+
+ @Override
+ public String getFacebookNameByHash(String hash) {
+ return null;
+ }
+
+ @Override
+ public String getTelegramNameByHash(String hash) {
+ return null;
+ }
+
+ @Override
+ public boolean setFacebookUser(String hash, int uid) {
+ return false;
+ }
+
+ @Override
+ public String getVKNameByHash(String hash) {
+ return null;
+ }
+
+ @Override
+ public boolean setVKUser(String hash, int uid) {
+ return false;
+ }
+
+ @Override
+ public boolean setTelegramUser(String hash, int uid) {
+ return false;
+ }
+
+ @Override
+ public String getJIDByHash(String hash) {
+ return null;
+ }
+
+ @Override
+ public boolean setJIDUser(String hash, int uid) {
+ return false;
+ }
+}