Exemple #1
0
        public static IRestResponse FetchProfileUrl()
        {
            api      Api          = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>");
            batchApi batchRequest = new batchApi(Api);

            // Create a new batch
            int batchId    = batchRequest.Create();
            var parameters = new api.Parameters();

            parameters.Add("batch-id", batchId);
            parameters.Add("business-names", "La Bernardin\nBernardin Cafe\nBernardin restaraunt");
            parameters.Add("country", "USA");
            parameters.Add("city", "New York");
            parameters.Add("postcode", "10019");
            parameters.Add("local-directory", "google");


            var jobId = Api.Post("/v4/ld/fetch-profile-url", parameters);

            if (jobId.ResponseStatus == ResponseStatus.Completed)
            {
                dynamic job = JsonConvert.DeserializeObject(jobId.Content);
                if (!job.success)
                {
                    string message        = "Error adding job";
                    var    batchException = new ApplicationException(message + job.errors, job.ErrorException);
                    throw batchException;
                }
            }
            else
            {
                throw new ApplicationException(jobId.ErrorMessage);
            }

            // Commit the batch, resturns true or false
            bool commit = batchRequest.Commit(batchId);

            // Poll for results. In a real world example you should do this in a backgroud process, such as HangFire,  or use the Task Parallel Library to create a BackGroundWorker Task.
            // It is bad practice to use Thread.Sleep(). This is only for the example and will actually freeze the UI until the while loop is finished.

            var     results          = batchRequest.GetResults(batchId);
            dynamic directoryResults = JsonConvert.DeserializeObject(results.Content);

            if (directoryResults.success)
            {
                while (directoryResults.status != "Stopped" || directoryResults.status != "Finished")
                {
                    Thread.Sleep(10000);
                    results          = batchRequest.GetResults(batchId);
                    directoryResults = JsonConvert.DeserializeObject(results.Content);
                }
                return(results);
            }
            else
            {
                const string message        = "Error Retrieving batch results ";
                var          batchException = new ApplicationException(message, results.ErrorException);
                throw batchException;
            }
        }
        public static IRestResponse addReport()
        {
            api request = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>");

            var parameters = new api.Parameters();

            parameters.Add("report_name", "Sample SEO Check-Up Report");
            parameters.Add("business_names", "Le Bernardin");
            parameters.Add("schedule", "Adhoc");
            parameters.Add("day_of_month", "2");
            parameters.Add("report_type", "with");
            parameters.Add("address1", "155 Weest 51st Street");
            parameters.Add("address2", "");
            parameters.Add("city", "New York");
            parameters.Add("state_code", "NY");
            parameters.Add("postcode", "10019");
            parameters.Add("phone_number", "+1 212-554-1515");
            parameters.Add("country", "USA");
            parameters.Add("business-category", "Restaurant");
            parameters.Add("search-terms", "['restaurant manhattan', 'cafe new york']");

            var success = request.Post("v4/gpw/add", parameters);

            return(success);
        }
        public void testRequest()
        {
            //arrange
            api request = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>");
            //api request = new api("1a08b2e1fd07fa4150f91b80636906a9a29b8e47", "57645cb550c37");
            var parameters = new api.Parameters();

            parameters.Add("report_name", "Sample SEO Check-Up Report");
            parameters.Add("business_names", "Le Bernardin");
            parameters.Add("schedule", "Adhoc");
            parameters.Add("day_of_month", "2");
            parameters.Add("report_type", "with");
            parameters.Add("address1", "155 Weest 51st Street");
            parameters.Add("address2", "");
            parameters.Add("city", "New York");
            parameters.Add("state_code", "NY");
            parameters.Add("postcode", "10019");
            parameters.Add("phone_number", "+1 212-554-1515");
            parameters.Add("country", "USA");
            parameters.Add("business-category", "Restaurant");
            parameters.Add("search_terms", "['restaurant manhattan', 'cafe new york']");

            //act
            var     success = request.Post("v4/gpw/add", parameters);
            dynamic obj     = JsonConvert.DeserializeObject(success.Content);

            //assert
            Assert.AreEqual(HttpStatusCode.OK, success.StatusCode);
            Assert.IsTrue(obj.success == "true");
        }
        public static IRestResponse runReport()
        {
            api request = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>");

            var parameters = new api.Parameters();

            parameters.Add("campaign-id", "50");

            var success = request.Post("v2/lsrc/run", parameters);

            return(success);
        }
        public static IRestResponse deleteReport()
        {
            api request = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>");

            var parameters = new api.Parameters();

            parameters.Add("report-id", "682");

            var success = request.Post("v2/ct/delete", parameters);

            return(success);
        }
        public static IRestResponse addReport()
        {
            api request = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>");

            var parameters = new api.Parameters();

            parameters.Add("name", "Le Bernardin");
            parameters.Add("schedule", "Adhoc");
            parameters.Add("search-terms", "Restaurant\nfood+nyc\ndelivery+midtown+manhattan");
            parameters.Add("website-addresses", "['le-bernardin.com', 'le-bernardin2.com']");
            parameters.Add("search-engines", "google, google-mobile, google-local, yahoo, yahoo-local, bing, bing-local");
            var success = request.Post("v2/lsrc/add", parameters);

            return(success);
        }
        public static IRestResponse updateReport()
        {
            api request = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>");

            var parameters = new api.Parameters();

            parameters.Add("report-name", "Sample Citation Tracking Report");
            parameters.Add("business-name", "Le Bernardin");
            parameters.Add("business-location", "NY, New York");
            parameters.Add("phone", "+1 212-554-1515");
            parameters.Add("website", "le-bernardin.com");
            parameters.Add("business-type", "Restaurant");
            parameters.Add("state-code", "NY");

            var success = request.Post("v2/ct/update", parameters);

            return(success);
        }
        public static IRestResponse addReport()
        {
            api request = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>");

            var parameters = new api.Parameters();

            parameters.Add("report-name", "Sample Citation Tracking Report");
            parameters.Add("business-name", "Le Bernardin");
            parameters.Add("contact-telephone", "+1 212-554-1515");
            parameters.Add("address1", "155 Weest 51st Street");
            parameters.Add("address2", "");
            parameters.Add("city", "New York");
            parameters.Add("postcode", "10019");
            parameters.Add("country", "USA"); // USA only

            var success = request.Post("v4/rf/add", parameters);

            return(success);
        }
        public static IRestResponse addReport()
        {
            api request = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>");

            var parameters = new api.Parameters();

            parameters.Add("report-name", "Sample SEO Check-Up Report");
            parameters.Add("business-names", "['Le Bernardin']");
            parameters.Add("website-address", "le-bernardin.com");
            parameters.Add("address1", "155 Weest 51st Street");
            parameters.Add("address2", "");
            parameters.Add("city", "New York");
            parameters.Add("state-code", "NY");
            parameters.Add("postcode", "10019");
            parameters.Add("telephone", "+1 212-554-1515");
            parameters.Add("country", "USA");
            parameters.Add("business-category", "Restaurant");
            parameters.Add("primary-business-location", "NY, New York");
            parameters.Add("search-terms", "['restaurant manhattan', 'cafe new york']");

            var success = request.Post("v4/lscu", parameters);

            return(success);
        }
        public static IRestResponse search()
        {
            List <RankingsSearch> searches = new List <RankingsSearch>();

            searches.Add(new RankingsSearch()
            {
                search_engine   = "google",
                country         = "USA",
                google_location = "New York, NY",
                search_term     = "restaurant new york",
                urls            = new List <string>()
                {
                    "le-bernardin.com"
                },
                business_names = new List <string>()
                {
                    "Le Bernardin"
                }
            });
            searches.Add(new RankingsSearch()
            {
                search_engine   = "yahoo",
                country         = "USA",
                google_location = "New York, NY",
                search_term     = "restaurant new york",
                urls            = new List <string>()
                {
                    "le-bernardin.com"
                },
                business_names = new List <string>()
                {
                    "Le Bernardin"
                }
            });


            api      Api          = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>");
            batchApi batchRequest = new batchApi(Api);

            // Create a new batch
            int batchId    = batchRequest.Create();
            var parameters = new api.Parameters();

            // Add jobs to batch
            foreach (var item in searches)
            {
                // Convert the searches list into parameters for the web requestt
                parameters = batchRequest.convertListToParameters(item);
                parameters.Add("batch-id", batchId);

                var jobId = Api.Post("/v4/rankings/search", parameters);

                if (jobId.ResponseStatus == ResponseStatus.Completed)
                {
                    dynamic job = JsonConvert.DeserializeObject(jobId.Content);
                    if (job.success)
                    {
                        string message        = "Error adding job";
                        var    batchException = new ApplicationException(message + job.errors, job.ErrorException);
                        throw batchException;
                    }
                }
                else
                {
                    throw new ApplicationException(jobId.ErrorMessage);
                }
            }
            // Commit the batch, resturns true or false
            bool commit = batchRequest.Commit(batchId);

            // Poll for results. In a real world example you should do this in a backgroud process, such as HangFire,  or use the Task Parallel Library to create a BackGroundWorker Task.
            // It is bad practice to use Thread.Sleep(). This is only for the example and will actually freeze the UI until the while loop is finished.

            var     results        = batchRequest.GetResults(batchId);
            dynamic rankingResults = JsonConvert.DeserializeObject(results.Content);

            if (rankingResults.success)
            {
                while (rankingResults.status != "Stopped" || rankingResults.status != "Finished")
                {
                    Thread.Sleep(10000);
                    results        = batchRequest.GetResults(batchId);
                    rankingResults = JsonConvert.DeserializeObject(results.Content);
                }
                return(rankingResults);
            }
            else
            {
                const string message        = "Error Retrieving batch results ";
                var          batchException = new ApplicationException(message, results.ErrorException);
                throw batchException;
            }
        }
        public static IRestResponse bulkSearch()
        {
            List <string> searches = new List <string>(
                new string[] {
                "restaurant new york'",
                "restaurant manhattan",
                "restaurant 10019"
            });

            api      Api          = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>");
            batchApi batchRequest = new batchApi(Api);

            // Create a new batch
            int batchId    = batchRequest.Create();
            var parameters = new api.Parameters();

            parameters.Add("batch-id", batchId);
            parameters.Add("search-engine", "google");
            parameters.Add("country", "USA");
            parameters.Add("telephone", "+1 212-554-1515");
            parameters.Add("google-location", "New York, NY");
            parameters.Add("search-terms", searches);
            parameters.Add("urls", "['le-bernardin.com']");
            parameters.Add("business-names", "['Le Bernardin']");
            var jobId = Api.Post("/v4/rankings/bulk-search", parameters);

            if (jobId.ResponseStatus == ResponseStatus.Completed)
            {
                dynamic job = JsonConvert.DeserializeObject(jobId.Content);
                if (!job.success)
                {
                    string message        = "Error adding job";
                    var    batchException = new ApplicationException(message + job.errors, job.ErrorException);
                    throw batchException;
                }
            }
            else
            {
                throw new ApplicationException(jobId.ErrorMessage);
            }

            // Commit the batch, resturns true or false
            bool commit = batchRequest.Commit(batchId);

            // Poll for results. In a real world example you should do this in a backgroud process, such as HangFire,  or use the Task Parallel Library to create a BackGroundWorker Task.
            // It is bad practice to use Thread.Sleep(). This is only for the example and will actually freeze the UI until the while loop is finished.

            var     results        = batchRequest.GetResults(batchId);
            dynamic rankingResults = JsonConvert.DeserializeObject(results.Content);

            if (rankingResults.success)
            {
                while (rankingResults.status != "Stopped" || rankingResults.status != "Finished")
                {
                    Thread.Sleep(10000);
                    results        = batchRequest.GetResults(batchId);
                    rankingResults = JsonConvert.DeserializeObject(results.Content);
                }
                return(rankingResults);
            }
            else
            {
                const string message        = "Error Retrieving batch results ";
                var          batchException = new ApplicationException(message, results.ErrorException);
                throw batchException;
            }
        }
