In this post, I will go over how I implemented integration between my Episerver website with ProductReview.com.au
There were three things involved in the development:
- Custom Plugin – This really is just a settings page that allows authors to add multiple endpoints/APIs from Product Reviews (i.e. you have multiple products up for reviews)
- Scheduled job that grabs the latest reviews for all your products and stores the response internally
- New block that allows authors to render the outcome of the product review
Two reasons why we opted for the scheduled job approach instead of server-side/AJAX call on render of page are:
- Performance – we don’t have to make an extra server-side call to Product Reviews every time a webpage on your site is rendered since the latest results are already stored internally
- SEO – Google can’t index these reviews if the reviews are loaded through an AJAX call. The reviews have to be part of the first render of the page.
[TABS_R id=2594]
Scheduled Job
[ScheduledPlugIn(DisplayName = "External Data Importer")]
public class DataImportScheduledJob : ScheduledJobBase
{
private readonly DataImportService _dataImportService;
private bool _stopSignaled;
public DataImportScheduledJob(DataImportService dataImportService)
{
_dataImportService = dataImportService;
IsStoppable = true;
}
public override void Stop()
{
_stopSignaled = true;
}
public override string Execute()
{
//Call OnStatusChanged to periodically notify progress of job for manually started jobs
OnStatusChanged(String.Format("Starting execution of {0}", this.GetType()));
var endpoints = _dataImportService.GetAllImportedData();
foreach (var endpoint in endpoints.Where(e => !string.IsNullOrEmpty(e.Endpoint)))
{
OnStatusChanged(String.Format("Importing data for {0}", endpoint.Source));
using (var webClient = new WebClient())
{
endpoint.Response = webClient.DownloadString(endpoint.Endpoint);
endpoint.ImportDate = DateTime.Now;
_dataImportService.UpdateDataImport(endpoint);
}
if (_stopSignaled)
{
return "Stop of job was called";
}
}
return "All configured external data have been imported";
}
}
[TABS_R id=2774]
And this is what the new block looks like: