예제 #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);
        }
예제 #2
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;
        }
예제 #3
0
        internal static void Run(string username, string apikey)
        {
            var client = new DataSiftClient(username, apikey);

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

            var get = client.List.Get();
            Console.WriteLine("\nCurrent of dynamic lists: " + JsonConvert.SerializeObject(get.Data));

            var create = client.List.Create(ListType.Integer, "Example integer list");
            Console.WriteLine("\nCreated list: {0}", create.Data.id);

            client.List.Add(create.Data.id, new int[] { 1, 2, 3, 4, 5 });
            Console.WriteLine("\nAdded items to list");

            client.List.Remove(create.Data.id, new int[] { 1, 2 });
            Console.WriteLine("\nRemoved items from list");

            var exists = client.List.Exists(create.Data.id, new int[] { 2, 4 });
            Console.WriteLine("\nExistance in list: " + JsonConvert.SerializeObject(exists.Data));

            var replace = client.List.ReplaceStart(create.Data.id);
            Console.WriteLine("\nReplace started with ID: " + replace.Data.id);

            client.List.ReplaceAdd(replace.Data.id, new int[] { 6, 7, 8, 9, 10 });
            Console.WriteLine("\nAdded new items in replace.");

            client.List.ReplaceCommit(replace.Data.id);
            Console.WriteLine("\nCommitted bulk replace");

            client.List.Delete(create.Data.id);
            Console.WriteLine("\nDeleted list.");
        }
예제 #4
0
        static void Main(string[] args)
        {
            // Create a new DataSift client
            var client = new DataSiftClient("DATASIFT_USERNAME", "DATASIFT_APIKEY");

            // Compile filter
            var csdl = @"tag.source ""Pandora"" { links.domain == ""pandora.com"" }
                        tag.source ""SoundCloud"" { links.domain == ""soundcloud.com"" }
                        tag.source ""Spotify"" { links.domain == ""spotify.com"" }

                        return {
                            links.domain in ""pandora.com,soundcloud.com,spotify.com""
                            AND interaction.type == ""twitter""
                        }";

            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);
        }
예제 #5
0
        static void Main(string[] args)
        {
            // Create a new DataSift client
            _client = new DataSiftClient("DATASIFT_USERNAME", "DATASIFT_APIKEY");

            var recordingId = StartRecording();
            Analyze(recordingId);

            // Wait for key press before ending example
            Console.WriteLine("-- Press any key to exit --");
            Console.ReadKey(true);
        }
예제 #6
0
        internal static void Run(string username, string apikey)
        {
            var client = new DataSiftClient(username, apikey);

            Console.WriteLine("Running 'Account Identity' example...");

            var get = client.Account.Identity.Get();
            Console.WriteLine("\nGot current identities: " + JsonConvert.SerializeObject(get.Data));

            var identity = client.Account.Identity.Create("Test Identity " + DateTime.Now.Ticks.ToString());
            Console.WriteLine("\nCreated new identity: " + identity.Data.id);

            var identityRenamed = client.Account.Identity.Update(identity.Data.id, "Test Identity Renamed " + DateTime.Now.Ticks.ToString());
            Console.WriteLine("\nUpdated identity: " + identityRenamed.Data.label);

            var getById = client.Account.Identity.Get(id: identity.Data.id);
            Console.WriteLine("\nGot updated identity: " + JsonConvert.SerializeObject(getById.Data));

            var token = client.Account.Identity.Token.Create(identity.Data.id, "facebook", "ddd85f6b316fb18930ee28e8754f4963");
            Console.WriteLine("\nCreated token: " + JsonConvert.SerializeObject(token.Data));

            var getAllIdentityTokens = client.Account.Identity.Token.Get(identity.Data.id);
            Console.WriteLine("\nAll tokens for identity: " + JsonConvert.SerializeObject(getAllIdentityTokens.Data));

            var getTokenByService = client.Account.Identity.Token.Get(identity.Data.id, "facebook");
            Console.WriteLine("\nGot token by service: " + JsonConvert.SerializeObject(getTokenByService.Data));

            var updatedToken = client.Account.Identity.Token.Update(identity.Data.id, "facebook", "eed85f6b316fb18930ee28e8754f4963");
            Console.WriteLine("\nUpdated token: " + JsonConvert.SerializeObject(updatedToken.Data));

            var limit = client.Account.Identity.Limit.Create(identity.Data.id, "facebook", 100000);
            Console.WriteLine("\nCreated limit: " + JsonConvert.SerializeObject(limit.Data));

            var allLimitsForService = client.Account.Identity.Limit.Get("facebook");
            Console.WriteLine("\nAll limits for service: " + JsonConvert.SerializeObject(allLimitsForService.Data));

            var limitForService = client.Account.Identity.Limit.Get("facebook", identity.Data.id);
            Console.WriteLine("\nLimit for service: " + JsonConvert.SerializeObject(limitForService.Data));

            var updatedLimit = client.Account.Identity.Limit.Update(identity.Data.id, "facebook", 200000);
            Console.WriteLine("\nUpdated limit: " + JsonConvert.SerializeObject(updatedLimit.Data));

            client.Account.Identity.Limit.Delete(identity.Data.id, "facebook");
            Console.WriteLine("\nDeleted limit.");

            client.Account.Identity.Token.Delete(identity.Data.id, "facebook");
            Console.WriteLine("\nDeleted token.");

            // DELETE not currently supported by the API
            //client.Account.Identity.Delete(id: identity.Data.id);
            //Console.WriteLine("\nDeleted identity.");
        }
