Created
January 26, 2015 14:54
-
-
Save ldoguin/067475b75bc6cf7ed68c to your computer and use it in GitHub Desktop.
Spring service to store twit account update in Couchbase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.couchbase.advocacy.metrics.twitter; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.scheduling.annotation.Scheduled; | |
import org.springframework.social.twitter.api.Twitter; | |
import org.springframework.social.twitter.api.TwitterProfile; | |
import org.springframework.stereotype.Service; | |
import java.util.Date; | |
import java.util.Iterator; | |
import java.util.function.Consumer; | |
@Service | |
public class TwitterService { | |
private final Twitter twitter; | |
private final TwitterUpdateRepository twitterUpdateRepository; | |
private String keyReg = "tw-%s-%d"; | |
@Autowired | |
TwitterService(Twitter twitter, TwitterUpdateRepository twitterUpdateRepository) { | |
this.twitter = twitter; | |
this.twitterUpdateRepository = twitterUpdateRepository; | |
} | |
public void update(String twitterAccount){ | |
TwitterProfile twitterProfile = twitter.userOperations().getUserProfile(twitterAccount); | |
int followers = twitterProfile.getFollowersCount(); | |
int favorites = twitterProfile.getFavoritesCount(); | |
int friends = twitterProfile.getFriendsCount(); | |
int statuses = twitterProfile.getStatusesCount(); | |
long createdAt = new Date().getTime(); | |
String key = String.format(keyReg, twitterAccount, createdAt); | |
TwitterUpdate tu = new TwitterUpdate(key, createdAt, twitterAccount, followers, favorites, friends, statuses); | |
twitterUpdateRepository.save(tu); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment