├── .DS_Store ├── .gitignore ├── .idea ├── .gitignore ├── artifacts │ └── .gitignore ├── copyright │ └── .gitignore ├── dictionaries │ └── .gitignore ├── libraries │ └── .gitignore └── scopes │ └── .gitignore ├── .settings └── .gitignore ├── PastebinAPI.iml ├── README.md ├── out └── production │ ├── PastebinAPI │ └── me │ │ └── nrubin29 │ │ └── pastebinapi │ │ ├── AccountType.class │ │ ├── CreatePaste.class │ │ ├── ExpireDate.class │ │ ├── Format.class │ │ ├── Parser.class │ │ ├── Paste.class │ │ ├── PastebinAPI.class │ │ ├── PastebinException.class │ │ ├── PrivacyLevel.class │ │ ├── User.class │ │ ├── Utils.class │ │ └── example │ │ └── Example.class │ └── SkypeAPI │ └── me │ └── pogostick29 │ └── skypeapi │ └── .gitignore └── src └── me └── nrubin29 └── pastebinapi ├── AccountType.java ├── CreatePaste.java ├── ExpireDate.java ├── Format.java ├── Parser.java ├── Paste.java ├── PastebinAPI.java ├── PastebinException.java ├── Poster.java ├── PrivacyLevel.java ├── User.java └── example └── Example.java /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /*.classpath 2 | /*.project 3 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | /*.name 2 | /*.xml 3 | -------------------------------------------------------------------------------- /.idea/artifacts/.gitignore: -------------------------------------------------------------------------------- 1 | /*.xml 2 | -------------------------------------------------------------------------------- /.idea/copyright/.gitignore: -------------------------------------------------------------------------------- 1 | /*.xml 2 | -------------------------------------------------------------------------------- /.idea/dictionaries/.gitignore: -------------------------------------------------------------------------------- 1 | /*.xml 2 | -------------------------------------------------------------------------------- /.idea/libraries/.gitignore: -------------------------------------------------------------------------------- 1 | /*.xml 2 | -------------------------------------------------------------------------------- /.idea/scopes/.gitignore: -------------------------------------------------------------------------------- 1 | /*.xml 2 | -------------------------------------------------------------------------------- /.settings/.gitignore: -------------------------------------------------------------------------------- 1 | /org.eclipse.jdt.core.prefs 2 | -------------------------------------------------------------------------------- /PastebinAPI.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 30 | 189 | 202 | 203 | 204 | 205 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PastebinAPI (1.2.3) 2 | =========== 3 | 4 | **A complete API for Pastebin written in Java.** 5 | 6 | Get your Pastebin API key [here](http://pastebin.com/api#1). 7 | 8 | Learn how to use PastebinAPI [here](https://github.com/nrubin29/PastebinAPI/blob/master/src/me/nrubin29/pastebinapi/example/Example.java). 9 | 10 | Changelog 11 | =========== 12 | * **1.2.3** 13 | * Changes how posting works internally. The new method is much cleaner. 14 | 15 | * **1.2.2** 16 | * You can now create a paste and give it a File. It will create the paste using the text from that file. 17 | 18 | * **1.2.1** 19 | * A bunch of enhancements. 20 | 21 | * **1.2** 22 | * PastebinAPI can now do everything the official Pastebin API can. 23 | 24 | * **1.1** 25 | * Adds enums for expire date, format, and privacy level. 26 | * Renames PastebinPasteContext to CreatePaste. 27 | * Fixes example. 28 | 29 | * **1.0.1** 30 | * Added example. 31 | 32 | * **1.0** 33 | * Initial upload. It works. 34 | -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/AccountType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/AccountType.class -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/CreatePaste.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/CreatePaste.class -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/ExpireDate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/ExpireDate.class -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/Format.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/Format.class -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/Parser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/Parser.class -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/Paste.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/Paste.class -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/PastebinAPI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/PastebinAPI.class -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/PastebinException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/PastebinException.class -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/PrivacyLevel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/PrivacyLevel.class -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/User.class -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/Utils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/Utils.class -------------------------------------------------------------------------------- /out/production/PastebinAPI/me/nrubin29/pastebinapi/example/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrubin29/PastebinAPI/23fc4be5dacec4a405f2a6386411d19fa1099ecc/out/production/PastebinAPI/me/nrubin29/pastebinapi/example/Example.class -------------------------------------------------------------------------------- /out/production/SkypeAPI/me/pogostick29/skypeapi/.gitignore: -------------------------------------------------------------------------------- 1 | /*.class 2 | -------------------------------------------------------------------------------- /src/me/nrubin29/pastebinapi/AccountType.java: -------------------------------------------------------------------------------- 1 | package me.nrubin29.pastebinapi; 2 | 3 | public enum AccountType { 4 | NORMAL(0), PRO(1); 5 | 6 | public static AccountType valueOf(int i) { 7 | switch(i) { 8 | case 0: return NORMAL; 9 | case 1: return PRO; 10 | default: return null; 11 | } 12 | } 13 | 14 | private int i; 15 | 16 | AccountType(int i) { 17 | this.i = i; 18 | } 19 | 20 | public int getI() { 21 | return i; 22 | } 23 | } -------------------------------------------------------------------------------- /src/me/nrubin29/pastebinapi/CreatePaste.java: -------------------------------------------------------------------------------- 1 | package me.nrubin29.pastebinapi; 2 | 3 | import java.io.*; 4 | 5 | public class CreatePaste { 6 | 7 | private PastebinAPI api; 8 | 9 | protected CreatePaste(PastebinAPI api) { 10 | this.api = api; 11 | } 12 | 13 | private User user; 14 | private File file; 15 | private String text, name; 16 | private Format format; 17 | private PrivacyLevel privacylevel = PrivacyLevel.PUBLIC; 18 | private ExpireDate expiredate = ExpireDate.NEVER; 19 | 20 | protected CreatePaste withUser(User user) { 21 | this.user = user; 22 | return this; 23 | } 24 | 25 | /** 26 | * Sets the text of the paste. If you use this method, you cannot use withFile. 27 | * @param text The text of the paste. 28 | * @return The same instance of CreatePaste with the text set as given. 29 | */ 30 | public CreatePaste withText(String text) { 31 | this.text = text; 32 | return this; 33 | } 34 | 35 | /** 36 | * Sets the text of the paste to the contents of the file. If you use this method, you cannot use withText. 37 | * @param file The file from which to get the text of the paste. 38 | * @return The same instance of CreatePaste with the file set as given. 39 | */ 40 | public CreatePaste withFile(File file) { 41 | this.file = file; 42 | return this; 43 | } 44 | 45 | /** 46 | * Sets the name of the paste. 47 | * @param pastename The name of the paste. 48 | * @return The same instance of CreatePaste with the name set as given. 49 | */ 50 | public CreatePaste withName(String pastename) { 51 | this.name = pastename; 52 | return this; 53 | } 54 | 55 | /** 56 | * Sets the paste format. 57 | * @param pasteformat The paste format. 58 | * @return The same instance of CreatePaste with the format set as given. 59 | */ 60 | public CreatePaste withFormat(Format pasteformat) { 61 | this.format = pasteformat; 62 | return this; 63 | } 64 | 65 | /** 66 | * Sets the expiration date of the paste. 67 | * @param pasteexpiredate The expiration date of the paste. 68 | * @return The same instance of CreatePaste with the expiration date set as given. 69 | */ 70 | public CreatePaste withExpireDate(ExpireDate pasteexpiredate) { 71 | this.expiredate = pasteexpiredate; 72 | return this; 73 | } 74 | 75 | /** 76 | * Sets the privacy level of the paste. 77 | * @param privacylevel The privacy level of the paste. 78 | * @return The same instance of CreatePaste with the privacy level set as given. 79 | */ 80 | public CreatePaste withPrivacyLevel(PrivacyLevel privacylevel) { 81 | this.privacylevel = privacylevel; 82 | return this; 83 | } 84 | 85 | /** 86 | * Posts using the information given. You should probably run this in a new thread. 87 | * @return The URL of the paste. 88 | * @throws PastebinException Thrown if an error occurs; contains the error message returned by Pastebin. 89 | * @throws IOException Thrown if you use withFile instead of withText and an IOException is thrown. 90 | */ 91 | public String post() throws PastebinException, IOException { 92 | Poster p = api.getNewPoster(); 93 | 94 | p.withArg("api_option", "paste"); 95 | if (text != null) p.withArg("api_paste_code", text); 96 | else if (file != null) { 97 | StringBuffer contents = new StringBuffer(); 98 | BufferedReader read = new BufferedReader(new FileReader(file)); 99 | while(read.ready()) contents.append(read.readLine() + "\n"); 100 | read.close(); 101 | p.withArg("api_paste_code", contents.toString()); 102 | } 103 | if (name != null) p.withArg("api_paste_name", name); 104 | if (format != null) p.withArg("api_paste_format", format.getFormat()); 105 | p.withArg("api_paste_expire_date", expiredate.getCode()); 106 | p.withArg("api_paste_private", privacylevel.getLevel()); 107 | if (user != null) p.withArg("api_user_key", user.getUserKey()); 108 | 109 | return p.post()[0]; 110 | } 111 | } -------------------------------------------------------------------------------- /src/me/nrubin29/pastebinapi/ExpireDate.java: -------------------------------------------------------------------------------- 1 | package me.nrubin29.pastebinapi; 2 | 3 | public enum ExpireDate { 4 | 5 | NEVER("N"), 6 | TEN_MINUTES("10M"), 7 | ONE_HOUR("1H"), 8 | ONE_DAY("1D"), 9 | ONE_WEEK("1W"), 10 | TWO_WEEKS("2W"), 11 | ONE_MONTH("1M"); 12 | 13 | private String code; 14 | 15 | private ExpireDate(String code) { 16 | this.code = code; 17 | } 18 | 19 | public String getCode() { 20 | return code; 21 | } 22 | } -------------------------------------------------------------------------------- /src/me/nrubin29/pastebinapi/Format.java: -------------------------------------------------------------------------------- 1 | package me.nrubin29.pastebinapi; 2 | 3 | public enum Format { 4 | 5 | FourCS("4cs"), 6 | SixFiveZeroTwo_ACME_Cross_Assembler("6502acme"), 7 | SixFiveZeroTwo_Kick_Assember("6502kickass"), 8 | SixFiveZeroTwo_TAS_64TASS("6502tasm"), 9 | ABAP("abap"), 10 | ActionScript("actionscript"), 11 | ActionScript3("actionscript3"), 12 | Ada("ada"), 13 | ALGOL68("algol68"), 14 | ApacheLog("apache"), 15 | AppleScript("applescript"), 16 | API_Sources("apt_sources"), 17 | ARM("arm"), 18 | ASM_NASM("asm"), 19 | ASP("asp"), 20 | Asymptote("asymptote"), 21 | Autoconf("autoconf"), 22 | Autohotkey("autohotkey"), 23 | AutoIt("autoit"), 24 | Avisynth("avisynth"), 25 | Awk("awk"), 26 | BASCOM_AVR("basconavr"), 27 | Bash("bash"), 28 | Basic4GL("basic4gl"), 29 | BibTeX("bibtex"), 30 | Blitz_Basic("blitzbasic"), 31 | BNF("bnf"), 32 | BOO("boo"), 33 | BrainFuck("bf"), 34 | C("c"), 35 | C_for_Macs("c_mac"), 36 | C_Intermediate_Language("cil"), 37 | CSharp("csharp"), 38 | CPlusPlus("cpp"), 39 | CPlusPlus_QT("cpp-qt"), 40 | C_Loadrunner("c_loadrunner"), 41 | CAD_DCL("caddcl"), 42 | CAD_Lisp("cadlisp"), 43 | CFDG("cfdg"), 44 | ChaiScript("chaiscript"), 45 | Clojure("clojure"), 46 | CloneC("klonec"), 47 | CloneCPlusPlus("klonecpp"), 48 | CMake("cmake"), 49 | COBOL("cobol"), 50 | CoffeeScript("coffeescript"), 51 | ColdFusion("cfm"), 52 | CSS("css"), 53 | Cuesheet("cuesheet"), 54 | D("d"), 55 | DCL("dcl"), 56 | DCPU_16("dcpu16"), 57 | DCS("dcs"), 58 | Delphi("delphi"), 59 | Delphi_Prism_Oxygene("oxygene"), 60 | Diff("diff"), 61 | DIV("div"), 62 | DOS("dos"), 63 | DOT("dot"), 64 | E("e"), 65 | ECMAScript("ecmascript"), 66 | Eiffel("eiffel"), 67 | Email("email"), 68 | EPC("epc"), 69 | Erlang("erlang"), 70 | FSharp("fsharp"), 71 | Falcon("falcon"), 72 | FO_Language("fo"), 73 | Formula_One("f1"), 74 | Fortran("fortran"), 75 | FreeBasic("freebasic"), 76 | FreeSWITCH("freeswitch"), 77 | GAMBAS("gambas"), 78 | Game_Maker("gml"), 79 | GDB("gdb"), 80 | Genero("genero"), 81 | Genie("genie"), 82 | GetText("gettext"), 83 | Go("go"), 84 | Groovy("groovy"), 85 | GwBasic("gwbasic"), 86 | Haskell("haskell"), 87 | Haxe("haxe"), 88 | HicEst("hicest"), 89 | HQ9_Plus("hq9plus"), 90 | HTML("html4strict"), 91 | HTML_5("html5"), 92 | Icon("icon"), 93 | IDL("idl"), 94 | INI_File("ini"), 95 | Inno_Script("inno"), 96 | INTERCAL("intercal"), 97 | IO("io"), 98 | J("j"), 99 | Java("java"), 100 | Java_5("java5"), 101 | JavaScript("javascript"), 102 | jQuery("jQuery"), 103 | KiXtart("kixtart"), 104 | Latex("latex"), 105 | LDIF("ldif"), 106 | Liberty_BASIC("lb"), 107 | Linden_Scripting("lsl2"), 108 | Lisp("lisp"), 109 | LLVM("llvm"), 110 | Loco_Basic("locobasic"), 111 | Logtalk("logtalk"), 112 | LOL_Code("lolcode"), 113 | Lotus_Formulas("lotusformulas"), 114 | Lotus_Script("lotusscript"), 115 | LScript("lscript"), 116 | Lua("lua"), 117 | M68000_Assembler("m68k"), 118 | MagikSF("magiksf"), 119 | Make("make"), 120 | MapBasic("mapbasic"), 121 | MatLab("matlab"), 122 | mIRC("mirc"), 123 | MIX_Assembler("mmix"), 124 | Modula_2("modula2"), 125 | Modula_3("modula3"), 126 | Motorola_68000_HiSoft_Dev("68000devpac"), 127 | MPASM("mpasm"), 128 | MXML("mxml"), 129 | MySQL("mysql"), 130 | Nagios("nagios"), 131 | newLISP("newlisp"), 132 | None("text"), 133 | NullSoft_Installer("nsis"), 134 | Oberon_2("oberon2"), 135 | Objeck_Programming_Language("objeck"), 136 | Objective_C("objc"), 137 | OCaml_Brief("ocaml-brief"), 138 | OCaml("ocaml"), 139 | Octave("octave"), 140 | OpenBSD_PACKET_FILLER("pf"), 141 | OpenGL_Shading("glsl"), 142 | Openoffice_BASIC("oobas"), 143 | Oracle_11("oracle11"), 144 | Oracle_8("oracle8"), 145 | Oz("oz"), 146 | ParaSail("parasail"), 147 | PARI_GP("parigp"), 148 | Pascal("pascal"), 149 | PAWN("pawn"), 150 | PCRE("pcre"), 151 | Per("per"), 152 | Perl("perl"), 153 | Perl_6("perl6"), 154 | PHP("php"), 155 | PHP_Brief("php-brief"), 156 | Pic_16("pic16"), 157 | Pike("pike"), 158 | Pixel_Bender("pixelbender"), 159 | PL_SQL("plsql"), 160 | PostgreSQL("postgresql"), 161 | POV_Ray("povray"), 162 | Power_Shell("powershell"), 163 | PowerBuilder("powerbuilder"), 164 | ProFTPd("proftpd"), 165 | Progress("progress"), 166 | Prolog("prolog"), 167 | Properties("properties"), 168 | ProviteX("providex"), 169 | PureBasic("purebasic"), 170 | PyCon("pycon"), 171 | Python("python"), 172 | Phthon_for_S60("pys60"), 173 | q_kdbplus("q"), 174 | QBasic("qbasic"), 175 | R("rsplus"), 176 | Rails("rails"), 177 | REBOL("rebol"), 178 | REG("reg"), 179 | Rexx("rexx"), 180 | Robots("robots"), 181 | RPM_Spec("rpmspec"), 182 | Ruby("ruby"), 183 | Ruby_Gnuplot("gnuplot"), 184 | SAS("sas"), 185 | Scala("scala"), 186 | Sceme("scheme"), 187 | Scilab("scilab"), 188 | SdlBasic("sdlbasic"), 189 | Smalltalk("smalltalk"), 190 | Smarty("smarty"), 191 | SPARK("spark"), 192 | SPARQL("sparql"), 193 | SQL("sql"), 194 | StoneScript("stonescript"), 195 | SystemVerilog("systemverilog"), 196 | T_SQL("tsql"), 197 | TCL("tcl"), 198 | Tera_Term("teraterm"), 199 | thinBasic("thinkbasic"), 200 | TypoScript("typoscript"), 201 | Unicon("unicon"), 202 | UnrealScript("uscript"), 203 | UPC("upc"), 204 | Urbi("urbi"), 205 | Vala("vala"), 206 | VB_NET("vbnet"), 207 | Vedit("vedit"), 208 | VeriLog("verilog"), 209 | VHDL("vhdl"), 210 | VIM("vim"), 211 | Visual_Pro_Log("visualprolog"), 212 | VisualBasic("vb"), 213 | VisualFoxPro("visualfoxpro"), 214 | WhiteSpace("whitespace"), 215 | WHOIS("whois"), 216 | Winbatch("winbatch"), 217 | XBasic("xbasic"), 218 | XML("xml"), 219 | Xorg_Config("xorg_conf"), 220 | XPP("xpp"), 221 | YAML("yaml"), 222 | Z80_Assembler("z80"), 223 | ZXBasic("zxbasic"); 224 | 225 | private String format; 226 | 227 | private Format(String format) { 228 | this.format = format; 229 | } 230 | 231 | public String getFormat() { 232 | return format; 233 | } 234 | } -------------------------------------------------------------------------------- /src/me/nrubin29/pastebinapi/Parser.java: -------------------------------------------------------------------------------- 1 | package me.nrubin29.pastebinapi; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.HashMap; 6 | 7 | public class Parser { 8 | 9 | private String[] args; 10 | private ArrayList keys = new ArrayList(); 11 | private HashMap vals = new HashMap(); 12 | 13 | protected Parser(String[] args) { 14 | this.args = args; 15 | } 16 | 17 | public void addKey(String... keyarray) { 18 | keys.addAll(Arrays.asList(keyarray)); 19 | } 20 | 21 | public HashMap parse() { 22 | for (String arg : args) { 23 | arg = arg.substring(arg.indexOf("_") + 1, arg.lastIndexOf("<")); 24 | for (String key : keys) { 25 | if (arg.startsWith("key")) vals.put(key, sub(arg)); 26 | } 27 | } 28 | return vals; 29 | } 30 | 31 | private String sub(String str) { 32 | return str.substring(str.indexOf(">") + 1); 33 | } 34 | } -------------------------------------------------------------------------------- /src/me/nrubin29/pastebinapi/Paste.java: -------------------------------------------------------------------------------- 1 | package me.nrubin29.pastebinapi; 2 | 3 | import java.net.MalformedURLException; 4 | import java.net.URL; 5 | import java.util.ArrayList; 6 | import java.util.Date; 7 | 8 | public class Paste { 9 | 10 | private PastebinAPI api; 11 | private String key, name; 12 | private int size, hits; 13 | private Date date, expiredate; 14 | private PrivacyLevel level; 15 | private Format format; 16 | private URL url; 17 | 18 | protected Paste(PastebinAPI api, ArrayList args) throws PastebinException { 19 | this.api = api; 20 | for (String arg : args) { 21 | arg = arg.substring(arg.indexOf("_") + 1, arg.lastIndexOf("<")); 22 | if (arg.startsWith("key")) key = sub(arg); 23 | else if (arg.startsWith("date")) date = new Date(Long.valueOf(sub(arg))); 24 | else if (arg.startsWith("title")) name = sub(arg); 25 | else if (arg.startsWith("size")) size = Integer.valueOf(sub(arg)); 26 | else if (arg.startsWith("expire_date")) expiredate = new Date(Long.valueOf(sub(arg))); 27 | else if (arg.startsWith("private")) level = PrivacyLevel.valueOf(Integer.parseInt(sub(arg))); 28 | else if (arg.startsWith("format_long")) format = Format.valueOf(sub(arg)); 29 | else if (arg.startsWith("url")) { 30 | try { 31 | url = new URL(sub(arg)); 32 | } catch (MalformedURLException e) { 33 | throw new PastebinException("Invalid URL returned!"); 34 | } 35 | } else if (arg.startsWith("hits")) hits = Integer.valueOf(sub(arg)); 36 | } 37 | } 38 | 39 | private String sub(String str) { 40 | return str.substring(str.indexOf(">") + 1); 41 | } 42 | 43 | /** 44 | * Gets the paste key. 45 | * @return The paste key. 46 | */ 47 | public String getKey() { 48 | return key; 49 | } 50 | 51 | /** 52 | * Gets the paste name. 53 | * @return The paste name. 54 | */ 55 | public String getName() { 56 | return name; 57 | } 58 | 59 | /** 60 | * Gets the paste size. 61 | * @return The paste size. 62 | */ 63 | public int getSize() { 64 | return size; 65 | } 66 | 67 | /** 68 | * Gets the number of paste hits. 69 | * @return The number of paste hits. 70 | */ 71 | public int getHits() { 72 | return hits; 73 | } 74 | 75 | /** 76 | * Gets the date of creation. 77 | * @return The date of creation. 78 | */ 79 | public Date getDate() { 80 | return new Date(date.getTime()); 81 | } 82 | 83 | /** 84 | * Gets the date of expiration. 85 | * @return The date of expiration. 86 | */ 87 | public Date getExpireDate() { 88 | return new Date(expiredate.getTime()); 89 | } 90 | 91 | /** 92 | * Gets the privacy level of the paste. 93 | * @return A value from the PrivacyLevel enum representing the paste privacy level. 94 | * @see PrivacyLevel 95 | */ 96 | public PrivacyLevel getLevel() { 97 | return level; 98 | } 99 | 100 | /** 101 | * Gets the format of the paste. 102 | * @return A value from the Format enum representing the paste format. 103 | * @see Format 104 | */ 105 | public Format getFormat() { 106 | return format; 107 | } 108 | 109 | /** 110 | * Gets the URL of the paste. 111 | * @return The URL of the paste. 112 | */ 113 | public URL getURL() { 114 | return url; 115 | } 116 | 117 | /** 118 | * Gets the raw text of the paste. 119 | * @return A String[] containing all lines of the paste. 120 | * @throws PastebinException Thrown if an error occurs; contains the error message. 121 | */ 122 | public String[] getText() throws PastebinException { 123 | Poster p = api.getNewPoster(); 124 | try { return p.withURL(new URL("http://pastebin.com/raw.php?i=" + key)).post(); } 125 | catch (MalformedURLException ignored) { return null; } 126 | } 127 | 128 | /** 129 | * Gets the raw text of the paste. 130 | * @param lineSeparator The text that separates each line of the raw text. 131 | * @return A String containing all lines of the paste separated by the lineSeparator. 132 | * @throws PastebinException Thrown if an error occurs; contains the error message. 133 | */ 134 | public String getText(String lineSeparator) throws PastebinException { 135 | StringBuffer result = new StringBuffer(); 136 | 137 | for (String str : getText()) { 138 | result.append(str + lineSeparator); 139 | } 140 | 141 | return result.toString(); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/me/nrubin29/pastebinapi/PastebinAPI.java: -------------------------------------------------------------------------------- 1 | package me.nrubin29.pastebinapi; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class PastebinAPI { 6 | 7 | private String apikey; 8 | 9 | /** 10 | * Constructor for PastebinAPI. 11 | * @param apikey Your API key. Get yours from http://pastebin.com/api/ 12 | */ 13 | public PastebinAPI(String apikey) { 14 | this.apikey = apikey; 15 | } 16 | 17 | protected Poster getNewPoster() { 18 | return new Poster(this); 19 | } 20 | 21 | /** 22 | * Get the supplied API key. 23 | * @return The supplied API key. 24 | */ 25 | public String getAPIKey() { 26 | return apikey; 27 | } 28 | 29 | /** 30 | * Begin constructing a paste. To create a paste with a user, use the createPaste() method in the User class. 31 | * @return A new instance of the CreatePaste class. 32 | */ 33 | public CreatePaste createPaste() { 34 | return new CreatePaste(this); 35 | } 36 | 37 | /** 38 | * Get a new User with a username and password. 39 | * @param username The username. 40 | * @param password The password. 41 | * @return A new instance of User with the username and password authenticated. 42 | */ 43 | public User getUser(String username, String password) throws PastebinException { 44 | return new User(this, username, password); 45 | } 46 | 47 | /** 48 | * Get a Paste[] containing all trending pastes. 49 | * @return A Paste[] containing all trending pastes. 50 | * @throws PastebinException Thrown if an error occurs. 51 | */ 52 | public Paste[] getTrendingPastes() throws PastebinException { 53 | Poster p = getNewPoster(); 54 | p.withArg("api_option", "trends"); 55 | return parse(p.post()); 56 | } 57 | 58 | protected Paste[] parse(String[] args) throws PastebinException { 59 | ArrayList pastes = new ArrayList(); 60 | ArrayList current = new ArrayList(); 61 | 62 | for (String str : args) { 63 | if (str != null && !str.equals("")) { 64 | if (str.equals("")) { 65 | pastes.add(new Paste(this, current)); 66 | current = new ArrayList<>(); 67 | } 68 | else if (str.startsWith(" args = new HashMap<>(); 15 | private URL url; 16 | 17 | protected Poster(PastebinAPI api) { 18 | this.api = api; 19 | } 20 | 21 | protected Poster withArg(String key, Object value) { 22 | args.put(key, value); 23 | return this; 24 | } 25 | 26 | protected Poster withURL(URL url) { 27 | this.url = url; 28 | return this; 29 | } 30 | 31 | protected String[] post() { 32 | try { 33 | StringBuffer a = new StringBuffer("api_dev_key=" + api.getAPIKey()); 34 | 35 | for (Map.Entry e : args.entrySet()) { 36 | a.append("&" + e.getKey() + "=" + e.getValue()); 37 | } 38 | 39 | String text = a.toString(); 40 | 41 | if (url == null) url = new URL("http://pastebin.com/api/api_post.php"); 42 | 43 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 44 | connection.setDoOutput(true); 45 | connection.setDoInput(true); 46 | connection.setInstanceFollowRedirects(false); 47 | connection.setRequestMethod("POST"); 48 | connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 49 | connection.setRequestProperty("charset", "utf-8"); 50 | connection.setRequestProperty("Content-Length", "" + text.getBytes().length); 51 | connection.setUseCaches(false); 52 | 53 | DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); 54 | wr.writeBytes(text); 55 | wr.flush(); 56 | wr.close(); 57 | 58 | connection.disconnect(); 59 | 60 | Scanner s = new Scanner(connection.getInputStream()); 61 | 62 | ArrayList output = new ArrayList(); 63 | 64 | while (s.hasNext()) { 65 | String next = s.nextLine(); 66 | output.add(next); 67 | } 68 | 69 | if (output.get(0).startsWith("Bad API request")) { 70 | throw new PastebinException(output.get(0)); 71 | } 72 | 73 | return output.toArray(new String[output.size()]); 74 | } 75 | catch (Exception e) { e.printStackTrace(); } 76 | 77 | return null; 78 | } 79 | } -------------------------------------------------------------------------------- /src/me/nrubin29/pastebinapi/PrivacyLevel.java: -------------------------------------------------------------------------------- 1 | package me.nrubin29.pastebinapi; 2 | 3 | public enum PrivacyLevel { 4 | 5 | PUBLIC(0), 6 | UNLISTED(1), 7 | PRIVATE(2); 8 | 9 | public static PrivacyLevel valueOf(int i) { 10 | switch (i) { 11 | case 0: return PUBLIC; 12 | case 1: return UNLISTED; 13 | case 2: return PRIVATE; 14 | default: return null; 15 | } 16 | } 17 | 18 | private int level; 19 | 20 | private PrivacyLevel(int level) { 21 | this.level = level; 22 | } 23 | 24 | public int getLevel() { 25 | return level; 26 | } 27 | } -------------------------------------------------------------------------------- /src/me/nrubin29/pastebinapi/User.java: -------------------------------------------------------------------------------- 1 | package me.nrubin29.pastebinapi; 2 | 3 | import java.net.MalformedURLException; 4 | import java.net.URL; 5 | import java.util.HashMap; 6 | 7 | public class User { 8 | 9 | private PastebinAPI api; 10 | private String username, password, userkey; 11 | private ExpireDate expire; 12 | private URL avatarURL, website; 13 | private PrivacyLevel privacyLevel; 14 | private String email, location; 15 | private AccountType type; 16 | 17 | protected User(PastebinAPI api, String username, String password) throws PastebinException { 18 | this.api = api; 19 | this.username = username; 20 | this.password = password; 21 | 22 | Poster login = api.getNewPoster(); 23 | 24 | try { login.withURL(new URL("http://pastebin.com/api/api_login.php")); } 25 | catch (MalformedURLException ignored) { } 26 | 27 | login.withArg("api_user_name", username); 28 | login.withArg("api_user_password", password); 29 | 30 | userkey = login.post()[0]; 31 | 32 | Poster info = api.getNewPoster(); 33 | info.withArg("api_user_key", userkey); 34 | info.withArg("api_option", "userdetails"); 35 | 36 | Parser p = new Parser(info.post()); 37 | p.addKey("expiration, avatar_url", "private", "website", "email", "location", "account_type"); 38 | HashMap ret = p.parse(); 39 | for (String key : ret.keySet()) { 40 | if (key.equals("expiration")) expire = ExpireDate.valueOf(key); 41 | else if (key.equals("avatar_url")) avatarURL = getURL(key); 42 | else if (key.equals("private")) privacyLevel = PrivacyLevel.valueOf(Integer.parseInt(key)); 43 | else if (key.equals("website")) website = getURL(key); 44 | else if (key.equals("email")) email = key; 45 | else if (key.equals("location")) location = key; 46 | else if (key.equals("account_type")) type = AccountType.valueOf(Integer.parseInt(key)); 47 | } 48 | } 49 | 50 | private URL getURL(String url) { 51 | try { return new URL(url); } 52 | catch (Exception e) { e.printStackTrace(); return null; } 53 | } 54 | 55 | /** 56 | * Get all user pastes. 57 | * @return An ArrayList containing all pastes. 58 | * @throws PastebinException Thrown if an error occurs; contains the error message. 59 | */ 60 | public Paste[] getPastes() throws PastebinException { 61 | return getPastes(Integer.MAX_VALUE); 62 | } 63 | 64 | /** 65 | * Get all user pastes. 66 | * @param results_limit Amount of results to limit to. 67 | * @return An ArrayList containing all pastes. 68 | * @throws PastebinException Thrown if an error occurs; contains the error message. 69 | */ 70 | public Paste[] getPastes(int results_limit) throws PastebinException { 71 | return api.parse(api.getNewPoster().withArg("api_results_limit", results_limit).withArg("api_option", "list").post()); 72 | } 73 | 74 | /** 75 | * Remove a user's paste 76 | * @param pasteKey The paste's key. 77 | * @throws PastebinException Thrown if an error occurs; contains the error message. 78 | */ 79 | public void removePaste(String pasteKey) throws PastebinException { 80 | api.getNewPoster().withArg("api_user_key", userkey).withArg("api_paste_key", pasteKey).withArg("api_option", "delete"); 81 | } 82 | 83 | /** 84 | * Remove a user's paste 85 | * @param p The paste to remove. 86 | * @throws PastebinException Thrown if an error occurs; contains the error message. 87 | */ 88 | public void removePaste(Paste p) throws PastebinException { 89 | removePaste(p.getKey()); 90 | } 91 | 92 | /** 93 | * Begin constructing a paste. 94 | * @return A new instance of the CreatePaste class. 95 | */ 96 | public CreatePaste createPaste() { 97 | return new CreatePaste(api).withUser(this); 98 | } 99 | 100 | /** 101 | * Get the user's username. 102 | * @return The user's username. 103 | */ 104 | public String getUsername() { 105 | return username; 106 | } 107 | 108 | /** 109 | * Get the user's password. 110 | * @return The user's password. 111 | */ 112 | public String getPassword() { 113 | return password; 114 | } 115 | 116 | protected String getUserKey() { 117 | return userkey; 118 | } 119 | 120 | /** 121 | * Get the user's expire date. 122 | * @return A value from the ExpireDate enum representing the user's expire date. 123 | */ 124 | public ExpireDate getExpireDate() { 125 | return expire; 126 | } 127 | 128 | /** 129 | * Get the user's avatar URL. 130 | * @return The user's avatar URL. 131 | */ 132 | public URL getAvatarURL() { 133 | return avatarURL; 134 | } 135 | 136 | /** 137 | * Get the user's website. 138 | * @return The user's website. 139 | */ 140 | public URL getWebsite() { 141 | return website; 142 | } 143 | 144 | /** 145 | * Get the user's privacy level. 146 | * @return A value from the PrivacyLevel enum representing the user's privacy level. 147 | */ 148 | public PrivacyLevel getPrivacyLevel() { 149 | return privacyLevel; 150 | } 151 | 152 | /** 153 | * Get the user's email. 154 | * @return The user's email. 155 | */ 156 | public String getEmail() { 157 | return email; 158 | } 159 | 160 | /** 161 | * Get the user's location. 162 | * @return The user's location. 163 | */ 164 | public String getLocation() { 165 | return location; 166 | } 167 | 168 | /** 169 | * Get the user's account type. 170 | * @return A value from the AccountType enum representing the user's account type. 171 | */ 172 | public AccountType getAccountType() { 173 | return type; 174 | } 175 | } -------------------------------------------------------------------------------- /src/me/nrubin29/pastebinapi/example/Example.java: -------------------------------------------------------------------------------- 1 | package me.nrubin29.pastebinapi.example; 2 | 3 | import me.nrubin29.pastebinapi.*; 4 | 5 | import java.io.IOException; 6 | import java.util.ArrayList; 7 | 8 | public class Example { 9 | 10 | public static void main(String[] args) throws PastebinException, IOException /* You'll probably want to handle these exceptions. */ { 11 | 12 | /* PastebinAPI initialization */ 13 | 14 | PastebinAPI api = new PastebinAPI("Put your developer key here."); 15 | 16 | /* Getting a user */ 17 | 18 | User user = api.getUser("username", "password"); // Without get an instance of User, 19 | // you can only get trending pastes and paste as a guest. 20 | 21 | /* Getting user information */ 22 | 23 | String userEmail = user.getEmail(); // There are plenty of other get methods in the User class. 24 | 25 | /* Creating a paste */ 26 | 27 | CreatePaste paste = user.createPaste() // You can call api.createPaste() to create a paste as a guest. 28 | .withName("Paste name") 29 | .withFormat(Format.None) 30 | .withPrivacyLevel(PrivacyLevel.PUBLIC) 31 | .withExpireDate(ExpireDate.NEVER) 32 | .withText("Text to paste"); // You can also call withFile and give it a File. It will paste the text from that file. 33 | 34 | String url = paste.post(); // The post method posts the paste and returns the URL. 35 | // If you use a File in the paste, an IOException may be thrown. 36 | 37 | /* Getting pastes from a user */ 38 | 39 | Paste[] pastes = user.getPastes(); // You can also specify a limit on the number of results returned. 40 | 41 | /* Getting raw text from a paste */ 42 | 43 | Paste firstPaste = pastes[0]; 44 | 45 | String[] rawText = firstPaste.getText(); // You can also get a String containing the raw text by adding a String to the getText() method. 46 | // There are plenty of other get methods in the Paste class. 47 | 48 | /* Removing a user's paste */ 49 | 50 | user.removePaste("pastekey"); // You can also give it a Paste. 51 | 52 | /* Get trending pastes */ 53 | 54 | Paste[] trending = api.getTrendingPastes(); 55 | 56 | // NOTE: Various methods may throw a PastebinException, which will contain the error message Pastebin returns. 57 | } 58 | } 59 | 60 | --------------------------------------------------------------------------------