예제 #7
0
        internal static void Run(string username, string apikey)
        {
            var client = new DataSiftClient(username, apikey);

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

            var response = client.ODP.Ingest("d44757b030a1499492f539591d86fe3e", new[] {
                    new {
                        title = "Dummy content"
                    }
                });

            Console.WriteLine("\nIngestion response: " + JsonConvert.SerializeObject(response.Data));
        }
예제 #8
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: " + JsonConvert.SerializeObject(usage.Data));

            var balance = client.Balance();
            Console.WriteLine("\nBalance report: " + JsonConvert.SerializeObject(balance.Data));
        }
예제 #9
0
        internal static void Run(string username, string apikey)
        {
            _client = new DataSiftClient(username, apikey);

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

            _stream = _client.Connect();
            _stream.OnConnect += stream_OnConnect;
            _stream.OnMessage += stream_OnMessage;
            _stream.OnDataSiftMessage += stream_OnDataSiftMessage;
            _stream.OnSubscribed += stream_OnSubscribed;
            _stream.OnError += stream_OnError;
            _stream.OnClosed += stream_OnClosed;
            _stream.OnDelete += stream_OnDelete;
        }
예제 #10
0
        internal static void Run(string username, string apikey)
        {
            var client = new DataSiftClient(username, apikey);

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

            var latest = client.Account.Usage();
            Console.WriteLine("\nGot latest usage info: " + JsonConvert.SerializeObject(latest.Data));

            DateTimeOffset lastMonth = DateTimeOffset.Now.AddMonths(-1);
            var firstDayOfLastMonth = new DateTimeOffset(lastMonth.Year, lastMonth.Month, 1, 0, 0, 0, TimeSpan.Zero);

            var lastMonthUsage = client.Account.Usage(period: AccountUsagePeriod.Monthly, start: firstDayOfLastMonth);
            Console.WriteLine("\nGot last month's usage info: " + JsonConvert.SerializeObject(lastMonthUsage.Data));
        }
예제 #11
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());
        }
