Exemple #1
0
  /** @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());
    }
  }
Exemple #2
0
  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());
    }
  }
Exemple #3
0
  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());
    }
  }
Exemple #4
0
  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());
    }
  }
  /** @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());
    }
  }