Beispiel #1
0
        static void Main(string[] args)
        {
            // Create a new DataSift client
            var client = new DataSiftClient("DATASIFT_USERNAME", "DATASIFT_APIKEY");

            // Compile filter
            var csdl = @"tag.brand ""Calvin Klein"" { interaction.content contains ""Calvin Klein"" }
                tag.brand ""GQ"" { interaction.content contains ""GQ"" }
                tag.brand ""Adidas"" { interaction.content contains ""Adidas"" }
            
                return
                {
                    interaction.content contains_any ""Calvin Klein, GQ, Adidas""
                }";

            var compiled = client.Compile(csdl);

            _hash = compiled.Data.hash;

            _stream                    = client.Connect();
            _stream.OnConnect         += stream_OnConnect;
            _stream.OnMessage         += stream_OnMessage;
            _stream.OnDelete          += stream_OnDelete;
            _stream.OnDataSiftMessage += stream_OnDataSiftMessage;
            _stream.OnClosed          += stream_OnClosed;

            // Wait for key press before ending example
            Console.WriteLine("-- Press any key to exit --");
            Console.ReadKey(true);
        }
Beispiel #2
0
        static void stream_OnConnect()
        {
            Console.WriteLine("Connected.");

            // Compile and subscribe to a stream
            var compiled = _client.Compile("interaction.content contains \"football\"");

            Console.WriteLine("Compiled stream to {0}, DPU = {1}", compiled.Data.hash, compiled.Data.dpu);
            _stream.Subscribe(compiled.Data.hash);
        }
Beispiel #3
0
        private static RestAPIResponse Core(DataSiftClient client, string command)
        {
            RestAPIResponse response = null;

            switch (command)
            {
            case "validate":
                response = client.Validate(_argsParser.GetParameter <string>("csdl"));
                break;

            case "compile":
                response = client.Compile(_argsParser.GetParameter <string>("csdl"));
                break;

            case "usage":
                UsagePeriod period;

                if (Enum.TryParse(_argsParser.GetParameter <string>("period"), out period))
                {
                    client.Usage(period);
                }
                else
                {
                    client.Usage();
                }

                break;

            case "balance":
                response = client.Balance();
                break;

            case "dpu":
                response = client.Compile(_argsParser.GetParameter <string>("hash"));
                break;

            default:
                throw new ApplicationException("Unrecognised command: " + command);
            }

            return(response);
        }
Beispiel #4
0
        internal static void Run(string username, string apikey)
        {
            var client = new DataSiftClient(username, apikey);

            Console.WriteLine("Running 'Historics' example...");

            var get = client.Historics.Get();

            Console.WriteLine("\nList of historics: " + JsonConvert.SerializeObject(get.Data));

            var status = client.Historics.Status(DateTimeOffset.Now.AddDays(-2), DateTimeOffset.Now.AddDays(-1), new string[] { "twitter" });

            Console.WriteLine("\nTwitter status for period: " + status.Data[0].sources.twitter.status);

            var compiled = client.Compile("interaction.content contains \"datasift\"");

            Console.WriteLine("\nCompiled CSDL to {0}, DPU = {1}", compiled.Data.hash, compiled.Data.dpu);

            var prepare = client.Historics.Prepare(compiled.Data.hash, DateTimeOffset.Now.AddDays(-8), DateTimeOffset.Now.AddDays(-1), "Example historic", new string[] { "twitter" }, Sample.TenPercent);

            Console.WriteLine("\nPrepared historic query, ID = " + prepare.Data.id);

            var subscription = client.Push.Create("Example historic subscription", "pull", historicsId: prepare.Data.id);

            Console.WriteLine("\nCreated subscription, ID = " + subscription.Data.id);

            client.Historics.Start(prepare.Data.id);
            Console.WriteLine("\nStarted historic.");

            var update = client.Historics.Update(prepare.Data.id, "Updated historic query");

            Console.WriteLine("\nUpdated historic.");

            var getById = client.Historics.Get(id: prepare.Data.id);

            Console.WriteLine("\nDetails for updated historic: " + JsonConvert.SerializeObject(getById.Data));

            client.Historics.Pause(prepare.Data.id);
            Console.WriteLine("\nPaused historic.");

            client.Historics.Resume(prepare.Data.id);
            Console.WriteLine("Resumed historic.");

            client.Historics.Stop(prepare.Data.id);
            Console.WriteLine("Stopped historic.");

            client.Historics.Delete(prepare.Data.id);
            Console.WriteLine("Deleted historic.");
        }