예제 #12
0
        private static RestAPIResponse Historics(DataSiftClient client, string command)
        {
            RestAPIResponse response = null;

            switch (command)
            {
                case "prepare":

                    Sample sampleTemp;
                    Sample? sample = null;

                    if (Enum.TryParse(_argsParser.GetParameter<string>("sample"), out sampleTemp))
                        sample = sampleTemp;

                    response = client.Historics.Prepare(_argsParser.GetParameter<string>("hash"), _argsParser.GetParameter<DateTimeOffset>("start"),
                            _argsParser.GetParameter<DateTimeOffset>("end"), _argsParser.GetParameter<string>("name"), _argsParser.GetParameter<string[]>("sources"),
                            sample);
                    break;
                case "start":
                    response = client.Historics.Start(_argsParser.GetParameter<string>("id"));
                    break;
                case "stop":
                    response = client.Historics.Stop(_argsParser.GetParameter<string>("id"));
                    break;
                case "status":
                    response = client.Historics.Status(_argsParser.GetParameter<DateTimeOffset>("start"), _argsParser.GetParameter<DateTimeOffset>("stop"), _argsParser.GetParameter<string[]>("sources"));
                    break;
                case "update":
                    response = client.Historics.Update(_argsParser.GetParameter<string>("id"), _argsParser.GetParameter<string>("name"));
                    break;
                case "delete":
                    response = client.Historics.Delete(_argsParser.GetParameter<string>("id"));
                    break;
                case "get":
                    response = client.Historics.Get(id: _argsParser.GetParameter<string>("id"), max: _argsParser.GetParameter<int?>("max"),
                        page: _argsParser.GetParameter<int?>("page"), withEstimate: _argsParser.GetParameter<bool?>("with_estimate"));
                    break;
                default:
                    throw new ApplicationException("Unrecognised command: " + command);
            }

            return response;
        }
예제 #13
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.");
        }
예제 #14
0
        // Note that to run the PYLON example you must use an API key which corresponds to a valid identity with Facebook access
        internal static void Run(string username, string apikey)
        {
            var client = new DataSiftClient(username, apikey);

            // TODO: Insert the service, recording id and analysis parameters you'd like to use
            var service = "";
            var recordingId = "";

            dynamic parameters = new {
                        parameters = new
                        {
                            analysis_type = "timeSeries",
                            parameters = new
                            {
                                interval = "hour",
                                span = 1
                            }
                        }
                    };

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

            var get = client.Pylon.Task.Get(service);
            Console.WriteLine("\nCurrent list of tasks: " + JsonConvert.SerializeObject(get.Data));

            var create = client.Pylon.Task.Create(service, recordingId, "New analyze task", "analysis", parameters);
            Console.WriteLine("\nCreated task: " + JsonConvert.SerializeObject(create.Data));

            var getOne = client.Pylon.Task.Get(service, taskId: create.Data.id);
            Console.WriteLine("\nGot task: " + JsonConvert.SerializeObject(getOne.Data));

            while(getOne.Data.status != "completed")
            {
                getOne = client.Pylon.Task.Get(service, taskId: create.Data.id);
                Console.WriteLine("\nStatus: " + getOne.Data.status);
            }
        }
예제 #15
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(5000);

            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.");
        }
예제 #16
0
        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));
        }