Exemple #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("BrightLocal Demo");

            List <string> localDirectories = new List <string>();

            localDirectories.Add("google");
            localDirectories.Add("yahoo");
            //localDirectories.Add("facebook");


            api      Api          = new api("api key", "secret");
            batchApi batchRequest = new batchApi(Api);

            // Create a new batch
            int batchId = batchRequest.Create();

            Console.WriteLine($"Batch created: id {batchId}");

            var model = new {
                BusinessNames = "Foo",
                City          = "New York",
                PostalCode    = "90210",
                Telephone     = "2140000000"
            };

            // Add jobs to batch
            foreach (var item in localDirectories)
            {
                var parameters = new api.Parameters();
                parameters.Add("batch-id", batchId);
                parameters.Add("business-names", model.BusinessNames);
                parameters.Add("city", model.City);
                parameters.Add("postcode", model.PostalCode);
                parameters.Add("local-directory", item);
                parameters.Add("country", "USA");

                var jobId = Api.Post("/v4/ld/fetch-reviews-by-business-data", parameters);

                Console.WriteLine($"Job created with id {jobId}");

                // NOTE: ResponseStatus.Completed doesn't exist
                if (jobId.ResponseStatus == jobId.ResponseStatus) //ResponseStatus.Completed)
                {
                    dynamic job = JsonConvert.DeserializeObject(jobId.Content);
                    if (!job.success)
                    {
                        string message        = "Error adding job";
                        var    batchException = new ApplicationException(message + job.errors, job.ErrorException);
                        throw batchException;
                    }
                }
                else
                {
                    throw new ApplicationException(jobId.ErrorMessage);
                }
            }
            // Commit the batch, resturns true or false
            bool commit = batchRequest.Commit(batchId);

            // Poll for results. In a real world example you should do this in a backgroud process, such as HangFire,  or use the Task Parallel Library to create a BackGroundWorker Task.
            // It is bad practice to use Thread.Sleep(). This is only for the example and will actually freeze the UI until the while loop is finished.

            var results        = batchRequest.GetResults(batchId);
            var resultsContent = results.Content;

            LogResults(resultsContent);
            dynamic reviewResults = JsonConvert.DeserializeObject(resultsContent);

            if (reviewResults.success)
            {
                while (reviewResults.status != "Stopped" || reviewResults.status != "Finished")
                {
                    Thread.Sleep(10000);
                    results        = batchRequest.GetResults(batchId);
                    resultsContent = results.Content;
                    LogResults(resultsContent);
                    reviewResults = JsonConvert.DeserializeObject(resultsContent);
                }
                Console.WriteLine($"Results: {reviewResults.ToString()}");
                //return reviewResults;
            }
            else
            {
                const string message        = "Error Retrieving batch results ";
                var          batchException = new ApplicationException(message + reviewResults.errors, results.ErrorException);
                Console.WriteLine("Error: " + batchException.ToString());
                throw batchException;
            }

            Console.WriteLine("Done!");
        }