예제 #1
0
        /// <summary>
        /// Private utility method that makes call to server using the FrgxApicallHelper object and casts response into a Product object
        /// </summary>
        /// <param name="url">Url the get request is sent to</param>
        /// <returns>A product object</returns>
        /// <exception cref="FrgxPublicApiSDK.Exceptions.InvalidArgumentException">Thrown if given invald id or upcCode</exception>
        private Product GetProduct(string url)
        {
            string response = FrgxApicallHelper.GetApi(url).Result;

            //If bad ID or UPC code

            if (response.ToLower().StartsWith("{\"message\":\"") || response.ToLower().StartsWith("<!doctype"))
            {
                throw (new InvalidArgumentException("Id or upcCode is Invalid!"));
            }

            return(ProductMapper.Map(JObject.Parse(response)));
        }
예제 #2
0
        //Public Methods
        /// <summary>
        /// Retrieves the tracking information for a given order id.
        /// </summary>
        /// <param name="orderId">Either the FragranceX order ID or external ID that you want to retrieve the tracking information for.</param>
        /// <returns>An object of basic tracking information</returns>
        /// <exception cref="FrgxPublicApiSDK.Exceptions.EmptyFeildException">Thrown if missing order id</exception>
        /// <exception cref="FrgxPublicApiSDK.Exceptions.InvalidArgumentException">Thrown if invalid order id</exception>
        public TrackingInfo GetTracking(string orderId)
        {
            if (string.IsNullOrEmpty(orderId))
            {
                throw (new EmptyFeildException("No orderId given"));
            }

            var response = FrgxApicallHelper.GetApi(Constants.FrgxapiTracking + orderId).Result;

            var jResponse = JObject.Parse(response);

            if (jResponse.GetValue("Carrier").ToString() == "")
            {
                throw (new InvalidArgumentException("Invalid order id: " + orderId));
            }

            return(TrackingMapper.Map(jResponse));
        }
예제 #3
0
        /// <summary>
        /// Helper method for creating a HTTP request.
        /// The result of the request is then parsed and returned.
        /// </summary>
        /// <param name="url">URL of the HTTP request</param>
        /// <returns>A list of Product objects</returns>
        private List <Product> GetList(string url)
        {
            var response = FrgxApicallHelper.GetApi(url).Result;

            if (response.ToLower().StartsWith("{\"message\":\"") || response.ToLower().StartsWith("<!doctype"))
            {
                return(new List <Product>());
            }

            var jList = JArray.Parse(response);

            var prodList = new List <Product>();

            foreach (JObject jProd in jList.Children())
            {
                prodList.Add(ProductMapper.Map(jProd));
            }

            return(prodList);
        }