예제 #17
0
        internal static void Run(string username, string apikey)
        {
            // TODO: Insert auth tokens here from https://datasift.com/source/managed/new/facebook_page
            var authtoken = "";
            var authTokenToAddLater = "";

            if(String.IsNullOrEmpty(authtoken) || (String.IsNullOrEmpty(authTokenToAddLater)))
                throw new ArgumentException("Set the authtoken & authTokenToAddLater variables to a valid tokens");

            var client = new DataSiftClient(username, apikey);

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

            var get = client.Source.Get(page: 1, perPage: 5);
            Console.WriteLine("\nList of sources: " + JsonConvert.SerializeObject(get.Data));

            var prms = new
            {
                likes = true,
                posts_by_others = true,
                comments = true,
                page_likes = false
            };

            var resources = new[] {
                    new {
                        parameters = new {
                            url = "http://www.facebook.com/theguardian",
                            title = "The Guardian",
                            id = 10513336322
                        }
                    }
                };

            var resourcesToAddLater = new[] {
                    new {
                        parameters = new {
                            url = "http://www.facebook.com/thesun",
                            title = "The Sun",
                            id = 161385360554578
                        }
                    }
                };

            var auth = new[] {
                    new {
                        parameters = new {
                            value = authtoken
                        }
                    }
                };

            var authToAddLater = new[] {
                    new {
                        parameters = new {
                            value = authTokenToAddLater
                        }
                    }
                };

            var create = client.Source.Create("facebook_page", "Example source", prms, resources, auth);
            Console.WriteLine("\nCreated source: {0}", create.Data.id);

            client.Source.Start(create.Data.id);
            Console.WriteLine("\nStarted source.");

            var update = client.Source.Update(create.Data.id, name: "Updated example source");
            Console.WriteLine("\nUpdated source: {0}", update.Data.id);

            var getSource = client.Source.Get(id: create.Data.id);
            Console.WriteLine("\nSource details: " + JsonConvert.SerializeObject(getSource.Data));

            var addResource = client.Source.ResourceAdd(create.Data.id, resourcesToAddLater);
            Console.WriteLine("\nAdded resource ID: " + addResource.Data.resources[1].resource_id);

            var removeResource = client.Source.ResourceRemove(create.Data.id, new string[] { addResource.Data.resources[1].resource_id });
            Console.WriteLine("\nRemoved resource ID: " + addResource.Data.resources[1].resource_id);

            var addAuth = client.Source.AuthAdd(create.Data.id, authToAddLater);
            Console.WriteLine("\nAdded auth ID: " + addAuth.Data.auth[1].identity_id);

            var removeAuth = client.Source.ResourceRemove(create.Data.id, new string[] {  addAuth.Data.auth[1].identity_id });
            Console.WriteLine("\nRemoved auth ID: " + addAuth.Data.auth[1].identity_id);

            client.Source.Stop(create.Data.id);
            Console.WriteLine("\nStopped source.");

            var log = client.Source.Log(create.Data.id, 1, 5);
            Console.WriteLine("\nSource log: " + JsonConvert.SerializeObject(log.Data.log_entries));

            client.Source.Delete(create.Data.id);
            Console.WriteLine("\nDeleted source.");
        }
예제 #18
0
        // Note that to run the PYLON example you must use an API key which corresponds to a valid identity with Facebook access
        internal static void Run(string username, string apikey)
        {
            var client = new DataSiftClient(username, apikey);

            var csdl = "fb.content contains_any \"BMW, Mercedes, Cadillac\"";

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

            var get = client.Pylon.Get();
            Console.WriteLine("\nCurrent of recordings / tasks: " + JsonConvert.SerializeObject(get.Data));

            client.Pylon.Validate(csdl);
            Console.WriteLine("CSDL for recording validated");

            var compile = client.Pylon.Compile(csdl);
            Console.WriteLine("Hash for stream: " + compile.Data.hash);

            client.Pylon.Start(compile.Data.hash, "Example recording");
            Console.WriteLine("Recording started");

            var getRecording = client.Pylon.Get(hash: compile.Data.hash);
            Console.WriteLine("\nThis recording: " + JsonConvert.SerializeObject(getRecording.Data));

            var analysisParams = new  {
                    analysis_type = "freqDist",
                    parameters = new
                    {
                        threshold = 5,
                        target = "fb.author.age"
                    }
                };

            var analysis = client.Pylon.Analyze(compile.Data.hash, analysisParams);
            Console.WriteLine("\nAnalysis result: " + JsonConvert.SerializeObject(analysis.Data));

            var analysisWithFilter = client.Pylon.Analyze(compile.Data.hash, analysisParams, filter: "fb.author.gender == \"male\"");
            Console.WriteLine("\nAnalysis (with filter) result: " + JsonConvert.SerializeObject(analysisWithFilter.Data));

            dynamic nested = new
            {
                analysis_type = "freqDist",
                parameters = new
                {
                    threshold = 3,
                    target = "fb.author.gender"
                },
                child = new
                {
                    analysis_type = "freqDist",
                    parameters = new
                    {
                        threshold = 3,
                        target = "fb.author.age"
                    }
                }
            };

            var analysisNested = client.Pylon.Analyze(compile.Data.hash, nested);
            Console.WriteLine("\nNested analysis result: " + JsonConvert.SerializeObject(analysisNested.Data));

            var tags = client.Pylon.Tags(compile.Data.hash);
            Console.WriteLine("\nTags: " + JsonConvert.SerializeObject(tags.Data));

            client.Pylon.Stop(compile.Data.hash);
            Console.WriteLine("\nRecording stopped");
        }
