Package com.datasift.client

Examples of com.datasift.client.DataSiftClient


    private PullApiHistorics() {
    }

    public static void main(String... args) throws InterruptedException {
        DataSiftConfig config = new DataSiftConfig("zcourts", "acbf4788f875db9fdf6bbd2131b10752");
        final DataSiftClient datasift = new DataSiftClient(config);
        Stream stream = Stream.fromString("13e9347e7da32f19fcdb08e297019d2e");

        PreparedHistoricsQuery historic = datasift.historics().prepare(stream.hash(), DateTime.now().minusHours(5),
                DateTime.now().minusHours(4), "Historics pull test").sync();

        PushSubscription historicsSubscription = datasift.push()
                .createPull(PullJsonType.JSON_NEW_LINE, historic, "pull test " + DateTime.now()).sync();

        //don't forget to start it, AFTER creating the pull subscription
        datasift.historics().start(historic).sync();

        PulledInteractions historicSubscriptions = datasift.push().pull(historicsSubscription).sync();

        Interaction interaction;
        while (!((interaction = historicSubscriptions.take()) instanceof LastInteraction)) {
            System.out.println(interaction);
        }
View Full Code Here


public class ManagedSourcesApi {
    private ManagedSourcesApi() throws InterruptedException {
        DataSiftConfig config = new DataSiftConfig("username", "api-key");

        final DataSiftClient datasift = new DataSiftClient(config);

        FacebookPage source = new FacebookPage(config);
        String fbToken = "long-lived-facebook-api-token";

        source.addOAutToken(fbToken, "name", 1381406400);
        //username or id is valid
        source.addPage("theguardian", "https://www.facebook.com/theguardian", "a name for this");
        //or use the ID of the facebook page
        //source.addPage("10513336322", "https://www.facebook.com/theguardian", "a name for this");

        //enable options using
        source.enableComments(true)
                .enableLikes(true)
                .enablePostsByOthers(true);
        //or all at once
        source.setParams(true, true, true);
        ManagedSource managedSource = datasift.managedSource().create("My managed source", source).sync();
        if (managedSource.isSuccessful()) {
            //and now we can do filtering on this page e.g.
            Stream stream = datasift
                    .compile(String.format("interaction.content contains \"news\" AND source.id == \"%s\"",
                            managedSource.getId())).sync();

            System.out.println(managedSource);
        }
View Full Code Here

public class PreviewApi {
    private PreviewApi() throws InterruptedException {
        DataSiftConfig config = new DataSiftConfig("username", "api-key");

        final DataSiftClient datasift = new DataSiftClient(config);
        Stream stream = Stream.fromString("13e9347e7da32f19fcdb08e297019d2e");
        DateTime fiveHrsAgo = DateTime.now().minusHours(5);
        HistoricsPreview preview = datasift.preview().create(fiveHrsAgo, stream,
                new String[]{ "interaction.author.link,targetVol,hour;interaction.type,freqDist,10" }).sync();
        //can also later get the preview data
        datasift.preview().get(preview);
        //or
        datasift.preview().get(preview.id());
    }
View Full Code Here

    public static void main(String... args) throws InterruptedException {
        DataSiftConfig config = new DataSiftConfig("username", "api-key");
        //or
        config = new DataSiftConfig().auth("zcourts", "43aedc2c7e292016df949c972afe29be");
        config.setSslEnabled(false);
        final DataSiftClient datasift = new DataSiftClient(config);
        String csdl = "interaction.content contains \"music\"";
        //both sync and async processing are supported by calling "sync" on any FutureDate object

//        Usage u = datasift.usage().sync();
//        System.out.println(u);
        //all response objects extend DataSiftResult which present these utility methods
        DataSiftResult result = datasift.compile(csdl).sync();
        //is successful returns true if a response hasn't explicitly been marked as failed,
        //there is a valid response, no exceptions are set and the response status is between 200 - 399
        if (!result.isSuccessful()) {
            //if true an exception may have caused the request to fail, inspect the cause if available
            if (result.failureCause() != null) { //may not be an exception
                result.failureCause().printStackTrace();
            }
            return;
        }
        //is true if isSuccessful() == true and the response status is not 401
        result.isAuthorizationSuccesful();
        //allows access to the response object which you can list the request and JSON string response from
        result.getResponse();
        //gets the rate limit DataSift returned with the response, use it to keep track of usage
        result.rateLimit();
        //returns the cost of executing the request which produced this result
        result.rateLimitCost();
        //what's left of your rate limit quota
        result.rateLimitRemaining();

        Usage usage = datasift.usage().sync();

        Stream stream = Stream.fromString("13e9347e7da32f19fcdb08e297019d2e");
        Dpu dpu = datasift.dpu(stream).sync();

        Balance balance = datasift.balance().sync();
        //synchronously validate a CSDL
        Validation validation = datasift.validate(csdl).sync();
        if (!validation.isSuccessful()) {
            //if true an exception may have caused the request to fail, inspect the cause if available
            if (validation.failureCause() != null) { //may not be an exception
                validation.failureCause().printStackTrace();
            }
            return;
        }
        System.out.println(validation);
        if (validation.isSuccessful()) {
            //we now know it's valid so asynchronously compile the CSDL and obtain a stream
            FutureData<Stream> compiledStream = datasift.compile(csdl);
            compiledStream.onData(new FutureResponse<Stream>() {
                public void apply(Stream data) {
                    System.out.println(data);
                }
            });
            FutureData<Dpu> dpus = datasift.dpu(compiledStream);
            dpus.onData(new FutureResponse<Dpu>() {
                public void apply(Dpu data) {
                    System.out.println(data);
                }
            });
        }
        System.out.println(datasift.balance().sync());
        System.out.println(datasift.usage().sync());
    }
View Full Code Here

    private LiveStream() {
    }

    public static void main(String... args) throws InterruptedException {
        DataSiftConfig config = new DataSiftConfig("zcourts", "a9641ee0770d05ff3d83225c9fafe4bb");
        final DataSiftClient datasift = new DataSiftClient(config);
        Stream result = datasift.compile("interaction.content contains \"music\" ").sync();
        //handle exceptions that can't necessarily be linked to a specific stream
        datasift.liveStream().onError(new ErrorHandler());

        //handle delete message
        datasift.liveStream().onStreamEvent(new ExampleStreamEventHandler());

        //process interactions
        datasift.liveStream().subscribe(new Subscription(Stream.fromString("67b378312cca82eaf9fdaa9c3880c440")));
        //process interactions for another stream
        datasift.liveStream().subscribe(new Subscription(Stream.fromString("another-stream-hash")));
        datasift.liveStream().subscribe(new Subscription(result));
        //at some point later if you want unsubscribe
        datasift.liveStream().unsubscribe(Stream.fromString("67b378312cca82eaf9fdaa9c3880c450"));
    }
View Full Code Here

    public static void main(String... args) throws InterruptedException {
        DateTime.now();
        new Date();
        DataSiftConfig config = new DataSiftConfig("zcourts", "acbf4788f875db9fdf6bbd2131b10752");
        final DataSiftClient datasift = new DataSiftClient(config);
        Stream stream = Stream.fromString("13e9347e7da32f19fcdb08e297019d2e");

        PushSubscription streamSubscription = datasift.push()
                .createPull(PullJsonType.JSON_NEW_LINE, stream, "pull test").sync();

        PulledInteractions streamSubscriptions = datasift.push().pull(streamSubscription).sync();

        Interaction interaction;
        //non-blocking loop - if no data is available at the time of request the loop will be exited
        //if using this approach you must remember to manually call streamSubscriptions.stopPulling();
        for (Interaction i : streamSubscriptions) {
View Full Code Here

*/
public class DynamicListApi {
    private DynamicListApi() throws InterruptedException {
        DataSiftConfig config = new DataSiftConfig("username", "api-key");

        DataSiftClient datasift = new DataSiftClient(config);
        DataSiftDynamicList dynamiclist = new DataSiftDynamicList(config);

        DynamicList list = dynamiclist.create(DataSiftDynamicList.ListType.STRING, "example list").sync();
        if (list.isSuccessful()) {
            // create a stream that references the dynamic list, using the list_any operator
            Stream stream = datasift
                    .compile(String.format("interaction.content list_any \"%s\"", list.getId())).sync();

            // even after the stream was created, we can manipulate the list, even if the stream is running
            List<String> items = new ArrayList<>();
            items.add("keyword1");
View Full Code Here

import org.joda.time.DateTime;

public class HistoricsApi {
    private HistoricsApi() throws InterruptedException {
        DataSiftConfig config = new DataSiftConfig("zcourts", "44067e0ff342b76b52b36a63eea8e21a");
        DataSiftClient datasift = new DataSiftClient(config);
        Stream stream = Stream.fromString("13e9347e7da32f19fcdb08e297019d2e");

        S3 s3 = PushConnectors
                .s3()
                .accessKey("s3-access-key")
                .secretKey("s3-access-key")
                .bucket("apitests")
                .directory("java-client")
                .acl("private")
                .deliveryFrequency(0)
                .maxSize(10485760)
                .filePrefix("DataSiftJava-");

        DateTime fiveHrsAgo = DateTime.now().minusHours(5);
        DateTime fourHrsAgo = fiveHrsAgo.plusHours(1);
        String name = "My awesome Historics";
        //prepare our query
        PreparedHistoricsQuery query = datasift.historics().prepare(stream.hash(), fiveHrsAgo, fourHrsAgo, name).sync();
        //have to create a push subscription to the newly created historics before starting
        datasift.push().create(s3, FutureData.wrap(query), "Subscription name").sync();
        DataSiftResult historics = datasift.historics().start(query).sync();

        //stop a query
        datasift.historics().stop(query, "some reason").sync();
        //get a single historics query
        datasift.historics().get(query.getId()).sync();
        //get your list of historics
        datasift.historics().list().sync();
        //delete a query
        datasift.historics().delete(query).sync();
    }
View Full Code Here

    public static void main(String... args) throws InterruptedException {
        DataSiftConfig config = new DataSiftConfig("username", "api-key");
        //or
        config = new DataSiftConfig().auth("zcourts", "44067e0ff342b76b52b36a63eea8e21a");

        final DataSiftClient datasift = new DataSiftClient(config);
        String csdl = "interaction.content contains \"some string\"";
        //both sync and async processing are supported by calling "sync" on any FutureDate object

        //synchronously validate a CSDL
        Validation validation = datasift.core().validate(csdl).sync();
        if (validation.hasFailed()) {
            //if true an exception may have caused the request to fail, inspect the cause if available
            if (validation.failureCause() != null) { //may not be an exception
                validation.failureCause().printStackTrace();
            }
            return;
        }
        System.out.println(validation);
        if (validation.isSuccessful()) {
            //we now know it's valid so asynchronously compile the CSDL and obtain a stream
            FutureData<Stream> stream = datasift.core().compile(csdl);
            FutureData<Dpu> dpus = datasift.core().dpu(stream);
            dpus.onData(new FutureResponse<Dpu>() {
                public void apply(Dpu data) {
                    System.out.println(data);
                }
            });
        }
        System.out.println(datasift.core().balance().sync());
        System.out.println(datasift.core().usage().sync());

        datasift.liveStream().onError(new ErrorListener() {
            public void exceptionCaught(Throwable t) {
                t.printStackTrace();
            }
        });

        datasift.liveStream().onStreamEvent(new StreamEventListener() {
            public void onDelete(DeletedInteraction di) {
                System.out.println("DELETED:\n " + di);
            }
        });

        Stream stream = Stream.fromString("13e9347e7da32f19fcdb08e297019d2e");

        datasift.liveStream().subscribe(new StreamSubscription(stream) {
            public void onDataSiftLogMessage(DataSiftMessage di) {
                //di.isWarning() is also available
                System.out.println((di.isError() ? "Error" : di.isInfo() ? "Info" : "Warning") + ":\n" + di);
            }
View Full Code Here

    private PushApi() {
    }

    public static void main(String... args) throws InterruptedException {
        DataSiftConfig config = new DataSiftConfig("zcourts", "44067e0ff342b76b52b36a63eea8e21a");
        final DataSiftClient datasift = new DataSiftClient(config);
        Stream stream = Stream.fromString("13e9347e7da32f19fcdb08e297019d2e");
        S3 s3 = PushConnectors.s3()
                .accessKey("amazon-access-key")
                .secretKey("amazone-secret")
                .maxSize(102400)
                .deliveryFrequency(0)
                .acl("acl")
                .bucket("some-bucket")
                .directory("abc");
        FutureData<PushSubscription> subscriptionFuture = datasift.push().create(
                s3,
                null,  //historics must be null, we're creating from a stream
                FutureData.wrap(stream),
                "Example push from stream"
        );
View Full Code Here

TOP

Related Classes of com.datasift.client.DataSiftClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.