Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
TFJ-345 Twitter, AsyncTwitter and TwitterStream are now interface
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuke committed Feb 21, 2011
1 parent f315476 commit 79b17c0
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 379 deletions.
53 changes: 1 addition & 52 deletions twitter4j-core/src/main/java/twitter4j/AsyncTwitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package twitter4j;

import twitter4j.api.*;
import twitter4j.http.Authorization;
import twitter4j.http.OAuthSupport;

/**
Expand All @@ -25,6 +24,7 @@
*/
public interface AsyncTwitter extends java.io.Serializable,
OAuthSupport,
TwitterBase,
SearchMethodsAsync,
TrendsMethodsAsync,
TimelineMethodsAsync,
Expand All @@ -48,61 +48,10 @@ public interface AsyncTwitter extends java.io.Serializable,
NewTwitterMethodsAsync,
HelpMethodsAsync {

/**
* Returns authenticating user's screen name.<br>
* This method may internally call verifyCredentials() on the first invocation if<br>
* - this instance is authenticated by Basic and email address is supplied instead of screen name, or
* - this instance is authenticated by OAuth.<br>
* Note that this method returns a transiently cached (will be lost upon serialization) screen name while it is possible to change a user's screen name.<br>
*
* @return the authenticating screen name
* @throws TwitterException when verifyCredentials threw an exception.
* @throws IllegalStateException if no credentials are supplied. i.e.) this is an anonymous Twitter instance
* @since Twitter4J 2.1.1
*/
String getScreenName() throws TwitterException, IllegalStateException;

/**
* Returns authenticating user's user id.<br>
* This method may internally call verifyCredentials() on the first invocation if<br>
* - this instance is authenticated by Basic and email address is supplied instead of screen name, or
* - this instance is authenticated by OAuth.<br>
*
* @return the authenticating user's id
* @throws TwitterException when verifyCredentials threw an exception.
* @throws IllegalStateException if no credentials are supplied. i.e.) this is an anonymous Twitter instance
* @since Twitter4J 2.1.1
*/
long getId() throws TwitterException, IllegalStateException;

/**
* Returns the authorization scheme for this instance.<br>
* The returned type will be either of BasicAuthorization, OAuthAuthorization, or NullAuthorization
*
* @return the authorization scheme for this instance
*/
Authorization getAuthorization();

/**
* Registers a RateLimitStatusListener for account associated rate limits
*
* @param listener the listener to be added
* @see <a href="http://dev.twitter.com/pages/rate-limiting">Rate Limiting | dev.twitter.com</a>
* @since Twitter4J 2.1.12
*/
void addRateLimitStatusListener(RateLimitStatusListener listener);

/**
* Adds twitter listener
*
* @param listener TwitterListener
*/
void addListener(TwitterListener listener);

/**
* Shuts down internal dispatcher thread.
*
* @since Twitter4J 2.0.2
*/
void shutdown();
}
15 changes: 3 additions & 12 deletions twitter4j-core/src/main/java/twitter4j/AsyncTwitterFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import twitter4j.conf.ConfigurationContext;
import twitter4j.http.AccessToken;
import twitter4j.http.Authorization;
import twitter4j.http.AuthorizationFactory;
import twitter4j.http.BasicAuthorization;
import twitter4j.http.OAuthAuthorization;