예제 #19
0
        private static RestAPIResponse Source(DataSiftClient client, string command)
        {
            RestAPIResponse response = null;

            switch (command)
            {
                case "create":
                    response = client.Source.Create(_argsParser.GetParameter<string>("source_type"),
                        _argsParser.GetParameter<string>("name"), _argsParser.GetParameter<ExpandoObject>("parameters"),
                        _argsParser.GetParameter<List<ExpandoObject>>("resources"), _argsParser.GetParameter<List<ExpandoObject>>("auth"));
                    break;
                case "update":
                    response = client.Source.Update(_argsParser.GetParameter<string>("id"), _argsParser.GetParameter<string>("source_type"),
                        _argsParser.GetParameter<string>("name"), _argsParser.GetParameter<ExpandoObject>("parameters"),
                        _argsParser.GetParameter<List<ExpandoObject>>("resources"), _argsParser.GetParameter<List<ExpandoObject>>("auth"));
                    break;
                case "delete":
                    response = client.Source.Delete(_argsParser.GetParameter<string>("id"));
                    break;
                case "start":
                    response = client.Source.Start(_argsParser.GetParameter<string>("id"));
                    break;
                case "stop":
                    response = client.Source.Stop(_argsParser.GetParameter<string>("id"));
                    break;
                case "log":
                    response = client.Source.Log(_argsParser.GetParameter<string>("id"), _argsParser.GetParameter<int?>("page"),
                        _argsParser.GetParameter<int?>("per_page"));
                    break;
                case "get":
                    response = client.Source.Get(_argsParser.GetParameter<string>("id"),
                        _argsParser.GetParameter<int?>("page"),
                        _argsParser.GetParameter<int?>("per_page"), _argsParser.GetParameter<string>("id"));
                    break;
                default:
                    throw new ApplicationException("Unrecognised command: " + command);
            }

            return response;
        }
예제 #20
0
 static void Main(string[] args)
 {
     _client = new DataSiftClient("ACCOUNT_API_USERNAME", "IDENTITY_APIKEY");
 }
예제 #21
0
        private static void RunCommand()
        {
            string endpoint = "core";
            string[] auth = _argsParser.Get<string[]>("a");
            DataSiftClient datasift= null;

            if(_argsParser.Contains("u"))
                datasift = new DataSiftClient(auth[0], auth[1], baseUrl: _argsParser.Get<string>("u"));
            else
                datasift = new DataSiftClient(auth[0], auth[1]);

            if (_argsParser.Contains("e"))
                endpoint = _argsParser.Get<string>("e");

            var command = _argsParser.Get<string>("c").ToLower();

            RestAPIResponse response = null;

            switch(endpoint.ToLower())
            {
                case "core":
                    response = Core(datasift, command);
                    break;
                case "historics":
                    response = Historics(datasift, command);
                    break;
                case "preview":
                    response = HistoricsPreview(datasift, command);
                    break;
                case "source":
                    response = Source(datasift, command);
                    break;
                case "push":
                    response = Push(datasift, command);
                    break;
                case "pylon":
                    response = Pylon(datasift, command);
                    break;
            }

            WriteResult(response);
        }
