/** @param args */ public static void main(String[] args) { try { // Authenticate System.out.println("Creating user..."); User user = new User(Config.username, Config.api_key); // Create the definition Definition d = user.createDefinition("interaction.sample < 1.0"); // Create the consumer System.out.println("Getting the consumer..."); StreamConsumer consumer = d.getConsumer(StreamConsumer.TYPE_HTTP, new Deletes()); // And start consuming System.out.println("Consuming..."); System.out.println("--"); consumer.consume(); } catch (EInvalidData e) { System.out.print("InvalidData: "); System.out.println(e.getMessage()); } catch (ECompileFailed e) { System.out.print("CompileFailed: "); System.out.println(e.getMessage()); } catch (EAccessDenied e) { System.out.print("AccessDenied: "); System.out.println(e.getMessage()); } }
/** * Handle status notifications * * @param StreamConsumer consumer The consumer object. * @param String type The status notification type. * @param JSONdn info The notification data. */ public void onStatus(StreamConsumer consumer, String type, JSONdn info) { if (type.equalsIgnoreCase("info") && info.has("progress")) { try { System.err.println(info.getStringVal("progress") + "% done"); } catch (EInvalidData e) { // Failed to get the progress string, ignore it } } else { try { System.err.println("STATUS: " + type + " " + info.getStringVal("message")); } catch (EInvalidData e1) { System.err.println("STATUS: " + type); } try { _h.reloadData(); System.err.println( "STATUS: " + _h.getStatus() + " - " + String.valueOf(_h.getProgress()) + "% done"); if (_h.getStatus().equals("succeeded")) { consumer.stop(); } } catch (EInvalidData e) { System.err.println("reloadData: EInvalidData: " + e.getMessage()); } catch (EAccessDenied e) { System.err.println("reloadData: EAccessDenied: " + e.getMessage()); } catch (EAPIError e) { System.err.println("reloadData: EAPIError: " + e.getMessage()); } } }
public void testGetTotalDPU() { Definition def = new Definition(user, DataForTests.definition); try { assertEquals("Definition string not set correctly", def.get(), DataForTests.definition); } catch (EInvalidData e1) { fail("EInvalidData: " + e1.getMessage()); } try { double dpu = def.getTotalDPU(); assertTrue(dpu > 0); } catch (EInvalidData e) { fail("InvalidData: " + e.getMessage()); } catch (EAccessDenied e) { fail("AccessDenied: " + e.getMessage()); } }
public void testGetCreatedAt() { Definition def = new Definition(user, DataForTests.definition); try { assertEquals("Definition string not set correctly", def.get(), DataForTests.definition); } catch (EInvalidData e1) { fail("EInvalidData: " + e1.getMessage()); } try { Date d = def.getCreatedAt(); assertNotNull(d); } catch (EInvalidData e) { fail("InvalidData: " + e.getMessage()); } catch (EAccessDenied e) { fail("AccessDenied: " + e.getMessage()); } }
/** * Called when the connection has been established. * * @param StreamConsumer consumer The consumer object. */ public void onConnect(StreamConsumer c) { System.err.println("Connected, starting historic query"); // Start the historic query try { _h.start(); System.err.println("--"); } catch (EInvalidData e) { System.err.print("EInvalidData: "); System.err.println(e.getMessage()); } catch (EAccessDenied e) { System.err.print("EAccessDenied: "); System.err.println(e.getMessage()); } catch (EAPIError e) { System.err.print("EAPIError: "); System.err.println(e.getMessage()); } }
public void testValidate_Failure() { Definition def = new Definition(user, DataForTests.invalid_definition); try { assertEquals( "Definition string not set correctly", def.get(), DataForTests.invalid_definition); } catch (EInvalidData e1) { fail("EInvalidData: " + e1.getMessage()); } try { def.validate(); fail("Expected ECompileFailed exception was not thrown"); } catch (EInvalidData e) { fail("InvalidData: " + e.getMessage()); } catch (ECompileFailed e) { // This is what we should get } catch (EAccessDenied e) { fail("AccessDenied: " + e.getMessage()); } }
public void testValidate_Success() { Definition def = new Definition(user, DataForTests.definition); try { assertEquals("Definition string not set correctly", def.get(), DataForTests.definition); } catch (EInvalidData e1) { fail("EInvalidData: " + e1.getMessage()); } try { def.validate(); // We should now have a hash assertEquals("Incorrect hash", def.getHash(), DataForTests.definition_hash); } catch (EInvalidData e) { fail("InvalidData: " + e.getMessage()); } catch (ECompileFailed e) { fail("CompileFailed: " + e.getMessage()); } catch (EAccessDenied e) { fail("AccessDenied: " + e.getMessage()); } }
public void testGetDPUBreakdown() { Definition def = new Definition(user, DataForTests.definition); try { assertEquals("Definition string not set correctly", def.get(), DataForTests.definition); } catch (EInvalidData e1) { fail("EInvalidData: " + e1.getMessage()); } try { DPU dpu = def.getDPUBreakdown(); assertEquals(DataForTests.definition_dpu, dpu.getTotal()); } catch (EInvalidData e) { fail("InvalidData: " + e.getMessage()); } catch (EAccessDenied e) { fail("AccessDenied: " + e.getMessage()); } catch (ECompileFailed e) { fail("CompileFailed: " + e.getMessage()); } catch (EAPIError e) { fail("APIError: " + e.getMessage()); } }
public void testValidate_SuccessThenFailure() { Definition def = new Definition(user, DataForTests.definition); try { assertEquals("Definition string not set correctly", def.get(), DataForTests.definition); } catch (EInvalidData e1) { fail("EInvalidData: " + e1.getMessage()); } try { def.validate(); // We should now have a hash assertEquals("Hash is not correct", def.getHash(), DataForTests.definition_hash); } catch (EInvalidData e) { fail("InvalidData: " + e.getMessage()); } catch (ECompileFailed e) { fail("CompileFailed: " + e.getMessage()); } catch (EAccessDenied e) { fail("AccessDenied: " + e.getMessage()); } // Now set the invalid definition in that same object def.set(DataForTests.invalid_definition); try { assertEquals( "Definition string not set correctly", def.get(), DataForTests.invalid_definition); } catch (EInvalidData e1) { fail("EInvalidData: " + e1.getMessage()); } try { def.compile(); fail("CompileFailed exception expected, but not thrown"); } catch (EInvalidData e) { fail("InvalidData: " + e.getMessage()); } catch (ECompileFailed e) { // This is what we should get } catch (EAccessDenied e) { fail("AccessDenied: " + e.getMessage()); } }
/** @param args */ public static void main(String[] args) { if (args.length != 5) { System.err.println( "Usage: HistoricDump <keywords> <start_date> <end_date> <feeds> <csv_filename>"); System.err.println("Where..."); System.err.println(" <keywords> comma separated list of keywords"); System.err.println(" <start_date> start date (yyyymmddhhmmss)"); System.err.println(" <end_date> end date (yyyymmddhhmmss)"); System.err.println(" <feeds> comma separated list of feeds (twitter,digg,etc)"); System.err.println(" <csv_filename> filename for the csv output"); System.exit(1); } // Config String csdl = "interaction.type == \"twitter\" and language.tag == \"en\" and interaction.content contains_any \"" + args[0].replace("\"", "\\\"") + "\""; DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); try { // Authenticate System.err.println("Creating user..."); User user = new User(Config.username, Config.api_key); // Create the definition System.err.println("Creating definition..."); Definition d = user.createDefinition(csdl); // Create the historic System.err.println("Creating historic..."); Historic h = d.createHistoric(df.parse(args[1]), df.parse(args[2]), args[3], 100); // Display the playback ID System.err.println("Playback ID: " + h.getHash()); // Create the consumer System.err.println("Getting the consumer..."); StreamConsumer consumer = h.getConsumer(StreamConsumer.TYPE_HTTP, new HistoricDump(h, args[4])); // And start consuming System.err.println("Consuming..."); System.err.println("--"); consumer.consume(); } catch (EInvalidData e) { System.err.print("InvalidData: "); System.err.println(e.getMessage()); } catch (ECompileFailed e) { System.err.print("CompileFailed: "); System.err.println(e.getMessage()); } catch (EAccessDenied e) { System.err.print("AccessDenied: "); System.err.println(e.getMessage()); } catch (EAPIError e) { System.err.print("EAPIError: "); System.err.println(e.getMessage()); } catch (ParseException e) { System.err.print("ParseException: "); System.err.println(e.getMessage()); } }