示例#1
0
        private void ActivateAPOD(object sender, RoutedEventArgs e)
        {
            RestTalker nasaAPOD    = new RestTalker("https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY");
            APOD       todaysPhoto = nasaAPOD.talkToRestClient();

            Main_Grid.Background = new ImageBrush {
                ImageSource = new BitmapImage(new System.Uri(todaysPhoto.Url)), Stretch = Stretch.Fill
            };
            TitleWords.Text = "NASA'S A.P.O.D.:\n" + todaysPhoto.Title.ToUpper();
        }
示例#2
0
        public APOD talkToRestClient()
        {
            string responseString = string.Empty;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endPoint);

            request.Method = httpInteraction.ToString();
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(responseStream))
                    {
                        responseString = reader.ReadToEnd();
                    }
                }
            }
            APOD todaysPhoto = DeSerialize(responseString);

            return(todaysPhoto);
        }
示例#3
0
        public APOD DeSerialize(string responseString)
        {
            APOD retrievedPhoto = Newtonsoft.Json.JsonConvert.DeserializeObject <APOD>(responseString);

            return(retrievedPhoto);
        }