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

Commit

Permalink
Merge branch 'master' of https://github.com/Mocel/twitter4j into TFJ-593
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuke Yamamoto committed Oct 22, 2011
2 parents f5f336d + 22f8cf6 commit 665ae1d
Show file tree
Hide file tree
Showing 15 changed files with 325 additions and 32 deletions.
80 changes: 78 additions & 2 deletions twitter4j-async/src/main/java/twitter4j/AsyncTwitterImpl.java
Expand Up @@ -577,6 +577,82 @@ public void invoke(List<TwitterListener> listeners) throws TwitterException {
});
}

/**
* {@inheritDoc}
*/
public void updateStatusWithMedia(final String statusText,
final boolean possiblySensitive, final File file) {
getDispatcher().invokeLater(new AsyncTask(UPDATE_STATUS_WITH_MEDIA, listeners) {
@Override
void invoke(List<TwitterListener> listeners) throws TwitterException {
Status status = twitter.updateStatusWithMedia(statusText, possiblySensitive, file);
for (TwitterListener listener : listeners) {
try {
listener.updatedStatusWithMedia(status);
} catch (Exception ignore) {
}
}
}
});
}

/**
* {@inheritDoc}
*/
public void updateStatusWithMedia(final String statusText, final boolean possiblySensitive,
final String mediaFilename, final InputStream mediaBody) {
getDispatcher().invokeLater(new AsyncTask(UPDATE_STATUS_WITH_MEDIA, listeners) {
@Override
void invoke(List<TwitterListener> listeners) throws TwitterException {
Status status = twitter.updateStatusWithMedia(statusText, possiblySensitive, mediaFilename, mediaBody);
for (TwitterListener listener : listeners) {
try {
listener.updatedStatusWithMedia(status);
} catch (Exception ignore) {
}
}
}
});
}

/**
* {@inheritDoc}
*/
public void updateStatusWithMedia(final StatusUpdate latestStatus,
final boolean possiblySensitive, final File file) {
getDispatcher().invokeLater(new AsyncTask(UPDATE_STATUS_WITH_MEDIA, listeners) {
@Override
void invoke(List<TwitterListener> listeners) throws TwitterException {
Status status = twitter.updateStatusWithMedia(latestStatus, possiblySensitive, file);
for (TwitterListener listener : listeners) {
try {
listener.updatedStatusWithMedia(status);
} catch (Exception ignore) {
}
}
}
});
}

/**
* {@inheritDoc}
*/
public void updateStatusWithMedia(final StatusUpdate latestStatus,
final boolean possiblySensitive, final String mediaFilename, final InputStream mediaBody) {
getDispatcher().invokeLater(new AsyncTask(UPDATE_STATUS_WITH_MEDIA, listeners) {
@Override
void invoke(List<TwitterListener> listeners) throws TwitterException {
Status status = twitter.updateStatusWithMedia(latestStatus, possiblySensitive, mediaFilename, mediaBody);
for (TwitterListener listener : listeners) {
try {
listener.updatedStatusWithMedia(status);
} catch (Exception ignore) {
}
}
}
});
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -2220,7 +2296,7 @@ public void invoke(List<TwitterListener> listeners) throws TwitterException {
}
});
}

/**
* {@inheritDoc}
*/
Expand All @@ -2237,7 +2313,7 @@ public void invoke(List<TwitterListener> listeners) throws TwitterException {
}
});
}

