diff options
author | snowleo <schneeleo@gmail.com> | 2011-10-12 03:14:07 +0200 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-10-12 03:14:26 +0200 |
commit | 860d446d28776ec842fa53e8e08538d4e093d6e9 (patch) | |
tree | 0c4598eae4eb8c59fd36e8312eab1b27a8018794 /EssentialsUpdate/src/com/earth2me/essentials/update/PastieUpload.java | |
parent | 9ec398b39b0f48392a9d635041b392c7dba2ca0c (diff) | |
download | Essentials-860d446d28776ec842fa53e8e08538d4e093d6e9.tar Essentials-860d446d28776ec842fa53e8e08538d4e093d6e9.tar.gz Essentials-860d446d28776ec842fa53e8e08538d4e093d6e9.tar.lz Essentials-860d446d28776ec842fa53e8e08538d4e093d6e9.tar.xz Essentials-860d446d28776ec842fa53e8e08538d4e093d6e9.zip |
EssentialsUpdate WIP
Diffstat (limited to 'EssentialsUpdate/src/com/earth2me/essentials/update/PastieUpload.java')
-rw-r--r-- | EssentialsUpdate/src/com/earth2me/essentials/update/PastieUpload.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/PastieUpload.java b/EssentialsUpdate/src/com/earth2me/essentials/update/PastieUpload.java new file mode 100644 index 000000000..6cad44e4d --- /dev/null +++ b/EssentialsUpdate/src/com/earth2me/essentials/update/PastieUpload.java @@ -0,0 +1,40 @@ +package com.earth2me.essentials.update; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public class PastieUpload +{ + private final transient PostToUrl connection; + + public PastieUpload() throws MalformedURLException + { + connection = new PostToUrl(new URL("http://pastie.org/pastes")); + } + + public String send(final String data) throws IOException + { + final Map<String, Object> map = new HashMap<String, Object>(); + map.put("paste[parser_id]", "19"); + map.put("paste[authorization]", "burger"); + map.put("paste[body]", data); + map.put("paste[restricted]", "1"); + final String html = connection.send(map); + final Matcher matcher = Pattern.compile("(?s).*\\?key=([a-z0-9]+).*").matcher(html); + if (matcher.matches()) + { + final String key = matcher.group(1); + return "http://pastie.org/private/" + key; + } + else + { + throw new IOException("Failed to upload to pastie.org"); + } + } +}
\ No newline at end of file |