예제 #22
0
        private static RestAPIResponse Pylon(DataSiftClient client, string command)
        {
            RestAPIResponse response = null;

            switch (command)
            {
                case "validate":
                    response = client.Pylon.Validate(_argsParser.GetParameter<string>("csdl"));
                    break;
                case "compile":
                    response = client.Pylon.Compile(_argsParser.GetParameter<string>("csdl"));
                    break;
                case "start":
                    response = client.Pylon.Start(_argsParser.GetParameter<string>("hash"), _argsParser.GetParameter<string>("name"));
                    break;
                case "stop":
                    response = client.Pylon.Stop(_argsParser.GetParameter<string>("hash"));
                    break;
                case "get":
                    response = client.Pylon.Get(_argsParser.GetParameter<string>("hash"));
                    break;
                case "tags":
                    response = client.Pylon.Get(_argsParser.GetParameter<string>("hash"));
                    break;
                case "analyze":
                    response = client.Pylon.Analyze(_argsParser.GetParameter<string>("hash"),
                        _argsParser.GetParameter<ExpandoObject>("parameters"), _argsParser.GetParameter<string>("filter"),
                        _argsParser.GetParameter<DateTimeOffset?>("start"), _argsParser.GetParameter<DateTimeOffset?>("end"));
                    break;
                default:
                    throw new ApplicationException("Unrecognised command: " + command);
            }

            return response;
        }
예제 #23
0
        private static RestAPIResponse Push(DataSiftClient client, string command)
        {
            RestAPIResponse response = null;

            OrderDirection tmpOrderDir;
            OrderDirection? orderDir = null;
            OrderBy tmpOrderBy;
            OrderBy? orderBy = null;

            if (Enum.TryParse(_argsParser.GetParameter<string>("order_dir"), out tmpOrderDir))
                orderDir = tmpOrderDir;

            if (Enum.TryParse(_argsParser.GetParameter<string>("order_by"), out tmpOrderBy))
                orderBy = tmpOrderBy;

            switch (command)
            {
                case "validate":
                    response = client.Push.Validate(_argsParser.GetParameter<string>("output_type"),
                        _argsParser.GetParameter<ExpandoObject>("output_params"));
                    break;
                case "create":
                    PushStatus statusTemp;
                    PushStatus? status = null;

                    if (Enum.TryParse(_argsParser.GetParameter<string>("initial_status"), out statusTemp))
                        status = statusTemp;

                    response = client.Push.Create(_argsParser.GetParameter<string>("name"), _argsParser.GetParameter<string>("output_type"),
                        _argsParser.GetParameter<ExpandoObject>("output_params"), hash: _argsParser.GetParameter<string>("hash"), historicsId: _argsParser.GetParameter<string>("historics_id"),
                        initialStatus: status, start: _argsParser.GetParameter<DateTimeOffset?>("start"), end: _argsParser.GetParameter<DateTimeOffset?>("end"));
                    break;
                case "update":
                    if(_argsParser.Contains("output_params"))
                        response = client.Push.Update(_argsParser.GetParameter<string>("id"), _argsParser.GetParameter<ExpandoObject>("output_params"), name: _argsParser.GetParameter<string>("name"));
                    else
                        response = client.Push.Update(_argsParser.GetParameter<string>("id"), name: _argsParser.GetParameter<string>("name"));
                    break;
                case "pause":
                    response = client.Push.Pause(_argsParser.GetParameter<string>("id"));
                    break;
                case "resume":
                    response = client.Push.Resume(_argsParser.GetParameter<string>("id"));
                    break;
                case "delete":
                    response = client.Push.Delete(_argsParser.GetParameter<string>("id"));
                    break;
                case "stop":
                    response = client.Push.Stop(_argsParser.GetParameter<string>("id"));
                    break;
                case "log":
                    response = client.Push.Log(_argsParser.GetParameter<string>("id"), _argsParser.GetParameter<int?>("page"),
                        _argsParser.GetParameter<int?>("per_page"), orderDir);

                    break;
                case "get":
                    response = client.Push.Get(id: _argsParser.GetParameter<string>("id"), hash: _argsParser.GetParameter<string>("hash"),
                        historicsId: _argsParser.GetParameter<string>("historics_id"), page: _argsParser.GetParameter<int?>("page"),
                        perPage: _argsParser.GetParameter<int?>("per_page"), orderBy: orderBy, orderDirection: orderDir, includeFinished: _argsParser.GetParameter<bool?>("include_finished"));
                    break;
                default:
                    throw new ApplicationException("Unrecognised command: " + command);
            }

            return response;
        }
