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 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 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> 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; } }