public IResponseBase Execute(IRequestParameter parameters) { StoresByZip = new List <StoreByZip>(); IResponseBase result = new Response <StoreLocatorResponse>(); try { _request = (StoreLocatorRequest)parameters; Zip = _request.Zip; var geoLocationRequestBase = new GeoLocationRequestBase { Zip = _request.Zip, City = _request.City, State = _request.State }; var geoLocationsResponse = ((Response <GeoLocationResponseBase>) new GeoLocation().Execute(geoLocationRequestBase)); var geoLocation = geoLocationsResponse.resultset.Locations.FirstOrDefault(); if (geoLocation != null) { _request.Latitude = geoLocation.Latitude; _request.Longitude = geoLocation.Longitude; _request.Zip = string.Empty; } var config = BuildApiConfig(parameters); result = GetResponse(config); } catch (Exception ex) { _errors.Add(ex.Handle("StoreLocator.GetResponse", ErrorSeverity.FollowUp, ErrorType.RequestError)); } result = ZipLocations(result); return(result); }
public IResponseBase Execute(IRequestParameter parameters) { try { if (null == parameters) { parameters = new InitRequest(); } RequestHeaderHelper.GetClientIP(_core); _request = (InitRequest)parameters; GetDashByDate(); GetCartDetails(); GetCheckout(); SetMenuAndBrands(); SetSessionInfo(); SetPingdomStatus(); //SetLatLonPosition(); SetEnvironment(); } catch (Exception ex) { string errorMsg = string.Format("({0}){1}", ex.Message, ex.StackTrace); _result.errors.Add(ex.Handle("Init: " + errorMsg, ErrorSeverity.FollowUp, ErrorType.RequestError)); } //FIX ME:CPEREZ. Make me a stand along service to be call from front-end _result.resultset.GeoLat = 0; _result.resultset.GeoLon = 0; return(_result); }
public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <AutoCompleteSearchResponse>(); try { _request = (AutocompleteSearchRequest)parameters; var cacheKey = string.Format(Config.AutocompleteSearch.CacheName, _request.SearchToken); result = CacheMemory.Get <Response <AutoCompleteSearchResponse> >(cacheKey); if (result == null || result.resultset.SearchItem.Items.Count == 0) { var communicationRequest = BuildUrl(parameters); _response = Communicate(communicationRequest); result = ParseResponse(_response); if (result.resultset.SearchItem.Items.Count > 0) { if (Config.AutocompleteSearch.IsCacheEnabled && _request.SearchToken.Length > 2) { CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, Config.AutocompleteSearch.Cache_TTL_InMin); } } } } catch (Exception) { //don't fail/performace the UI because mad search errors. //allow user to search again. return(new Response <AutoCompleteSearchResponse>()); } return(result); }
private DWClientConfig BuildApiConfig(IRequestParameter parameters) { TargetUrl = string.Empty; var sb = new StringBuilder(); sb.AppendFormat("country_code={0}", Config.Params.DefaultCountryCode); sb.AppendFormat("&distance_unit={0}", Config.Params.DefaultDistanceUnit); sb.AppendFormat("&max_distance={0}", _request.Radius); if (string.IsNullOrEmpty(_request.Zip)) { sb.AppendFormat("&latitude={0}", _request.Latitude); sb.AppendFormat("&longitude={0}", _request.Longitude); } else { sb.AppendFormat("&postal_code={0}", _request.Zip); } return(new DWClientConfig(_core) { Path = Config.DWPath.StoreLocator, Query = sb.ToString(), Method = HttpMethod.GET }); }
public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <ProductDetailResponse>(); try { _request = (ProductDetailRequest)parameters; var cacheKey = string.Format(Config.CacheKeys.ProductDetails, _request.Id, _request.Color); result = CacheMemory.Get <Response <ProductDetailResponse> >(cacheKey); if (result == null || string.IsNullOrWhiteSpace(result.resultset.Product.ProductId)) { var config = BuildAPIConfig(parameters); result = GetResponse(config); if (!result.errors.Any() && !string.IsNullOrEmpty(result.resultset.Product.ProductId)) { CacheMemory.SetAndExpiresHoursAsync(cacheKey, result, 1); } } } catch (Exception ex) { _errors.Add(ex.Handle("ProductDetail.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError)); } return(result); }
public ICommunicationRequest BuildUrl(IRequestParameter parameters) { try { var request = (CheckoutGoogleWalletPlaceOrderRequest)parameters; var url = Config.Urls.SecureBaseUrl + Config.Urls.CheckoutGoogleWalletPlaceOrder; var postSb = new StringBuilder(); postSb.AppendFormat("EnvironmentID={0}", EnvironmentHelper.GetEnvironmentId(_core.Context.Request)); postSb.AppendFormat("&fwJwt={0}", request.Jwt); postSb.AppendFormat("&fwCvn={0}", request.Cvn); postSb.AppendFormat("&fwPan={0}", request.Pan); _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.POST, url, _core, _errors) { OverridePostData = postSb.ToString() }; } catch (Exception ex) { _errors.Add(ex.Handle("CheckoutGoogleWalletPlaceOrder.BuildUrl", ErrorSeverity.FollowUp, ErrorType.BuildUrl)); } return(_core.CommunicationRequest); }
public IResponseBase Process(IResultResponse xResponse, IRequestParameter parameters, List <SiteError> errors) { _errors = errors; _cart = _session.GetCheckout().Cart; _xDoc = xResponse.XDocument; if (_xDoc != null) { _ns = _xDoc.Root.GetDefaultNamespace(); } var result = xResponse.Template.Method(xResponse, parameters); if (!_errors.Any(x => x.Type != ErrorType.UserActionRequired) && result.GetType() == typeof(Response <CartResponse>)) { var cart = ((Response <CartResponse>)result).resultset; cart.Template = xResponse.Template.TemplateName.ToString(); if (xResponse.Template.TemplateName.Equals(Config.TemplateEnum.CartDetail)) { SaveCart(cart.Cart); } else { SaveCartItemCount(cart.Cart); } } return(result); }
internal static HttpContent CreateFileContent(IRestClient client, IRequestParameter parameter, bool inMultipart = false) { if (parameter is IRequestFile) { return(CreateFileContent(client, (IRequestFile)parameter, inMultipart)); } var stream = parameter.Value as Stream; if (stream == null) { throw new InvalidOperationException("A file parameter must have a stream value"); } HttpContent content = new StreamContent(stream, 2048); if (!inMultipart) { var multipart = new MultipartFormDataContent(); multipart.Add(content, parameter.Name, parameter.Name); content = multipart; } return(content); }
/// <summary> /// SPAY-46 and SPAY-47 /// Date: 11/10/2015 /// cperez: RetryCouponBehaviorAtOnDemandWare /// parses the json frombody part of the response /// see GetLoyalCoupon... /// </summary> /// <param name="parameters"></param> /// <returns></returns> private Coupon RetryCouponBehaviorAtOnDemandWare(IRequestParameter parameters) { Coupon coupon = new Coupon(); string results = string.Empty; try { //https://staging.payless.com/on/demandware.store/Sites-payless-Site/default/COSinglePage-Start var request = (CartApplyCouponRequest)parameters; string hostEnvPath = Config.Urls.CartOnDemandWareAddCoupon; string hostEnv = Config.Urls.Domain; string couponCode = request.Coupons.FirstOrDefault().Code; string email = request.Email; string url = string.Format("https://{0}{1}?couponCode={2}&format=ajax&couponLoyaltyEmail={3}", hostEnv, hostEnvPath, couponCode, email); results = CartApplyCouponOnDemandWare.MakeRequest(url); } catch (Exception ex) { coupon.couponType = ""; coupon.CouponValue = null; coupon.loyaltyRequired = "false"; coupon.message = "Error: RetryCouponBehaviorAtOnDemandWare- " + ex.Message; } var couponObj = JsonConvert.DeserializeObject(results); coupon.status = ((dynamic)((JObject)(couponObj))).status; coupon.loyaltyRequired = ((dynamic)((JObject)(couponObj))).loyaltyRequired; coupon.message = ((dynamic)((JObject)(couponObj))).message.ToString(); coupon.sucess = ((dynamic)((JObject)(couponObj))).success; coupon.couponType = ((dynamic)((JObject)(couponObj))).couponType.ToString(); return(coupon); }
internal static StringContent ValueAsString(this IRequestParameter parameter, IRestClient client) { // TODO: get this from the client's settings var s = parameter.Value == null ? null : Convert.ToString(parameter.Value, CultureInfo.InvariantCulture); return(new StringContent(s, Encoding.UTF8, "text/plain")); }
public IResponseBase ProcessResponse(IResultResponse response, IRequestParameter parameters) { var result = new Response <CheckoutResponse>(); result.resultset = _request.CheckoutResponse; try { var dto = JsonConvert.DeserializeObject <CheckoutApplyCouponDTO>(response.RawData); if (dto.Success) { result.resultset.ApplyCouponMessage = dto.Message; (new PaylessSession(_core)).SetCheckout(result.resultset); } else { _errors.Add(new SiteError { Message = new ErrorMessage(dto.Message, dto.Message), Severity = ErrorSeverity.UserActionRequired, Type = ErrorType.UserActionRequired }); } } catch (Exception ex) { _errors.Add(ex.Handle("CheckoutApplyCoupon.ProcessResponse", ErrorSeverity.FollowUp, ErrorType.BuildUrl)); } return(result); }
public ICommunicationRequest BuildUrl(IRequestParameter parameters) { try { var checkout = ((CheckoutReviewRequest)parameters).CheckoutResponse; if (checkout != null) { var url = string.Format("{0}{1}", Config.Urls.SecureBaseUrl, Config.Urls.CheckoutReviewPost); if (!string.IsNullOrEmpty(checkout.CsrfToken)) { url = url + "?csrf_token=" + checkout.CsrfToken; } var postSb = new StringBuilder(); postSb.Append("submit=Place+Your+Order"); _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.POST, url, _core, _errors) { OverridePostData = postSb.ToString() }; } else { var url = string.Format("{0}{1}", Config.Urls.SecureBaseUrl, Config.Urls.CheckoutReviewGet); _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.GET, url, _core, _errors); } } catch (Exception ex) { _errors.Add(ex.Handle("CheckoutReview.BuildUrl", ErrorSeverity.FollowUp, ErrorType.BuildUrl)); } return(_core.CommunicationRequest); }
private RetrieveInventoryRequest BuildECRMrequest(IRequestParameter parameters) { int lotNumber; var sizeCode = 0; var sku = _request.ProductSku; var skuLength = sku.Length; var storeList = new List <int>(); _request.Stores.ForEach(store => storeList.Add(store.Id)); if (skuLength > 7) { int.TryParse(sku.Substring(0, skuLength - 3), out lotNumber); int.TryParse(sku.Substring(skuLength - 3, 3), out sizeCode); } else { int.TryParse(sku, out lotNumber); } return(new RetrieveInventoryRequest { lotQuantityList = new[] { new LotQuantity { lotNumber = lotNumber, desiredQuantity = 1, sizeCode = sizeCode } }, storeList = storeList.ToArray() }); }
public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <MenuResponse>(); try { _request = (MenuRequest)parameters; _isRoot = _request.Url.Equals(Config.Params.HrefPrefix + "root"); result = CacheMemory.Get <Response <MenuResponse> >(Config.CacheKeys.Menu); if (result == null || string.IsNullOrWhiteSpace(result.template)) { if (_request.Url.StartsWith(Config.Params.HrefPrefix)) { _request.Url = _request.Url.Remove(0, Config.Params.HrefPrefix.Length); } var config = BuildAPIConfig(parameters); result = GetResponse(config); result.template = Config.ResponseTemplates.Menu; if (_isRoot && _errors.Count == 0) { CacheMemory.SetAndExpiresHoursAsync(Config.CacheKeys.Menu, result, 4); } } } catch (Exception ex) { if (_isRoot) { _errors.Add(ex.Handle("Menu.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError)); } } return(result); }
public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <PowerReviewAvgRateResponse>(); try { _request = (PowerReviewAvgRateRequest)parameters; var cacheKey = string.Format(Config.PowerReview.CacheKeyAvgRate, _request.ProductId); result = CacheMemory.Get <Response <PowerReviewAvgRateResponse> >(cacheKey); if (result == null || result.resultset.AvgRates.Count == 0) { var communicationRequest = BuildUrl(parameters); _response = Communicate(communicationRequest); result = ParseResponse(_response); if (result.resultset.AvgRates.Count > 0) { if (Config.PowerReview.IsCacheEnabled) { CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, Config.PowerReview.Cache_TTL_InMinutes); } } } } catch (Exception ex) { _errors.Add(ex.Handle("PowerReviewGetAvgRates.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError)); } return(result); }
public ICommunicationRequest BuildUrl(IRequestParameter parameters) { try { var querySb = new StringBuilder(); querySb.Append("format=ajax"); querySb.AppendFormat("&dwfrm_requestpassword_email={0}", HttpUtility.UrlEncode(_request.UserName)); querySb.AppendFormat("&dwfrm_requestpassword_securekey={0}", _request.Form.DWSecureKey); querySb.Append("&dwfrm_requestpassword_send=submit"); var url = string.Format("{0}?{1}", _request.Form.Action, querySb.ToString()); _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.GET, url, _core, _errors) { OverrideGetTemplate = true }; } catch (Exception ex) { _errors.Add(ex.Handle("ForgotPassword.BuildUrl", ErrorSeverity.FollowUp, ErrorType.BuildUrl)); } return(_core.CommunicationRequest); }
public ICommunicationRequest BuildUrl(IRequestParameter parameters) { var url = Config.Urls.SecureBaseUrl + Config.Urls.ForgotPasswordForm; var checkout = _session.GetCheckout(); if (checkout != null) { if (!string.IsNullOrEmpty(checkout.CsrfToken)) { url = string.Format("{0}{1}&csrf_token={2}", Config.Urls.SecureBaseUrl, Config.Urls.ForgotPasswordForm, checkout.CsrfToken); } } try { _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.GET, url, _core, _errors) { OverrideGetTemplate = true }; } catch (Exception ex) { _errors.Add(ex.Handle("ForgotPasswordForm.BuildUrl", ErrorSeverity.FollowUp, ErrorType.BuildUrl)); } return(_core.CommunicationRequest); }
public IResponseBase Execute(IRequestParameter parameters) { IResponseBase result = new Response <ProductLocatorResponse>(); try { _request = (ProductLocatorRequest)parameters; var storeLocator = new StoreLocator(_core, _errors); var storeLocatorRequest = new StoreLocatorRequest { Latitude = _request.Latitude, Longitude = _request.Longitude, Zip = _request.Zip, Radius = _request.SearchRadius }; var storeLocatorResponse = storeLocator.Execute(storeLocatorRequest); if (!_errors.Any()) { _request.Stores = ((Response <StoreLocatorResponse>)storeLocatorResponse).resultset.Locations; var ecrmRequest = BuildECRMrequest(parameters); result = GetResponse(ecrmRequest); } } catch (Exception ex) { _errors.Add(ex.Handle("ProductLocator.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError)); } return(result); }
private IResponseBase ParseResponse(IResultResponse response, IRequestParameter parameters) { var result = new Response <GetLanLonPositionResponse>(); var ns = response.XDocument.Root.GetDefaultNamespace(); var scriptTag = response.XDocument.Descendants(ns + "script").Where(script => { return(script.Value.Contains("geolat") && script.Value.Contains("geolong")); }).FirstOrDefault(); if (scriptTag != null) { var script = scriptTag.Value; var latLine = GetSubString(script, "var geolat=", ";"); var lonLine = GetSubString(script, "var geolong=", ";"); var lat = GetSubString(latLine, "'", "'").Replace("'", ""); var lon = GetSubString(lonLine, "'", "'").Replace("'", ""); if (!string.IsNullOrEmpty(lat) && !string.IsNullOrEmpty(lon)) { result.resultset.Latitude = double.Parse(lat); result.resultset.Longitude = double.Parse(lon); } } return(result); }
public ICommunicationRequest BuildUrl(IRequestParameter parameters) { try { var checkout = (new PaylessSession(_core)).GetCheckout(); //TODO : why are we using checkout to store these DW-specific elements? var url = string.Format("{0}{1}{2}", Config.Urls.SecureBaseUrl, Config.Urls.CheckoutGuest, checkout.Cart.DWQuery); var postSb = new StringBuilder(); postSb.Append("dwfrm_login_unregistered=Checkout+as+Guest"); postSb.AppendFormat("&dwfrm_login_securekey={0}", checkout.DWSecureKey); _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.POST, url, _core, _errors) { OverridePostData = postSb.ToString() }; } catch (Exception ex) { _errors.Add(ex.Handle("CheckoutGuest.BuildUrl", ErrorSeverity.FollowUp, ErrorType.BuildUrl)); } return(_core.CommunicationRequest); }
public ICommunicationRequest BuildUrl(IRequestParameter parameters) { try { var cart = (new PaylessSession(_core)).GetCheckout().Cart; var url = string.Format("{0}{1}{2}", Config.Urls.SecureBaseUrl, Config.Urls.CheckoutBeginPayPal, cart.DWQuery); var postSb = new StringBuilder(); postSb.Append("dwfrm_cart_expressCheckout="); postSb.AppendFormat("&EnvironmentID={0}", EnvironmentHelper.GetEnvironmentId(_core.Context.Request)); _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.POST, url, _core, _errors) { OverridePostData = postSb.ToString(), OverrideStopAutoRedirects = true, OverrideBlockXDocumentConversion = true, OptionalReturnResponseHeaders = true }; } catch (Exception ex) { _errors.Add(ex.Handle("CheckoutBeginPayPal.BuildUrl", ErrorSeverity.FollowUp, ErrorType.BuildUrl)); } return(_core.CommunicationRequest); }
public IResponseBase ProcessResponse(IResultResponse response, IRequestParameter parameters) { var result = new Response <StringResponse>(); try { var xDoc = response.XDocument; result.resultset.Model = ParsingHelper.GetDWQuery(xDoc, "dwfrm_ordertrack"); if (string.IsNullOrEmpty(result.resultset.Model)) { _errors.Add(new SiteError { Message = new ErrorMessage(Config.Constants.GenericError, Config.Constants.GenericError), Severity = ErrorSeverity.FollowUp, Type = ErrorType.Unclassifiable }); } } catch (Exception ex) { _errors.Add(ex.Handle("OrderLookupForm.ProcessResponse", ErrorSeverity.FollowUp, ErrorType.Parsing)); } return(result); }
public ICommunicationRequest BuildUrl(IRequestParameter parameters) { try { var request = (CartUpdateRequest)parameters; var postSb = new StringBuilder(); var cart = (new PaylessSession(_core)).GetCheckout().Cart; var url = string.Format("{0}{1}{2}", Config.Urls.SecureBaseUrl, Config.Urls.CartUpdate, cart.DWQuery); postSb.Append("dwfrm_cart_updateCart=dwfrm_cart_updateCart"); postSb.Append("&dwfrm_cart_couponCode="); for (int i = 0; i < request.Items.Count; ++i) { var item = request.Items.ElementAt(i); postSb.AppendFormat("&dwfrm_cart_shipments_i0_items_i{0}_quantity={1}", i, item.Quantity); } _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.POST, url, _core, _errors) { OverridePostData = postSb.ToString() }; } catch (Exception ex) { _errors.Add(ex.Handle("CartUpdate.BuildUrl", ErrorSeverity.FollowUp, ErrorType.BuildUrl)); } return(_core.CommunicationRequest); }
private IResponseBase GetResponse(DWClientConfig config, IRequestParameter parameters) { var theParams = (CartApplyCouponRequest)parameters; var result = new Response <CheckoutResponse>(); try { var apiResponse = DWClient.GetAPIResponse <CouponResponse>(config, true); if (apiResponse.ResponseStatus.Code == HttpStatusCode.OK) { if (apiResponse.Model.success) { _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.GET, Config.Urls.ApplyBillingCouponPart2, _core, _errors); var response = _core.RequestManager.Communicate(_core.CommunicationRequest); result = ProcessCart(response, parameters); result.resultset.Cart.Coupons.Add(new CouponCodeBase() { Code = theParams.Coupons[0].Code, Message = apiResponse.Model.message }); } else { _errors.Add(new SiteError { Message = new ErrorMessage(apiResponse.Model.message, Config.Constants.GenericError) }); } } } catch (Exception ex) { _errors.Add(ex.Handle("CheckoutBillingCoupon.GetResponse", ErrorSeverity.FollowUp, ErrorType.RequestError)); } return(result); }
public ICommunicationRequest BuildUrl(IRequestParameter parameters) { string url = Config.Urls.SecureBaseUrl + Config.Urls.CartAdd; try { var request = (CartAddRequest)parameters; var postSb = new StringBuilder(); postSb.AppendFormat("Quantity={0}", request.Quantity); postSb.Append("&cartAction=add"); postSb.Append("&omnitureAddToCartType=Product+View"); postSb.AppendFormat("&pid={0}", request.Sku); _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.POST, url, _core, _errors) { OverridePostData = postSb.ToString() }; } catch (Exception ex) { _errors.Add(ex.Handle("CartAdd.BuildUrl", ErrorSeverity.FollowUp, ErrorType.BuildUrl)); } return(_core.CommunicationRequest); }
public IResponseBase ProcessResponse(IResultResponse response, IRequestParameter parameters) { var result = new Response <StringResponse>(); var xDoc = response.XDocument; try { result.resultset.Model = ParsingHelper.GetDWQuery(xDoc, "NewPasswordForm"); if (string.IsNullOrEmpty(result.resultset.Model)) { result.resultset.Model = ParsingHelper.GetDWQuery(xDoc, "PasswordResetForm"); if (string.IsNullOrEmpty(result.resultset.Model)) { _errors.Add(new SiteError { Message = new ErrorMessage(Config.Constants.GenericError, Config.Constants.GenericError), Severity = ErrorSeverity.UserActionRequired, Type = ErrorType.UserActionRequired }); } } } catch (Exception ex) { _errors.Add(ex.Handle("ResetPasswordForm.ProcessResponse", ErrorSeverity.FollowUp, ErrorType.Parsing)); } return(result); }
public ICommunicationRequest BuildUrl(IRequestParameter parameters) { try { var request = (CheckoutPayPalSuccessRequest)parameters; var session = new PaylessSession(_core); var cart = session.GetCheckout(); var url = new StringBuilder(); url.Append(Config.Urls.SecureBaseUrl); url.Append(Config.Urls.CheckoutPayPalSuccess); url.AppendFormat("?dwcont={0}", request.DWControl); url.AppendFormat("&token={0}", request.Token); url.AppendFormat("&PayerID={0}", request.PayerId); _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.GET, url.ToString(), _core, _errors); } catch (Exception ex) { _errors.Add(ex.Handle("CheckoutPayPalSuccess.BuildUrl", ErrorSeverity.FollowUp, ErrorType.BuildUrl)); } return(_core.CommunicationRequest); }
public IResponseBase ProcessResponse(IResultResponse response, IRequestParameter parameters) { IResponseBase result = new Response <BoolResponse>(); try { if (response.Template.Service != null) { result = response.Template.Service.Process(response, parameters, _errors); } else { _errors.Add(new SiteError { Message = new ErrorMessage(Config.Constants.GenericError, Config.Constants.GenericError), Severity = ErrorSeverity.UserActionRequired, Type = ErrorType.UserActionRequired }); } } catch (Exception ex) { _errors.Add(ex.Handle("CheckoutBeginPayPal.ProcessResponse", ErrorSeverity.FollowUp, ErrorType.Parsing)); } return(result); }
public ICommunicationRequest BuildUrl(IRequestParameter parameters) { try { var request = parameters as PowerReviewsRequest; var productId = request.ProductId; var page = request.PageNumber; _sort = request.Sort; _pageSize = Config.PowerReview.PageSize; var url = string.Format(Config.PowerReview.ReviewsUrl, Config.PowerReview.ApiKey, Config.PowerReview.MerchantId, _pageSize, request.ProductId); if (page == 0) { _displayFrom = 1; _displayTo = _pageSize; } else { _displayFrom = (page * _pageSize) + 1; _displayTo = (page * _pageSize) + _pageSize; } _currentPage = page; url = url + "&page=" + page; _sort = (!string.IsNullOrEmpty(_sort)) ? _sort : "created_date desc"; url = url + "&sort=" + _sort; _core.CommunicationRequest = new ExtendedComRequest(HttpRequestMethod.GET, url, _core, _errors); } catch (Exception ex) { _errors.Add(ex.Handle("PowerReviewGetReviews.BuildUrl", ErrorSeverity.FollowUp, ErrorType.BuildUrl)); } return(_core.CommunicationRequest); }
public IResponseBase Execute(IRequestParameter parameter) { var config = BuildAPIConfig(parameter); var result = GetResponse(config); return(result); }
/// <summary> /// Create Content-Type header value based on the provided parameters /// </summary> /// <param name="request">Request for which Content-Type header is generated</param> /// <param name="firstRequestParameter">First parameter which was used in generating post request body</param> private static void InitContentTypeHeader(PostRequest request, IRequestParameter firstRequestParameter) { request.ContentTypeHeader = string.Format(TypeHeaderTemplate, firstRequestParameter.ParameterType == RequestParameterType.Basic ? "application/x-www-form-urlencoded" : "multipart/form-data"); if (firstRequestParameter.ParameterType != RequestParameterType.Basic) { request.ContentTypeHeader += string.Format(BoundaryDefinitionTemplate, request.BoundaryValue); } request.ContentTypeHeader += NewLine; }
public void Consumer_CreateRequest() { //arrange var provider = A.Fake<IOAuthProvider>(); IConsumer consumer = new ConsumerFactory(options, provider) .CreateConsumer(); var request_token = "requestToken"; var request_token_secret = "requestTokenSecret"; var authorize_url = new Uri("http://expectedUrl"); var verifier = "verifier"; var getRequestTokenRequestResult = string.Format("oauth_token={0}&oauth_token_secret={1}&oauth_expires_in=124&xoauth_request_auth_url={2}", request_token, request_token_secret, authorize_url); var access_token = "accessToken"; var access_token_secret = "accessTokenSecret"; var getAccessTokenRequestResult = string.Format("oauth_token={0}&oauth_token_secret={1}&oauth_expires_in=124&oauth_session_handle=12334&oauth_authorization_expires_in=1234", access_token, access_token_secret); A.CallTo(() => provider.GetRequestTokenRequest( A<string>._, A<string>._, A<string>._, A<string>._, A<SignatureMethod>._)) .Returns(getRequestTokenRequestResult); A.CallTo(() => provider.GetGetAccessTokenRequest( A<string>._, A<string>._, A<string>._, A<string>._, A<SignatureMethod>._, A<string>._, A<string>._)) .Returns(getAccessTokenRequestResult); var requestParameters = new IRequestParameter[] { new RequestParameter("test1", "value1"), new RequestParameter("test2", "value2") }; //act consumer.RequestLogin(); consumer.AuthorizeUser(verifier); var request = consumer.CreateHttpRequest("http://test123", HttpMethod.GET, requestParameters); //assert A.CallTo(() => provider.GetRequestTokenRequest( options.RequestTokenUrl, options.ConsumerKey, options.ConsumerSecret, options.RequestTokenResponseCallbackUrl, options.SignatureMethod)); A.CallTo(() => provider.GetGetAccessTokenRequest( options.AccessTokenUrl, options.ConsumerKey, options.ConsumerSecret, request_token_secret, options.SignatureMethod, request_token, verifier)); var requestString = request.RequestUri.ToString(); var expectedSignature = OAuthMessageBuilder.GetOAuthSignature_PlainText(options.ConsumerSecret, null); Assert.IsTrue(requestString.Contains(options.ConsumerKey), "ConsumerKey"); Assert.IsTrue(requestString.Contains("plaintext"), "SignatureMethod"); Assert.IsTrue(requestString.Contains("test1=value1"), "test1"); Assert.IsTrue(requestString.Contains("test2=value2"), "test2"); Assert.IsTrue(requestString.Contains(expectedSignature), "signature"); }