Ejemplo n.º 1
0
        /// <summary>
        /// The get deals by id.
        /// </summary>
        /// <param name="dealIds">
        /// The deal ids.
        /// </param>
        /// <param name="count">
        /// The count.
        /// </param>
        /// <param name="refinements">The refinements. <seealso cref="Refinements"/> </param>
        /// <param name="format">The format of the response: "simple", "all",...</param>
        /// <returns>
        /// The <see cref="Uri"/>.
        /// </returns>
        internal Uri GetDealsById(IList <Guid> dealIds, int?count = null, Refinements refinements = null, string format = "default")
        {
            var queryString = new List <KeyValuePair <string, string> > {
                this.clientQueryParameter
            };

            if (dealIds != null && dealIds.Any())
            {
                queryString.Add(new KeyValuePair <string, string>(DealIdsKey, string.Join(",", dealIds)));
            }

            if (count.HasValue)
            {
                queryString.Add(new KeyValuePair <string, string>(CountKey, count.Value.ToString(CultureInfo.InvariantCulture)));
            }

            if (refinements != null)
            {
                queryString.Add(new KeyValuePair <string, string>(RefinementsKey, RefinementsQueryStringConstructor.ConstructString(refinements)));
            }

            if (string.Compare(format, "default", StringComparison.CurrentCultureIgnoreCase) != 0)
            {
                queryString.Add(new KeyValuePair <string, string>(FormatKey, format));
            }

            return(this.BuildUrl(GetDealsByIdMethod, queryString));
        }
        /// <summary>
        /// The construct refinements string.
        /// </summary>
        /// <param name="refinements">
        /// The refinements.
        /// </param>
        /// <returns>
        /// The refinements string
        /// </returns>
        internal static string ConstructString(Refinements refinements)
        {
            const string KeyvalueSeperator   = ":";
            const string RefinmentsSeperator = ";";
            var          propertyBag         = BuildRefinementsPropertiesBag(refinements);
            var          refinmentsList      = propertyBag.Select(elem => string.Format("{0}{1}{2}", elem.Key, KeyvalueSeperator, elem.Value));
            var          refinementsString   = string.Join(RefinmentsSeperator, refinmentsList);

            return(refinementsString);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The get online deals uri.
        /// </summary>
        /// <param name="count">
        /// The count.
        /// </param>
        /// <param name="refinements">
        /// The refinements.
        /// </param>
        /// <returns>
        /// The <see cref="Uri"/>.
        /// </returns>
        internal Uri GetOnlineDealsUri(int?count = null, Refinements refinements = null)
        {
            var queryString = new List <KeyValuePair <string, string> > {
                this.clientQueryParameter
            };

            if (count.HasValue)
            {
                queryString.Add(new KeyValuePair <string, string>(CountKey, count.Value.ToString(CultureInfo.InvariantCulture)));
            }

            if (refinements != null)
            {
                queryString.Add(new KeyValuePair <string, string>(RefinementsKey, RefinementsQueryStringConstructor.ConstructString(refinements)));
            }

            return(this.BuildUrl(GetOnlineDealsMethod, queryString));
        }
        /// <summary>
        /// Builds the  refinements properties bag.
        /// </summary>
        /// <param name="refinements">
        /// The refinements.
        /// </param>
        /// <returns>
        /// Mapping between refinement key and value
        /// </returns>
        private static Dictionary <string, string> BuildRefinementsPropertiesBag(Refinements refinements)
        {
            const string ListSplitChar = ",";

            var propertyBag = new Dictionary <string, string>();

            if (refinements.ExpiresAfter.HasValue)
            {
                // datetime ISO 8601 format
                // http://msdn.microsoft.com/en-us/library/az4se3k1.aspx#Sortable
                propertyBag.Add(ExpiresAfterString, refinements.ExpiresAfter.Value.ToString("s"));
            }

            if (refinements.ActiveBefore.HasValue)
            {
                // datetime ISO 8601 format
                // http://msdn.microsoft.com/en-us/library/az4se3k1.aspx#Sortable
                propertyBag.Add(ActiveBeforeString, refinements.ActiveBefore.Value.ToString("s"));
            }

            if (refinements.ResultsPerBusiness.HasValue)
            {
                propertyBag.Add(ResultsPerBizString, refinements.ResultsPerBusiness.Value.ToString(CultureInfo.InvariantCulture));
            }

            if (refinements.HotOffer)
            {
                propertyBag.Add(TypeString, HotOfferString);
            }

            if (refinements.Offset.HasValue)
            {
                propertyBag.Add(OffSetString, refinements.Offset.Value.ToString(CultureInfo.InvariantCulture));
            }

            if (refinements.Timeout.HasValue)
            {
                propertyBag.Add(TimeoutString, refinements.Timeout.Value.ToString(CultureInfo.InvariantCulture));
            }

            if (!string.IsNullOrEmpty(refinements.Market))
            {
                propertyBag.Add(MarketString, refinements.Market);
            }

            if (refinements.Sources != null && refinements.Sources.Any())
            {
                propertyBag.Add(SourceString, string.Join(ListSplitChar, refinements.Sources));
            }

            if (refinements.Categories != null && refinements.Categories.Any())
            {
                propertyBag.Add(CategoriesString, string.Join(ListSplitChar, refinements.Categories));
            }

            if (refinements.QueryKeywords != null && refinements.QueryKeywords.Any())
            {
                propertyBag.Add(QueryString, string.Join(ListSplitChar, refinements.QueryKeywords));
            }

            if (!string.IsNullOrEmpty(refinements.Flights))
            {
                propertyBag.Add(FlightsString, refinements.Flights);
            }

            propertyBag.Add(SortString, refinements.Sort.ToString());

            return(propertyBag);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The get deals by region uri.
        /// </summary>
        /// <param name="regionCode">
        /// The region code.
        /// </param>
        /// <param name="coordinates">
        /// The coordinates.
        /// </param>
        /// <param name="radius">
        /// The radius.
        /// </param>
        /// <param name="count">
        /// The count.
        /// </param>
        /// <param name="refinements">
        /// The refinements.
        /// </param>
        /// <param name="anid">
        /// Anid of the user
        /// </param>
        /// <returns>
        /// The <see cref="Uri"/>.
        /// </returns>
        internal Uri GetDealsByRegionUri(string regionCode, Coordinates coordinates, double?radius, int?count, Refinements refinements, string anid = null)
        {
            var queryString = new List <KeyValuePair <string, string> > {
                this.clientQueryParameter
            };

            if (coordinates != null)
            {
                queryString.Add(new KeyValuePair <string, string>(CoordKey, string.Format("{0},{1}", coordinates.Latitude, coordinates.Longitude)));
            }

            if (!string.IsNullOrEmpty(regionCode))
            {
                queryString.Add(new KeyValuePair <string, string>(RegionKey, regionCode));
            }

            if (!string.IsNullOrEmpty(anid))
            {
                queryString.Add(new KeyValuePair <string, string>(AnidKey, anid));
            }

            if (radius.HasValue)
            {
                queryString.Add(new KeyValuePair <string, string>(RadiusKey, radius.Value.ToString(CultureInfo.InvariantCulture)));
            }

            if (count.HasValue)
            {
                queryString.Add(new KeyValuePair <string, string>(CountKey, count.Value.ToString(CultureInfo.InvariantCulture)));
            }

            if (refinements != null)
            {
                queryString.Add(new KeyValuePair <string, string>(RefinementsKey, RefinementsQueryStringConstructor.ConstructString(refinements)));
            }

            return(this.BuildUrl(GetDealsByRegionMethod, queryString));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The get near by deals uri.
        /// </summary>
        /// <param name="coordinates">
        /// The coordinates.
        /// </param>
        /// <param name="radius">
        /// The radius.
        /// </param>
        /// <param name="count">
        /// The count.
        /// </param>
        /// <param name="refinements">
        /// The refinements.
        /// </param>
        /// <returns>
        /// The <see cref="Uri"/>.
        /// </returns>
        internal Uri GetNearByDealsUri(Coordinates coordinates, double?radius = null, int?count = null, Refinements refinements = null)
        {
            var queryString = new List <KeyValuePair <string, string> > {
                this.clientQueryParameter
            };

            if (coordinates != null)
            {
                queryString.Add(new KeyValuePair <string, string>(CoordKey, string.Format("{0},{1}", coordinates.Latitude, coordinates.Longitude)));
            }

            if (radius.HasValue)
            {
                queryString.Add(new KeyValuePair <string, string>(RadiusKey, radius.Value.ToString(CultureInfo.InvariantCulture)));
            }

            if (count.HasValue)
            {
                queryString.Add(new KeyValuePair <string, string>(CountKey, count.Value.ToString(CultureInfo.InvariantCulture)));
            }

            if (refinements != null)
            {
                queryString.Add(new KeyValuePair <string, string>(RefinementsKey, RefinementsQueryStringConstructor.ConstructString(refinements)));
            }

            return(this.BuildUrl(GetNearbyDealsMethod, queryString));
        }
Ejemplo n.º 7
0
        /// <summary>
        ///  list of online deals independent of user location. Asyc execution
        /// </summary>
        /// <param name="count">max result size - (optional). Default is 50</param>
        /// <param name="refinements">
        /// The refinements. <seealso cref="Refinements"/>
        /// </param>
        /// <returns>list of online deals </returns>
        public Task <IEnumerable <Deal> > GetOnlineDeals(int?count = null, Refinements refinements = null)
        {
            Uri methodUri = this.urlBuilder.GetOnlineDealsUri(count, refinements);

            return(this.GetDealsAsync(methodUri));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get deals by region to the input location. Asyc execution
        /// </summary>
        /// <param name="regionCode">the region code</param>
        /// <param name="coordinates">
        /// coordinate (optional) as latitude and longitude
        /// </param>
        /// <param name="radius">
        /// meters - (optional). Default is 1000
        /// </param>
        /// <param name="count">
        /// max result size - (optional). Default is 50
        /// </param>
        /// <param name="refinements">
        /// The refinements. <seealso cref="Refinements"/>
        /// </param>
        /// <param name="anid">
        /// Anid of the user
        /// </param>
        /// <returns>list of deals </returns>
        public Task <IEnumerable <Deal> > GetDealsByRegion(string regionCode, Coordinates coordinates, double?radius = null, int?count = null, Refinements refinements = null, string anid = null)
        {
            Uri methodUri = this.urlBuilder.GetDealsByRegionUri(regionCode, coordinates, radius, count, refinements, anid);

            return(this.GetDealsAsync(methodUri));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns list of deals nearby to the input location. Asyc execution
        /// </summary>
        /// <param name="coordinates">
        /// coordinate (required) as latitude and longitude
        /// </param>
        /// <param name="radius">
        /// meters - (optional). Default is 1000
        /// </param>
        /// <param name="count">
        /// max result size - (optional). Default is 50
        /// </param>
        /// <param name="refinements">
        /// The refinements. <seealso cref="Refinements"/>
        /// </param>
        /// <returns>list of nearby deals </returns>
        public Task <IEnumerable <Deal> > GetNearbyDeals(Coordinates coordinates, double?radius = null, int?count = null, Refinements refinements = null)
        {
            if (coordinates == null)
            {
                throw new ArgumentNullException("coordinates");
            }

            Uri methodUri = this.urlBuilder.GetNearByDealsUri(coordinates, radius, count, refinements);

            return(this.GetDealsAsync(methodUri));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns list of deals with the input id(s), or null if no such deals exist.
        /// </summary>
        /// <param name="dealIds"> The deal ids. </param>
        /// <param name="count">max result size.</param>
        /// <param name="refinements">The refinements. <seealso cref="Refinements"/></param>
        /// <param name="format">The format of the response: "simple", "all",...</param>
        /// <returns> The <see cref="IEnumerable{Deal}"/>. </returns>
        /// <exception cref="ArgumentException"> Deal ids are null or empty</exception>
        public Task <IEnumerable <Deal> > GetDealsById(IList <Guid> dealIds, int?count = null, Refinements refinements = null, string format = "default")
        {
            if (dealIds == null || !dealIds.Any())
            {
                throw new ArgumentException("Deal Ids list must contain elements", "dealIds");
            }

            Uri methodUri = this.urlBuilder.GetDealsById(dealIds, count, refinements, format);

            return(this.GetDealsAsync(methodUri));
        }