Ejemplo n.º 1
0
        public Response <PowerReviewSnapshotResponse> ParseResponse(IResultResponse response)
        {
            var result = new Response <PowerReviewSnapshotResponse>();

            result.resultset.Snapshot = PowerReviewHelper.GetSnapshot(response.RawData);
            return(result);
        }
Ejemplo n.º 2
0
        private IResponseBase GetResponse(DWClientConfig config)
        {
            var result = new Response <ProductListExtensionResponse>();

            try
            {
                APIResponse apiResponse = null;
                if (_hasMultipleProducts)
                {
                    apiResponse = DWClient.GetAPIResponse <ProductResult>(config);
                }
                else
                {
                    apiResponse = DWClient.GetAPIResponse <DWProduct>(config);
                }

                if (apiResponse.ResponseStatus.Code == HttpStatusCode.OK)
                {
                    if (_hasMultipleProducts)
                    {
                        var productResult = ((APIResponse <ProductResult>)apiResponse).Model;
                        productResult.Products = SetProductBrands(productResult.Products, apiResponse.Raw);
                        result.resultset       = new ProductListExtensionResponse(productResult, _request.Colors, apiResponse.Raw);
                    }
                    else
                    {
                        var product = ((APIResponse <DWProduct>)apiResponse).Model;
                        if (_usePredefinedVariations)
                        {
                            ReplaceColors(product);
                        }

                        result.resultset = new ProductListExtensionResponse(ProductListExtensionResponse.GetProductResult(product), _request.Colors, apiResponse.Raw);
                    }

                    result.template = Config.ResponseTemplates.ProductListExtension;
                    foreach (var productItem in result.resultset.ProductIdToExtension)
                    {
                        try
                        {
                            var productsnapshot = PowerReviewHelper.GetSnapshot(productItem.Key);
                            productItem.Value.Rating = (productsnapshot.average_rating == null)? 0: decimal.Parse((productsnapshot.average_rating));
                        }
                        catch (Exception ex)
                        {
                            productItem.Value.Rating = 0;
                        }
                    }
                }
                else
                {
                    _errors.Add(new SiteError {
                        Message = new ErrorMessage(Config.Constants.GenericError, apiResponse.ResponseStatus.Message.ToString())
                    });
                }
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("ProductListExtension.GetResponse", ErrorSeverity.FollowUp, ErrorType.RequestError));
            }

            return(result);
        }