This repository has been archived by the owner on Nov 19, 2021. It is now read-only.
forked from Twitter4J/Twitter4J
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mobypicture, Twipl, Posterous Support.
- Loading branch information
Showing
6 changed files
with
328 additions
and
0 deletions.
There are no files selected for viewing
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
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
88 changes: 88 additions & 0 deletions
88
twitter4j-media-support/src/main/java/twitter4j/media/MobypictureUpload.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
Copyright (c) 2007-2011, Yusuke Yamamoto | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the Yusuke Yamamoto nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY | ||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package twitter4j.media; | ||
|
||
import twitter4j.TwitterException; | ||
import twitter4j.conf.Configuration; | ||
import twitter4j.http.OAuthAuthorization; | ||
import twitter4j.internal.http.HttpParameter; | ||
import twitter4j.internal.org.json.JSONException; | ||
import twitter4j.internal.org.json.JSONObject; | ||
|
||
/** | ||
* @see <a href="http://developers.mobypicture.com/documentation/">mobyapi documentation</a> | ||
* @author withgod - noname at withgod.jp | ||
* @since Twitter4J 2.1.12 | ||
*/ | ||
class MobypictureUpload extends AbstractImageUploadImpl { | ||
|
||
public MobypictureUpload(Configuration conf, String apiKey, OAuthAuthorization oauth) { | ||
super(conf, apiKey, oauth); | ||
} | ||
|
||
@Override | ||
protected String postUpload() throws TwitterException { | ||
int statusCode = httpResponse.getStatusCode(); | ||
if (statusCode != 200) | ||
throw new TwitterException("Mobypic image upload returned invalid status code", httpResponse); | ||
|
||
String response = httpResponse.asString(); | ||
|
||
try { | ||
JSONObject json = new JSONObject(response); | ||
if (!json.isNull("media")) { | ||
return json.getJSONObject("media").getString("mediaurl"); | ||
} | ||
} catch (JSONException e) { | ||
throw new TwitterException("Invalid Mobypic response: " + response, e); | ||
} | ||
|
||
throw new TwitterException("Unknown Mobypic response", httpResponse); | ||
} | ||
|
||
@Override | ||
protected void preUpload() throws TwitterException { | ||
uploadUrl = "https://api.mobypicture.com/2.0/upload.json"; | ||
String verifyCredentialsAuthorizationHeader = generateVerifyCredentialsAuthorizationHeader(TWITTER_VERIFY_CREDENTIALS_JSON); | ||
|
||
headers.put("X-Auth-Service-Provider", TWITTER_VERIFY_CREDENTIALS_JSON); | ||
headers.put("X-Verify-Credentials-Authorization", verifyCredentialsAuthorizationHeader); | ||
|
||
if (null == apiKey) { | ||
throw new IllegalStateException("No API Key for Mobypic specified. put media.providerAPIKey in twitter4j.properties."); | ||
} | ||
HttpParameter[] params = { | ||
new HttpParameter("key", apiKey), | ||
this.image}; | ||
if (message != null) { | ||
params = appendHttpParameters(new HttpParameter[]{ | ||
this.message | ||
}, params); | ||
} | ||
this.postParameter = params; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
twitter4j-media-support/src/main/java/twitter4j/media/PosterousUpload.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Copyright (c) 2007-2011, Yusuke Yamamoto | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the Yusuke Yamamoto nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY | ||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package twitter4j.media; | ||
|
||
import twitter4j.TwitterException; | ||
import twitter4j.conf.Configuration; | ||
import twitter4j.http.OAuthAuthorization; | ||
import twitter4j.internal.http.HttpParameter; | ||
import twitter4j.internal.org.json.JSONException; | ||
import twitter4j.internal.org.json.JSONObject; | ||
|
||
/** | ||
* @see <a href="http://apidocs.posterous.com/pages/twitter">Posterous API Documentation</a> | ||
* @author withgod - noname at withgod.jp | ||
* @since Twitter4J 2.1.12 | ||
*/ | ||
class PosterousUpload extends AbstractImageUploadImpl { | ||
|
||
public PosterousUpload(Configuration conf, OAuthAuthorization oauth) { | ||
super(conf, oauth); | ||
} | ||
|
||
|
||
@Override | ||
protected String postUpload() throws TwitterException { | ||
int statusCode = httpResponse.getStatusCode(); | ||
if (statusCode != 200) | ||
throw new TwitterException("Posterous image upload returned invalid status code", httpResponse); | ||
|
||
String response = httpResponse.asString(); | ||
|
||
try { | ||
JSONObject json = new JSONObject(response); | ||
if (!json.isNull("url")) | ||
return json.getString("url"); | ||
} catch (JSONException e) { | ||
throw new TwitterException("Invalid Posterous response: " + response, e); | ||
} | ||
|
||
throw new TwitterException("Unknown Posterous response", httpResponse); | ||
} | ||
|
||
@Override | ||
protected void preUpload() throws TwitterException { | ||
uploadUrl = "http://posterous.com/api2/upload.json"; | ||
String verifyCredentialsAuthorizationHeader = generateVerifyCredentialsAuthorizationHeader(TWITTER_VERIFY_CREDENTIALS_JSON); | ||
|
||
headers.put("X-Auth-Service-Provider", TWITTER_VERIFY_CREDENTIALS_JSON); | ||
headers.put("X-Verify-Credentials-Authorization", verifyCredentialsAuthorizationHeader); | ||
|
||
HttpParameter[] params = {this.image}; | ||
if (message != null) { | ||
params = appendHttpParameters(new HttpParameter[]{ | ||
this.message | ||
}, params); | ||
} | ||
this.postParameter = params; | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
twitter4j-media-support/src/main/java/twitter4j/media/TwiplUpload.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
Copyright (c) 2007-2011, Yusuke Yamamoto | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the Yusuke Yamamoto nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY | ||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package twitter4j.media; | ||
|
||
import twitter4j.TwitterException; | ||
import twitter4j.conf.Configuration; | ||
import twitter4j.http.OAuthAuthorization; | ||
import twitter4j.internal.http.HttpParameter; | ||
|
||
/** | ||
* @see <a href="http://www.twipl.net/api/doc">Twipl Open API</a> | ||
* @author withgod - noname at withgod.jp | ||
* @since Twitter4J 2.1.12 | ||
*/ | ||
class TwiplUpload extends AbstractImageUploadImpl { | ||
|
||
public TwiplUpload(Configuration conf, String apiKey, OAuthAuthorization oauth) { | ||
super(conf, apiKey, oauth); | ||
} | ||
|
||
|
||
@Override | ||
protected String postUpload() throws TwitterException { | ||
int statusCode = httpResponse.getStatusCode(); | ||
if (statusCode != 200) | ||
throw new TwitterException("Twipl image upload returned invalid status code", httpResponse); | ||
|
||
String response = httpResponse.asString(); | ||
if(-1 != response.indexOf("<response status=\"ok\">")){ | ||
String h = "<mediaurl>"; | ||
int i = response.indexOf(h); | ||
if(i != -1){ | ||
int j = response.indexOf("</mediaurl>", i + h.length()); | ||
if(j != -1){ | ||
return response.substring(i + h.length(), j); | ||
} | ||
} | ||
} else if(-1 != response.indexOf("<rsp status=\"fail\">")){ | ||
String h = "msg=\""; | ||
int i = response.indexOf(h); | ||
if(i != -1){ | ||
int j = response.indexOf("\"", i + h.length()); | ||
if(j != -1){ | ||
String msg = response.substring(i + h.length(), j); | ||
throw new TwitterException ("Invalid Twitgoo response: " + msg); | ||
} | ||
} | ||
} | ||
|
||
throw new TwitterException("Unknown Twipl response", httpResponse); | ||
} | ||
|
||
@Override | ||
protected void preUpload() throws TwitterException { | ||
uploadUrl = "http://api.twipl.net/2/upload.xml"; | ||
String verifyCredentialsAuthorizationHeader = generateVerifyCredentialsAuthorizationHeader(TWITTER_VERIFY_CREDENTIALS_XML); | ||
|
||
headers.put("X-OAUTH-AUTHORIZATION ", verifyCredentialsAuthorizationHeader); | ||
headers.put("X-OAUTH-SP-URL ", TWITTER_VERIFY_CREDENTIALS_XML); | ||
|
||
if (null == apiKey) { | ||
throw new IllegalStateException("No API Key for Twipl specified. put media.providerAPIKey in twitter4j.properties."); | ||
} | ||
String fname = this.image.getFile().getName(); | ||
HttpParameter[] params = { | ||
new HttpParameter("key", apiKey), | ||
new HttpParameter("media1", fname, this.image.getFileBody()) | ||
}; | ||
if (message != null) { | ||
params = appendHttpParameters(new HttpParameter[]{ | ||
this.message | ||
}, params); | ||
} | ||
this.postParameter = params; | ||
} | ||
} |
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