public IResponseBase Execute(IRequestParameter parameters)
        {
            var result = new Response <PowerReviewsResponse>();

            try
            {
                _request      = (PowerReviewsRequest)parameters;
                _request.Sort = (!string.IsNullOrEmpty(_request.Sort)) ? _request.Sort : "created_date desc";
                var cacheKey = string.Format(Config.PowerReview.CacheKeyReviews, _request.ProductId, _request.PageNumber, _request.Sort);
                result = CacheMemory.Get <Response <PowerReviewsResponse> >(cacheKey);
                if (result == null || result.resultset.Reviews.Count == 0)
                {
                    var communicationRequest = BuildUrl(parameters);
                    _response = Communicate(communicationRequest);
                    result    = ParseResponse(_response);
                    if (result.resultset.Reviews.Count > 0)
                    {
                        //per lead's request. only cache the first page
                        if (_request.PageNumber == 0)
                        {
                            CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, Config.PowerReview.Cache_TTL_InMinutes);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("PowerReviewGetReviews.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError));
            }
            return(result);
        }
Exemple #2
0
        private Tuple <List <ReviewItem>, Pagination> GetPwReviews(string productId)
        {
            var reviewsResponse = new PowerReviewsResponse();
            var reviewsRequest  = new PowerReviewsRequest();
            var reviews         = new PowerReviewGetReviews(_core);

            reviewsRequest.ProductId  = productId;
            reviewsRequest.PageNumber = 0; //API is "zero" base
            reviewsRequest.Sort       = "desc";
            var reviewResponse = ((Response <PowerReviewsResponse>)reviews.Execute(reviewsRequest)).resultset;

            return(new Tuple <List <ReviewItem>, Pagination>(reviewResponse.Reviews, reviewResponse.Pagination));
        }