Пример #1
0
        public DrawCardsModel DrawCards(string deckId, int cardAmount)
        {
            string         rawJson    = GetCardsJson(deckId, cardAmount);
            DrawCardsModel drawnCards = JsonConvert.DeserializeObject <DrawCardsModel>(rawJson);

            return(drawnCards);
        }
Пример #2
0
        public DrawCardsModel DrawCards(string deckId, int cardAmount)
        {
            // make request to api
            string url = @$"https://deckofcardsapi.com/api/deck/{deckId}/draw/?count={cardAmount}";
            HttpWebRequest request = WebRequest.CreateHttp(url);

            // store response from api
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            // convert the http response into a string of raw json
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string JSON = reader.ReadToEnd();

            // convert the raw json string into an object (DrawCardsModel) and return it
            DrawCardsModel drawnCards =  JsonConvert.DeserializeObject<DrawCardsModel>(JSON);

            return drawnCards; // is it confusing to call this "drawnCards"? I like the past-tense... I'm thinking "cards that were drawn"
        }