Beispiel #5
0
        internal static void Run(string username, string apikey)
        {
            var client = new DataSiftClient(username, apikey);

            Console.WriteLine("Running 'Push' example...");

            var get = client.Push.Get(page: 1, perPage: 5, orderBy: OrderBy.UpdatedAt, includeFinished: true);

            Console.WriteLine("\nList of push subscriptions: " + JsonConvert.SerializeObject(get.Data));

            var compiled = client.Compile("interaction.content contains \"music\"");

            Console.WriteLine("\nCompiled to {0}", compiled.Data.hash);

            var create = client.Push.Create(".NET example pull", "pull", hash: compiled.Data.hash);

            Console.WriteLine("\nCreated pull subscription: {0}", create.Data.id);

            var update = client.Push.Update(create.Data.id, name: "Updated example pull");

            Console.WriteLine("\nUpdated subscription name.");

            var getById = client.Push.Get(id: create.Data.id);

            Console.WriteLine("\nSubscription details: " + JsonConvert.SerializeObject(getById.Data));

            var log = client.Push.Log(create.Data.id);

            Console.WriteLine("\nLog for new subscription: " + JsonConvert.SerializeObject(log.Data.log_entries));

            Console.WriteLine("\nPausing for data.");
            Thread.Sleep(20000);

            var pull = client.Pull(create.Data.id, size: 500000);

            Console.WriteLine("\nGot data, first interaction: " + JsonConvert.SerializeObject(pull.Data[0]));

            client.Push.Stop(create.Data.id);
            Console.WriteLine("\nStopped subscription.");

            client.Push.Delete(create.Data.id);
            Console.WriteLine("\nDeleted subscription.");
        }
        internal static void Run(string username, string apikey)
        {
            var client = new DataSiftClient(username, apikey);

            Console.WriteLine("Running 'Historics Preview' example...");

            var compiled = client.Compile("interaction.content contains \"datasift\"");

            Console.WriteLine("\nCompiled to {0}", compiled.Data.hash);

            var prms = new List <HistoricsPreviewParameter>();

            prms.Add(new HistoricsPreviewParameter()
            {
                Target = "interaction.author.link", Analysis = "targetVol", Argument = "hour"
            });
            prms.Add(new HistoricsPreviewParameter()
            {
                Target = "twitter.user.lang", Analysis = "freqDist", Argument = "10"
            });
            prms.Add(new HistoricsPreviewParameter()
            {
                Target = "twitter.user.followers_count", Analysis = "numStats", Argument = "hour"
            });
            prms.Add(new HistoricsPreviewParameter()
            {
                Target = "interaction.content", Analysis = "wordCount", Argument = "10"
            });

            var create = client.HistoricsPreview.Create(compiled.Data.hash, new string[] { "twitter" }, prms, DateTimeOffset.Now.AddDays(-2), DateTimeOffset.Now.AddDays(-1));

            Console.WriteLine("\nCreated preview: {0}", create.Data.id);

            Console.WriteLine("\nPausing for preview status update.");
            Thread.Sleep(10000);

            var get1 = client.HistoricsPreview.Get(create.Data.id);

            Console.WriteLine("\nPreview status: " + JsonConvert.SerializeObject(get1.Data));
        }
Beispiel #7
0
        internal static void Run(string username, string apikey)
        {
            var client = new DataSiftClient(username, apikey);

            Console.WriteLine("Running 'Core' example...");

            var compiled = client.Compile("interaction.content contains \"music\"");

            Console.WriteLine("\nCompiled to {0}, DPU = {1}", compiled.Data.hash, compiled.Data.dpu);

            var usage = client.Usage();

            Console.WriteLine("\nUsage report: " + usage.ToJson());

            var dpu = client.DPU(hash: compiled.Data.hash);

            Console.WriteLine("\nDPU report: " + dpu.ToJson());

            var balance = client.Balance();

            Console.WriteLine("\nBalance report: " + balance.ToJson());
        }