From 940c6f44a3df9bcb633ba3c10a49d23f669dd830 Mon Sep 17 00:00:00 2001 From: Nicolas VINOT Date: Sat, 5 Nov 2011 13:47:44 +0100 Subject: [PATCH] Send UTF-8 to Pastebin --- .../hebdobot/pastebin/PastebinClient.java | 53 +++++++++++++------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/src/main/java/fr/imirhil/april/hebdobot/pastebin/PastebinClient.java b/src/main/java/fr/imirhil/april/hebdobot/pastebin/PastebinClient.java index ee6351b..495f747 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/pastebin/PastebinClient.java +++ b/src/main/java/fr/imirhil/april/hebdobot/pastebin/PastebinClient.java @@ -11,7 +11,7 @@ import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; -import org.apache.http.params.HttpParams; +import org.apache.http.protocol.HTTP; public class PastebinClient { private static final String API_DEV_KEY = "api_dev_key"; @@ -28,6 +28,8 @@ public class PastebinClient { private static final String API_ERROR = "Bad API request,"; public static class APIException extends Exception { + private static final long serialVersionUID = 1L; + private APIException(final String message) { super(message); } @@ -48,14 +50,6 @@ public class PastebinClient { this.apiDevKey = apiDevKey; } - public String paste(final String code) throws Exception { - return this.paste(code, null); - } - - public String paste(final String code, final String name) throws Exception { - return this.paste(code, name, Format.NONE, false, Expiration.DAY_1); - } - public void login(final String name, final String password) throws Exception { final List params = new LinkedList(); @@ -65,7 +59,7 @@ public class PastebinClient { final HttpPost request = new HttpPost("http://pastebin.com/api/api_login.php"); - request.setEntity(new UrlEncodedFormEntity(params)); + request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); final HttpResponse response = this.httpClient.execute(request); final String content = @@ -89,7 +83,7 @@ public class PastebinClient { final HttpPost request = new HttpPost("http://pastebin.com/api/api_post.php"); - request.setEntity(new UrlEncodedFormEntity(params)); + request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); final HttpResponse response = this.httpClient.execute(request); final String content = @@ -98,12 +92,37 @@ public class PastebinClient { return content; } - private static void setParameter(final HttpParams params, - final String name, final Object value) { - if (value == null) { - return; - } - params.setParameter(name, value); + public String paste(final String code) throws Exception { + return this.paste(code, null, Format.NONE, false, Expiration.DAY_1); + } + + public String paste(final String code, final String name) throws Exception { + return this.paste(code, name, Format.NONE, false, Expiration.DAY_1); + } + + public String paste(final String code, final String name, + final Format format) throws Exception { + return this.paste(code, name, format, false, Expiration.DAY_1); + } + + public String paste(final String code, final Format format) + throws Exception { + return this.paste(code, null, format, false, Expiration.DAY_1); + } + + public String paste(final String code, final Expiration expiration) + throws Exception { + return this.paste(code, null, Format.NONE, false, expiration); + } + + public String paste(final String code, final Format format, + final Expiration expiration) throws Exception { + return this.paste(code, null, format, false, expiration); + } + + public String paste(final String code, final String name, + final Format format, final Expiration expiration) throws Exception { + return this.paste(code, name, format, false, expiration); } private static void setParameter(final List params,