diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-04-30 11:35:56 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-04-30 11:35:56 +0200 |
commit | f044cf1c9782b773d1d0b2d7b651ad03341382b4 (patch) | |
tree | 4e0a0ac5f716ecb7dc04b451c695904620e4c965 /src/main/Main.java | |
parent | ebe4d6c1f394b172e6170f25a68fe163cec1967e (diff) | |
download | TwitterDataAnalytics-f044cf1c9782b773d1d0b2d7b651ad03341382b4.tar.gz |
Add feature to test a URL
Diffstat (limited to 'src/main/Main.java')
-rw-r--r-- | src/main/Main.java | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/main/Main.java b/src/main/Main.java index 2b1b7ed..81c06dc 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -21,6 +21,7 @@ public class Main { * Whether to use the Bearer method or OAuth-signed requests. */ private boolean useBearer = true; + private boolean rawOutput = false; private TwitterApi api_cached; public Main(String[] args) throws IOException { @@ -53,6 +54,8 @@ public class Main { for (int i = 0; i < args.length; i++) { if ("--oauth".equals(args[i])) { useBearer = false; + } else if ("--raw".equals(args[i])) { + rawOutput = true; } else if (args[i].startsWith("-")) { throw new IllegalArgumentException("Invalid option: " + args[i]); } else { @@ -82,6 +85,7 @@ public class Main { user, tweet, + hack, help; public static Command fromString(String command) { @@ -97,6 +101,7 @@ public class Main { private final static String[] HELP = { "Global options:", " --oauth Use OAuth (PIN) instead of Bearer tokens", + " --raw Do not beautify JSON output", "", "Available commands:" }; @@ -113,6 +118,21 @@ public class Main { req = getApi().build("statuses/show"); req.param("id", getParam(0, "numerical ID of tweet")); break; + case hack: + String name = getParam(0, "resource name"); + req = getApi().build(name); + if (name.startsWith("-")) { + throw new IllegalArgumentException("Resource expected, got option"); + } + for (int i = 1; i < params.length; i++) { + String keyval[] = params[i].split("=", 2); + if (keyval.length == 2) { + req.param(keyval[0], keyval[1]); + } else { + req.param(keyval[0], ""); + } + } + break; case help: for (String line : HELP) { System.out.println(line); @@ -128,7 +148,11 @@ public class Main { System.err.println("Executing: " + req.toString()); JSONObject result = req.request(); try { - System.out.println(result.toString(4)); + if (rawOutput) { + System.out.println(result); + } else { + System.out.println(result.toString(4)); + } } catch (JSONException ex) { /* cannot happen */ System.err.println("Warning: got JSON exception: " + ex); |