Ejemplo n.º 1
0
        /// <summary>
        /// Retrieves the first card price assosciated with the card.
        /// </summary>
        /// <param name="name">The case sensitive name of the card to base the search off of.</param>
        /// <returns>A CardPrices object.</returns>
        /// <exception cref="HttpRequestException">If the 'status' of the request is not success, this exception will throw with the message from the Json as the exception's message.</exception>
        public async Task <CardPrices> GetCardPricesByName(string name)
        {
            JObject message = JObject.Parse(await WebWrapper.Get(Endpoints.BaseURL + Endpoints.CardPrices + name).ConfigureAwait(false));

            if (message["status"].ToString() == "success")
            {
                CardPrices prices = new CardPrices();
                await Task.Factory.StartNew(() =>
                {
                    JArray data = JArray.Parse(message["data"].ToString());
                    if (data.Count > 0)
                    {
                        prices = JsonConvert.DeserializeObject <CardPrices>(data[0].ToString());
                        if (data[0]["price_data"]["status"].ToString() == "success")
                        {
                            prices.PriceData = JsonConvert.DeserializeObject <PriceData>(data[0]["price_data"]["data"]["prices"].ToString());
                        }
                    }
                });

                prices.Card = await GetCardByName(name).ConfigureAwait(false);

                return(prices);
            }
            else
            {
                throw new HttpRequestException(message["message"].ToString() != null ? message["message"].ToString() : "Couldn't get the card's prices.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets *all* of the card's prices.
        /// </summary>
        /// <param name="name">The case sensitive name of the card.</param>
        /// <returns>An array of CardPrices objects. Remember: CardPrices has a field called Card that contains the Card object so you don't have to perform a GetCardByName also.</returns>
        /// <exception cref="HttpRequestException">If the 'status' of the request is not success, this exception will throw with the message from the Json as the exception's message.</exception>
        public async Task <CardPrices[]> GetAllCardPricesByName(string name)
        {
            JObject message = JObject.Parse(await WebWrapper.Get(Endpoints.BaseURL + Endpoints.CardPrices + name).ConfigureAwait(false));

            if (message["status"].ToString() == "success")
            {
                List <CardPrices> list = new List <CardPrices>();
                Card card = await GetCardByName(name).ConfigureAwait(false);

                await Task.Factory.StartNew(() =>
                {
                    JArray data = JArray.Parse(message["data"].ToString());
                    foreach (var priceDataObject in data.Children())
                    {
                        CardPrices p = JsonConvert.DeserializeObject <CardPrices>(priceDataObject.ToString());
                        if (priceDataObject["price_data"]["status"].ToString() == "success")
                        {
                            p.PriceData = JsonConvert.DeserializeObject <PriceData>(priceDataObject["price_data"]["data"]["prices"].ToString());
                        }
                        p.Card = card;
                        list.Add(p);
                    }
                });

                if (list.Count > 0)
                {
                    return(list.ToArray());
                }
            }
            else
            {
                throw new HttpRequestException(message["message"].ToString() != null ? message["message"].ToString() : "Couldn't get the card's prices.");
            }
            return(null);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Retrieves the first card price assosciated with the card.
 /// </summary>
 /// <param name="name">The case sensitive name of the card to base the search off of.</param>
 /// <returns>A CardPrices object.</returns>
 /// <exception cref="HttpRequestException">If the 'status' of the request is not success, this exception will throw with the message from the Json as the exception's message.</exception>
 public async Task<CardPrices> GetCardPricesByName(string name)
 {
     JObject message = JObject.Parse(await WebWrapper.Get(Endpoints.BaseURL + Endpoints.CardPrices + name).ConfigureAwait(false));
     if(message["status"].ToString() == "success")
     {
         CardPrices prices = new CardPrices();
         await Task.Factory.StartNew(() => 
         {
             JArray data = JArray.Parse(message["data"].ToString());
             if (data.Count > 0)
             {
                 prices = JsonConvert.DeserializeObject<CardPrices>(data[0].ToString());
                 if (data[0]["price_data"]["status"].ToString() == "success")
                 {
                     prices.PriceData = JsonConvert.DeserializeObject<PriceData>(data[0]["price_data"]["data"]["prices"].ToString());
                 }
             }
         });
         prices.Card = await GetCardByName(name).ConfigureAwait(false);
         return prices;
     }
     else
     {
         throw new HttpRequestException(message["message"].ToString() != null ? message["message"].ToString() : "Couldn't get the card's prices.");
     }
 }