Expand Down Expand Up @@ -73,7 +72,7 @@ public AsyncTwitterFactory(String configTreePath) {
* @return default singleton instance
*/
public AsyncTwitter getInstance() {
return getInstance(conf);
return new AsyncTwitterImpl(conf);
}

/**
Expand All @@ -84,7 +83,7 @@ public AsyncTwitter getInstance() {
* @return an instance
*/
public AsyncTwitter getInstance(String screenName, String password) {
return getInstance(conf, new BasicAuthorization(screenName, password));
return new AsyncTwitterImpl(conf, new BasicAuthorization(screenName, password));
}

/**
Expand All @@ -104,22 +103,14 @@ public AsyncTwitter getInstance(AccessToken accessToken) {
OAuthAuthorization oauth = new OAuthAuthorization(conf);
oauth.setOAuthConsumer(consumerKey, consumerSecret);
oauth.setOAuthAccessToken(accessToken);
return getInstance(conf, oauth);
return new AsyncTwitterImpl(conf, oauth);
}

/**
* @param auth authorization
* @return an instance
*/
public AsyncTwitter getInstance(Authorization auth) {
return getInstance(conf, auth);
}

private AsyncTwitter getInstance(Configuration conf, Authorization auth) {
return new AsyncTwitterImpl(conf, auth);
}

private AsyncTwitter getInstance(Configuration conf) {
return new AsyncTwitterImpl(conf, AuthorizationFactory.getInstance(conf));
}
}
44 changes: 9 additions & 35 deletions twitter4j-core/src/main/java/twitter4j/AsyncTwitterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@
* @see twitter4j.AsyncTwitter
* @see twitter4j.TwitterListener
*/
public class AsyncTwitterImpl extends TwitterOAuthSupportBase
public class AsyncTwitterImpl extends TwitterBaseImpl
implements AsyncTwitter {
private static final long serialVersionUID = -2008667933225051907L;
private final Twitter twitter;
private final List<TwitterListener> listeners = new ArrayList<TwitterListener>();


/*package*/
AsyncTwitterImpl(Configuration conf) {
super(conf);
twitter = new TwitterFactory(conf).getInstance(auth);
}

/*package*/
AsyncTwitterImpl(Configuration conf, Authorization auth) {
super(conf, auth);
Expand All @@ -61,37 +67,6 @@ public void addListener(TwitterListener listener) {
this.listeners.add(listener);
}

/**
* Returns authenticating user's screen name.<br>
* This method may internally call verifyCredentials() on the first invocation if<br>
* - this instance is authenticated by Basic and email address is supplied instead of screen name, or
* - this instance is authenticated by OAuth.<br>
* Note that this method returns a transiently cached (will be lost upon serialization) screen name while it is possible to change a user's screen name.<br>
*
* @return the authenticating screen name
* @throws TwitterException when verifyCredentials threw an exception.
* @throws IllegalStateException if no credentials are supplied. i.e.) this is an anonymous Twitter instance
* @since Twitter4J 2.1.1
*/
public String getScreenName() throws TwitterException, IllegalStateException {
return twitter.getScreenName();
}

/**
* Returns authenticating user's user id.<br>
* This method may internally call verifyCredentials() on the first invocation if<br>
* - this instance is authenticated by Basic and email address is supplied instead of screen name, or
* - this instance is authenticated by OAuth.<br>
*
* @return the authenticating user's id
* @throws TwitterException when verifyCredentials threw an exception.
* @throws IllegalStateException if no credentials are supplied. i.e.) this is an anonymous Twitter instance
* @since Twitter4J 2.1.1
*/
public long getId() throws TwitterException, IllegalStateException {
return twitter.getId();
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -2648,9 +2623,7 @@ public void invoke(List<TwitterListener> listeners) throws TwitterException {
private static transient Dispatcher dispatcher;

/**
* Shuts down internal dispatcher thread.
*
* @since Twitter4J 2.0.2
* {@inheritDoc}
*/
public void shutdown() {
super.shutdown();
Expand All @@ -2660,6 +2633,7 @@ public void shutdown() {
dispatcher = null;
}
}
twitter.shutdown();
}

private Dispatcher getDispatcher() {
Expand Down
46 changes: 1 addition & 45 deletions twitter4j-core/src/main/java/twitter4j/Twitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package twitter4j;

import twitter4j.api.*;
import twitter4j.http.Authorization;
import twitter4j.http.OAuthSupport;

/**
Expand All @@ -25,6 +24,7 @@
*/
public interface Twitter extends java.io.Serializable,
OAuthSupport,
TwitterBase,
SearchMethods,
TrendsMethods,
TimelineMethods,
Expand All @@ -47,48 +47,4 @@ public interface Twitter extends java.io.Serializable,
LegalResources,
NewTwitterMethods,
HelpMethods {

/**
* Returns authenticating user's screen name.<br>
* This method may internally call verifyCredentials() on the first invocation if<br>
* - this instance is authenticated by Basic and email address is supplied instead of screen name, or
* - this instance is authenticated by OAuth.<br>
* Note that this method returns a transiently cached (will be lost upon serialization) screen name while it is possible to change a user's screen name.<br>
*
* @return the authenticating screen name
* @throws TwitterException when verifyCredentials threw an exception.
* @throws IllegalStateException if no credentials are supplied. i.e.) this is an anonymous Twitter instance
* @since Twitter4J 2.1.1
*/
String getScreenName() throws TwitterException, IllegalStateException;

/**
* Returns authenticating user's user id.<br>
* This method may internally call verifyCredentials() on the first invocation if<br>
* - this instance is authenticated by Basic and email address is supplied instead of screen name, or
* - this instance is authenticated by OAuth.<br>
*
* @return the authenticating user's id
* @throws TwitterException when verifyCredentials threw an exception.
* @throws IllegalStateException if no credentials are supplied. i.e.) this is an anonymous Twitter instance
* @since Twitter4J 2.1.1
*/
long getId() throws TwitterException, IllegalStateException;

/**
* Returns the authorization scheme for this instance.<br>
* The returned type will be either of BasicAuthorization, OAuthAuthorization, or NullAuthorization
*
* @return the authorization scheme for this instance
*/
Authorization getAuthorization();

/**
* Registers a RateLimitStatusListener for account associated rate limits
*
* @param listener the listener to be added
* @see <a href="http://dev.twitter.com/pages/rate-limiting">Rate Limiting | dev.twitter.com</a>
* @since Twitter4J 2.1.12
*/
void addRateLimitStatusListener(RateLimitStatusListener listener);
}
Loading

0 comments on commit 79b17c0

Please sign in to comment.