Example #1
0
        static OMovie RandomInput(string apiKey) // ----- change string to string[]
        {
            OMovie     movieInfo  = new OMovie();
            InvalidOId contentsIn = new InvalidOId();
            string     contents;


            // -- push the contents from random generation into the object
            do
            {
                string id = RandomGenerate();

                using (var client = new WebClient())
                {
                    string address = "http://www.omdbapi.com/?i=" + id + apiKey;
                    //Console.WriteLine(address);
                    contents = client.DownloadString(address);    // contents was originally of type var not string, declared here      // http://www.omdbapi.com/  ?i=tt389619   8&apikey=d6b3c2ae
                    if (contents.Contains("False"))
                    {
                        contentsIn = JsonConvert.DeserializeObject <InvalidOId>(contents);   // if the json string includes the word error then deserialise into contents(invalid)
                    }
                    else
                    {
                        movieInfo = JsonConvert.DeserializeObject <OMovie>(contents);
                    }
                }
            } while (movieInfo.title == null);
            return(movieInfo);
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e) // section for omdbAPI button click
        {
            string textBoxValue = textBox1.Text;

            webAddress = "http://www.omdbapi.com/";
            apiKey     = "&apikey=d6b3c2ae";
            //TextBoxString mc = new TextBoxString();
            //mc.MyProperty = textBox1_TextChanged.Text;
            string     sAddress    = webAddress + "?t=" + textBoxValue + apiKey;
            OMovie     searchMovie = new OMovie();
            InvalidOId invalid     = new InvalidOId();
            string     contents;

            using (var client = new WebClient())
            {
                contents = client.DownloadString(sAddress); // apikey unauthorized
                if (contents.Contains("False"))
                {
                    invalid = JsonConvert.DeserializeObject <InvalidOId>(contents);
                    //OSearch_Results(invalid);
                }
                else
                {
                    searchMovie = JsonConvert.DeserializeObject <OMovie>(contents);
                    OSearch_Results(searchMovie);
                }
            }

            currentID = searchMovie.imdbID;
        }