/**
* {@inheritDoc}
*/
Expand Down
6 changes: 6 additions & 0 deletions twitter4j-async/src/main/java/twitter4j/TwitterAdapter.java
Expand Up @@ -115,6 +115,12 @@ public void gotShowStatus(Status statuses) {
public void updatedStatus(Status statuses) {
}

/**
* @since Twitter4J 2.2.5
*/
public void updatedStatusWithMedia(Status status) {
}

public void destroyedStatus(Status destroyedStatus) {
}

Expand Down
5 changes: 5 additions & 0 deletions twitter4j-async/src/main/java/twitter4j/TwitterListener.java
Expand Up @@ -96,6 +96,11 @@ public interface TwitterListener {

void updatedStatus(Status status);

/**
* @since Twitter4J 2.2.5
*/
void updatedStatusWithMedia(Status status);

void destroyedStatus(Status destroyedStatus);

/**
Expand Down
1 change: 1 addition & 0 deletions twitter4j-async/src/main/java/twitter4j/TwitterMethod.java
Expand Up @@ -100,6 +100,7 @@ private Object readResolve() throws ObjectStreamException {
/*Status Methods*/
public static final TwitterMethod SHOW_STATUS = new TwitterMethod("SHOW_STATUS");
public static final TwitterMethod UPDATE_STATUS = new TwitterMethod("UPDATE_STATUS");
public static final TwitterMethod UPDATE_STATUS_WITH_MEDIA = new TwitterMethod("UPDATE_STATUS_WITH_MEDIA");
public static final TwitterMethod DESTROY_STATUS = new TwitterMethod("DESTROY_STATUS");
public static final TwitterMethod RETWEET_STATUS = new TwitterMethod("RETWEET_STATUS");
public static final TwitterMethod RETWEETS = new TwitterMethod("RETWEETS");
Expand Down
Expand Up @@ -17,9 +17,6 @@
package twitter4j.api;

import twitter4j.Paging;
import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.TwitterException;

/**
* @author Joern Huxhorn - jhuxhorn at googlemail.com
Expand Down Expand Up @@ -64,7 +61,7 @@ public interface FavoriteMethodsAsync {
* @since Twitter4J 2.0.1
*/
void getFavorites(String id, int page);

/**
* Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter in the requested format.
* <br>This method calls http://api.twitter.com/1/favorites.json
Expand All @@ -74,7 +71,7 @@ public interface FavoriteMethodsAsync {
* @since Twitter4J 2.2.5
*/
void getFavorites(Paging paging);

/**
* Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter in the requested format.
* <br>This method calls http://api.twitter.com/1/favorites/[id].json
Expand Down
Expand Up @@ -16,6 +16,9 @@

package twitter4j.api;

import java.io.File;
import java.io.InputStream;

import twitter4j.Paging;
import twitter4j.StatusUpdate;

Expand Down Expand Up @@ -128,4 +131,55 @@ public interface StatusMethodsAsync {
* @since Twitter4J 2.2.3
*/
void getRetweetedByIDs(long statusId, Paging paging);

/**
* Updates the authenticating user's status and attaches media for upload. The Tweet text will be rewritten to include the media URL(s), which will reduce the number of characters allowed in the Tweet text. If the URL(s) cannot be appended without text truncation, the tweet will be rejected and this method will return an HTTP 403 error.
* <br>This method calls http://upload.twitter.com/1/statuses/update_with_media
*
* @param status the text of your status update
* @param possiblySensitive Set to true for content which may not be suitable for every audience
* @param file the file of the media uploaded
* @see <a href="https://dev.twitter.com/docs/api/1/post/statuses/update_with_media">POST statuses/update_with_media | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
void updateStatusWithMedia(String statusText, boolean possiblySensitive, File file);

/**
* Updates the authenticating user's status and attaches media for upload. The Tweet text will be rewritten to include the media URL(s), which will reduce the number of characters allowed in the Tweet text. If the URL(s) cannot be appended without text truncation, the tweet will be rejected and this method will return an HTTP 403 error.
* <br>This method calls http://upload.twitter.com/1/statuses/update_with_media
*
* @param status the text of your status update
* @param possiblySensitive Set to true for content which may not be suitable for every audience
* @param mediaFilename the filename of the media uploaded
* @param mediaBody the body of the media uploaded
* @see <a href="https://dev.twitter.com/docs/api/1/post/statuses/update_with_media">POST statuses/update_with_media | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
void updateStatusWithMedia(String statusText, boolean possiblySensitive, String mediaFilename, InputStream mediaBody);

/**
* Updates the authenticating user's status and attaches media for upload. The Tweet text will be rewritten to include the media URL(s), which will reduce the number of characters allowed in the Tweet text. If the URL(s) cannot be appended without text truncation, the tweet will be rejected and this method will return an HTTP 403 error.
* <br>This method calls http://upload.twitter.com/1/statuses/update_with_media
*
* @param latestStatus the latest status to be updated.
* @param possiblySensitive Set to true for content which may not be suitable for every audience
* @param file the file of the media uploaded
* @see <a href="https://dev.twitter.com/docs/api/1/post/statuses/update">POST statuses/update | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
void updateStatusWithMedia(StatusUpdate latestStatus, boolean possiblySensitive, File file);

/**
* Updates the authenticating user's status and attaches media for upload. The Tweet text will be rewritten to include the media URL(s), which will reduce the number of characters allowed in the Tweet text. If the URL(s) cannot be appended without text truncation, the tweet will be rejected and this method will return an HTTP 403 error.
* <br>This method calls http://upload.twitter.com/1/statuses/update_with_media
*
* @param latestStatus the latest status to be updated.
* @param possiblySensitive Set to true for content which may not be suitable for every audience
* @param mediaFilename the filename of the media uploaded
* @param mediaBody the body of the media uploaded
* @see <a href="https://dev.twitter.com/docs/api/1/post/statuses/update">POST statuses/update | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
void updateStatusWithMedia(StatusUpdate latestStatus, boolean possiblySensitive, String mediaFilename, InputStream mediaBody);

}
5 changes: 5 additions & 0 deletions twitter4j-async/src/test/java/twitter4j/AsyncTwitterTest.java
Expand Up @@ -504,6 +504,11 @@ public void updatedStatus(Status status) {
notifyResponse();
}

public void updatedStatusWithMedia(Status status) {
this.status = status;
notifyResponse();
}

public void destroyedStatus(Status destroyedStatus) {
this.status = destroyedStatus;
notifyResponse();
Expand Down
56 changes: 56 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/TwitterImpl.java
Expand Up @@ -446,6 +446,62 @@ public Status updateStatus(StatusUpdate latestStatus) throws TwitterException {
INCLUDE_ENTITIES)));
}

/**
* {@inheritDoc}
*/
public Status updateStatusWithMedia(String status,
boolean possiblySensitive, File file) throws TwitterException {
ensureAuthorizationEnabled();
return factory.createStatus(post(conf.getUploadBaseURL()
+ "statuses/update_with_media.json",
new HttpParameter[]{ new HttpParameter("status", status)
, new HttpParameter("possibly_sensitive", possiblySensitive)
, new HttpParameter("media[]", file)}));
}

/**
* {@inheritDoc}
*/
public Status updateStatusWithMedia(String status, boolean possiblySensitive,
String mediaFilename, InputStream mediaBody) throws TwitterException {
ensureAuthorizationEnabled();
return factory.createStatus(post(conf.getUploadBaseURL()
+ "statuses/update_with_media.json",
new HttpParameter[]{ new HttpParameter("status", status)
, new HttpParameter("possibly_sensitive", possiblySensitive)
, new HttpParameter("media[]", mediaFilename, mediaBody)}));
}

/**
* {@inheritDoc}
*/
public Status updateStatusWithMedia(StatusUpdate latestStatus,
boolean possiblySensitive, File file) throws TwitterException {
ensureAuthorizationEnabled();
HttpParameter[] params = new HttpParameter[]{
new HttpParameter("possibly_sensitive", possiblySensitive),
new HttpParameter("media[]", file),
};
return factory.createStatus(post(conf.getUploadBaseURL()
+ "statuses/update_with_media.json",
mergeParameters(latestStatus.asHttpParameterArray(), params)));
}

/**
* {@inheritDoc}
*/
public Status updateStatusWithMedia(StatusUpdate latestStatus, boolean possiblySensitive,
String mediaFilename, InputStream mediaBody) throws TwitterException {
ensureAuthorizationEnabled();
HttpParameter[] params = new HttpParameter[]{
new HttpParameter("possibly_sensitive", possiblySensitive),
new HttpParameter("media[]", mediaFilename, mediaBody),
};
return factory.createStatus(post(conf.getUploadBaseURL()
+ "statuses/update_with_media.json",
mergeParameters(latestStatus.asHttpParameterArray(), params)));
}

/**
* {@inheritDoc}
*/
Expand Down
3 changes: 0 additions & 3 deletions twitter4j-core/src/main/java/twitter4j/TwitterResponse.java
Expand Up @@ -16,9 +16,6 @@

package twitter4j;


import twitter4j.internal.http.HttpResponse;

/**
* Super interface of Twitter Response data interfaces which indicates that rate limit status is avaialble.
*
Expand Down
61 changes: 61 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/api/StatusMethods.java
Expand Up @@ -16,6 +16,9 @@

package twitter4j.api;

import java.io.File;
import java.io.InputStream;

import twitter4j.IDs;
import twitter4j.Paging;
import twitter4j.ResponseList;
Expand Down Expand Up @@ -152,4 +155,62 @@ public interface StatusMethods {
* @since Twitter4J 2.2.3
*/
IDs getRetweetedByIDs(long statusId, Paging paging) throws TwitterException;

/**
* Updates the authenticating user's status and attaches media for upload. The Tweet text will be rewritten to include the media URL(s), which will reduce the number of characters allowed in the Tweet text. If the URL(s) cannot be appended without text truncation, the tweet will be rejected and this method will return an HTTP 403 error.
* <br>This method calls http://upload.twitter.com/1/statuses/update_with_media
*
* @param status the text of your status update
* @param possiblySensitive Set to true for content which may not be suitable for every audience
* @param file the file of the media uploaded
* @return the latest status
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1/post/statuses/update_with_media">POST statuses/update_with_media | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
Status updateStatusWithMedia(String status, boolean possiblySensitive, File file) throws TwitterException;

/**
* Updates the authenticating user's status and attaches media for upload. The Tweet text will be rewritten to include the media URL(s), which will reduce the number of characters allowed in the Tweet text. If the URL(s) cannot be appended without text truncation, the tweet will be rejected and this method will return an HTTP 403 error.
* <br>This method calls http://upload.twitter.com/1/statuses/update_with_media
*
* @param status the text of your status update
* @param possiblySensitive Set to true for content which may not be suitable for every audience
* @param mediaFilename the filename of the media uploaded
* @param mediaBody the body of the media uploaded
* @return the latest status
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1/post/statuses/update_with_media">POST statuses/update_with_media | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
Status updateStatusWithMedia(String status, boolean possiblySensitive, String mediaFilename, InputStream mediaBody) throws TwitterException;

/**
* Updates the authenticating user's status and attaches media for upload. The Tweet text will be rewritten to include the media URL(s), which will reduce the number of characters allowed in the Tweet text. If the URL(s) cannot be appended without text truncation, the tweet will be rejected and this method will return an HTTP 403 error.
* <br>This method calls http://upload.twitter.com/1/statuses/update_with_media
*
* @param latestStatus the latest status to be updated.
* @param possiblySensitive Set to true for content which may not be suitable for every audience
* @param file the file of the media uploaded
* @return the latest status
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1/post/statuses/update">POST statuses/update | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
Status updateStatusWithMedia(StatusUpdate latestStatus, boolean possiblySensitive, File file) throws TwitterException;

/**
* Updates the authenticating user's status and attaches media for upload. The Tweet text will be rewritten to include the media URL(s), which will reduce the number of characters allowed in the Tweet text. If the URL(s) cannot be appended without text truncation, the tweet will be rejected and this method will return an HTTP 403 error.
* <br>This method calls http://upload.twitter.com/1/statuses/update_with_media
*
* @param latestStatus the latest status to be updated.
* @param possiblySensitive Set to true for content which may not be suitable for every audience
* @param mediaFilename the filename of the media uploaded
* @param mediaBody the body of the media uploaded
* @return the latest status
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1/post/statuses/update">POST statuses/update | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
Status updateStatusWithMedia(StatusUpdate latestStatus, boolean possiblySensitive, String mediaFilename, InputStream mediaBody) throws TwitterException;
}
Expand Up @@ -102,6 +102,8 @@ public interface Configuration extends HttpClientConfiguration

String getSiteStreamBaseURL();

String getUploadBaseURL();

boolean isIncludeRTsEnabled();

boolean isIncludeEntitiesEnabled();
Expand Down

0 comments on commit 665ae1d

Please sign in to comment.