com.ahuralab.mozaic.app.TwitterClient.java Source code

Java tutorial

Introduction

Here is the source code for com.ahuralab.mozaic.app.TwitterClient.java

Source

/* 
 Copyright (c) 2013, Panteha Saeedi All rights reserved.
     
   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.ahuralab.mozaic.app;

import java.util.List;

import twitter4j.Paging;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;

/**
 * @author pani
 * 
 */
public class TwitterClient {

    private final Twitter twitter;

    public Twitter getTwitter() {
        return twitter;
    }

    public TwitterClient(Twitter twitter) {
        this.twitter = twitter;
    }

    public List<Status> getHomeTimeline(long sinceId) throws TwitterException {
        return twitter.getHomeTimeline(new Paging(sinceId));
    }

    public List<Status> getHomeTimeline() throws TwitterException {
        return twitter.getHomeTimeline(new Paging(1, 200));
    }

    public void sendTwitt(String message) throws TwitterException {
        twitter.updateStatus(message);
    }

    public void createFrienship(String userScreenName) throws TwitterException {
        twitter.createFriendship(userScreenName);
    }

    public void destroyFriendship(String userScreenName) throws TwitterException {
        twitter.destroyFriendship(userScreenName);
    }

    public void reTweet(Long tweetId) throws TwitterException {
        twitter.retweetStatus(tweetId);
    }

    public void replyTweetMessage(String userName, String message) throws TwitterException {
        twitter.sendDirectMessage(userName, message);
    }

    public List<Status> getRecentTweets() throws TwitterException {
        return twitter.getRetweetsOfMe(new Paging(1, 200));
    }

    public int getNumberofFollowers(long userId) throws TwitterException {
        return twitter.showUser(userId).getFollowersCount();
    }

    public int getNumberofFriends(long userId) throws TwitterException {
        return twitter.showUser(userId).getFriendsCount();
    }

    public int getNumberofTweetsSent(long userId) throws TwitterException {
        return twitter.showUser(userId).getStatusesCount();
    }

}