示例#1
0
        public async Task <Tuple <StarWarsSearchModel, ChuckSearchModel> > ReturnSearch(string query)
        {
            var randomSearchChuckNorrisAPIUrl = APIUrlDictionary.GetApiUrls()["randomSearchChuckNorrisAPIUrl"];
            var randomSearchStarwarsAPIUrl    = APIUrlDictionary.GetApiUrls()["randomSearchStarwarsAPIUrl"];

            using (var client = new HttpClient())
            {
                var chuck_url = new Uri(randomSearchChuckNorrisAPIUrl + query);
                var swapi_url = new Uri(randomSearchStarwarsAPIUrl + query);

                var chuck_response = await client.GetAsync(chuck_url);

                var swapi_response = await client.GetAsync(swapi_url);

                StarWarsSearchModel myDeserializedStarClass  = JsonConvert.DeserializeObject <StarWarsSearchModel>(GetJson(swapi_response).Result);
                ChuckSearchModel    myDeserializedChuckClass = JsonConvert.DeserializeObject <ChuckSearchModel>(GetJson(chuck_response).Result);

                return(new Tuple <StarWarsSearchModel, ChuckSearchModel>(myDeserializedStarClass, myDeserializedChuckClass));
            }
        }
示例#2
0
        public async Task <RandomJokeModel> ReturnRandomJoke(string category)
        {
            var chuckNorrisRandomJokeAPIUrl = APIUrlDictionary.GetApiUrls()["chuckNorrisRandomJokeAPIUrl"];

            using (var client = new HttpClient())
            {
                var url = new Uri(chuckNorrisRandomJokeAPIUrl + category);

                var response = await client.GetAsync(url);

                string json;
                using (var content = response.Content)
                {
                    json = await content.ReadAsStringAsync();
                }

                RandomJokeModel randomJoke = JsonConvert.DeserializeObject <RandomJokeModel>(json);

                return(randomJoke);
            }
        }
示例#3
0
        public async Task <PeopleModel> ReturnPeople()
        {
            var starWarsPeopleAPIUrl = APIUrlDictionary.GetApiUrls()["starWarsPeopleAPIUrl"];

            using (var client = new HttpClient())
            {
                var url = new Uri(starWarsPeopleAPIUrl);

                var response = await client.GetAsync(url);

                string json;
                using (var content = response.Content)
                {
                    json = await content.ReadAsStringAsync();
                }

                PeopleModel people = JsonConvert.DeserializeObject <PeopleModel>(json);

                return(people);
            }
        }
示例#4
0
        public async Task <List <string> > ReturnJokesCatergories()
        {
            var chuckNorrisJokeCategoriesAPIUrl = APIUrlDictionary.GetApiUrls()["chuckNorrisJokeCategoriesAPIUrl"];

            using (var client = new HttpClient())
            {
                var url = new Uri(chuckNorrisJokeCategoriesAPIUrl);

                var response = await client.GetAsync(url);

                string json;
                using (var content = response.Content)
                {
                    json = await content.ReadAsStringAsync();
                }

                var           res  = JokesModel.FromJson(json);
                List <string> list = new List <string>(res);

                return(list);
            }
        }