use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class CronServiceImpl method checkCredentials.
@Override
@Scheduled(fixedDelayString = "${wtfdyum.credentials-check-delay}", initialDelay = 120000L)
public void checkCredentials() {
log.debug("Checking credentials...");
final StopWatch watch = new StopWatch();
watch.start();
final Set<Long> members = principalService.getMembers();
for (final Long userId : members) {
final Principal principal = principalService.get(userId);
if (!twitterService.verifyCredentials(principal)) {
userService.applyLimit(userId, UserLimitType.CREDENTIALS_INVALID);
userService.addEvent(userId, new Event(EventType.INVALID_TWITTER_CREDENTIALS, ""));
} else {
userService.resetLimit(userId, UserLimitType.CREDENTIALS_INVALID);
}
}
watch.stop();
log.debug("Finished checking credentials in {} ms", watch.getTotalTimeMillis());
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class NotifyUnfollowFeatureStrategy method cron.
@Override
public Set<Event> cron(final Long userId) throws WTFDYUMException {
final Set<Event> result = new HashSet<>();
final Principal principal = principalService.get(userId);
final Set<Long> followers = twitterService.getFollowers(userId, Optional.ofNullable(principal));
final Set<Long> unfollowersId = followersService.getUnfollowers(userId, followers);
final List<User> unfollowers = twitterService.getUsers(principal, Longs.toArray(unfollowersId));
for (final User unfollower : unfollowers) {
result.add(new Event(EventType.UNFOLLOW, unfollower.getScreenName()));
twitterService.sendDirectMessage(principal, userId, String.format(unfollowDMText, unfollower.getScreenName()));
}
return result;
}
Aggregations