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 int addClient() { api Api = new api("<INSERT_API_KEY>", "<INSERT_API_SECRET>"); batchApi batchRequest = new batchApi(Api); var success = batchRequest.Create(); 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; } }
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!"); }