예제 #24
0
        private static RestAPIResponse HistoricsPreview(DataSiftClient client, string command)
        {
            RestAPIResponse response = null;

            switch (command)
            {
                case "create":
                    response = client.HistoricsPreview.Create(_argsParser.GetParameter<string>("hash"),
                        _argsParser.GetParameter<string[]>("sources"), _argsParser.GetParameter<List<HistoricsPreviewParameter>>("parameters"),
                        _argsParser.GetParameter<DateTimeOffset>("start"), _argsParser.GetParameter<DateTimeOffset?>("end"));
                    break;
                case "get":
                    response = client.HistoricsPreview.Get(_argsParser.GetParameter<string>("id"));
                    break;
                default:
                    throw new ApplicationException("Unrecognised command: " + command);
            }

            return response;
        }
예제 #25
0
        // Note that to run the PYLON example you must use an API key which corresponds to a valid identity with Facebook access
        internal static void Run(string username, string apikey)
        {
            var client = new DataSiftClient(username, apikey);

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

            var csdlV1 = "fb.content contains_any \"Ford, BMW, Honda\"";
            var csdlV2 = "fb.content contains_any \"Ford, BMW, Honda, Mercedes\"";

            var get = client.Pylon.Get();
            Console.WriteLine("\nCurrent of recordings / tasks: " + JsonConvert.SerializeObject(get.Data));

            client.Pylon.Validate(csdlV1);
            Console.WriteLine("CSDL for recording validated");

            var compile = client.Pylon.Compile(csdlV1);
            Console.WriteLine("Hash for filter: " + compile.Data.hash);

            var start = client.Pylon.Start(compile.Data.hash, "Example recording");
            Console.WriteLine("Recording started");

            Console.WriteLine("\nSleeping for a few seconds...");
            Thread.Sleep(5000);

            var getRecording = client.Pylon.Get(id: start.Data.id);
            Console.WriteLine("\nThis recording: " + JsonConvert.SerializeObject(getRecording.Data));

            var analysisParams = new  {
                    analysis_type = "freqDist",
                    parameters = new
                    {
                        threshold = 5,
                        target = "fb.author.age"
                    }
                };

            var analysis = client.Pylon.Analyze(start.Data.id, analysisParams);
            Console.WriteLine("\nAnalysis result: " + JsonConvert.SerializeObject(analysis.Data));

            var analysisWithFilter = client.Pylon.Analyze(start.Data.id, analysisParams, filter: "fb.author.gender == \"male\"");
            Console.WriteLine("\nAnalysis (with filter) result: " + JsonConvert.SerializeObject(analysisWithFilter.Data));

            dynamic nested = new
            {
                analysis_type = "freqDist",
                parameters = new
                {
                    threshold = 3,
                    target = "fb.author.gender"
                },
                child = new
                {
                    analysis_type = "freqDist",
                    parameters = new
                    {
                        threshold = 3,
                        target = "fb.author.age"
                    }
                }
            };

            var analysisNested = client.Pylon.Analyze(start.Data.id, nested);
            Console.WriteLine("\nNested analysis result: " + JsonConvert.SerializeObject(analysisNested.Data));

            var compile2 = client.Pylon.Compile(csdlV2);
            Console.WriteLine("\nHash for updated filter: " + compile2.Data.hash);

            var update = client.Pylon.Update(start.Data.id, hash: compile2.Data.hash, name: "Example recording - updated");
            Console.WriteLine("\nRecording updated");

            Console.WriteLine("\nSleeping for a few seconds...");
            Thread.Sleep(5000);

            getRecording = client.Pylon.Get(id: start.Data.id);
            Console.WriteLine("\nThis recording: " + JsonConvert.SerializeObject(getRecording.Data));

            var tags = client.Pylon.Tags(start.Data.id);
            Console.WriteLine("\nTags: " + JsonConvert.SerializeObject(tags.Data));

            var sample = client.Pylon.Sample(start.Data.id, count: 10);
            Console.WriteLine("\nSuper public samples: " + sample.ToJson());

            client.Pylon.Stop(start.Data.id);
            Console.WriteLine("\nRecording stopped");
        }