Java tutorial
/** * Copyright (C) 2012 Happy Coding <contact@happy-coding.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.happy_coding.viralo.twitter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import twitter4j.Twitter; import twitter4j.TwitterException; import twitter4j.TwitterFactory; /** * The class responsible for following friends. */ public class FriendFollower { /** * Logger. */ private Logger logger; public FriendFollower() { logger = LoggerFactory.getLogger(getClass()); } /** * Follows the friends. * * @param myContact * @return */ public Boolean follow(Contact myContact) { Twitter twitter = new TwitterFactory().getInstance(); try { logger.debug("Create friendship for " + myContact.getUid()); twitter.createFriendship(myContact.getUid()); } catch (TwitterException e) { logger.error("Can't follow contact " + myContact.getUid(), e); return Boolean.FALSE; } return Boolean.TRUE; } /** * Unfollows the contact. * * @param myContact * @return */ public Boolean unfollow(Contact myContact) { Twitter twitter = new TwitterFactory().getInstance(); try { logger.debug("remove friendship for " + myContact.getUid()); twitter.destroyFriendship(myContact.getUid()); } catch (TwitterException e) { logger.error("can't unfollow contact " + myContact.getUid(), e); return Boolean.FALSE; } return Boolean.TRUE; } }