Exemplo n.º 1
0
        private void _searchProductsButton_Click(object sender, EventArgs e)
        {
            ArrayList _searchStringArray = CreateProductSearchString();
            ArrayList _fieldArray = new ArrayList();
            ProductList productList = new ProductList();

            string queryString = productList.QueryString(_searchStringArray, _fieldArray);
            string showString = productList.ShowString();
            BestBuyAPI.ProductRequest(queryString, showString);

            if (BestBuyAPI.Products.products != null)
            {
                for (int i = 0; i < BestBuyAPI.Products.products.Count; i++)
                {
                    _resultsListBox.Items.Add(BestBuyAPI.Products.products[i].ToString());
                }
            }
            else
            {
                _resultsListBox.Items.Add("No products found.");
            }
            _requestTextBox.Text = BestBuyAPI.UrlRequest;
        }
Exemplo n.º 2
0
        public static void ProductRequest(string queryString, string showString)
        {
            try
            {
                UrlRequest = url + queryString + showString;

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(UrlRequest);
                ((HttpWebRequest)request).UserAgent = ".NET Framework Example Client";
                WebResponse response = request.GetResponse();

                Stream       dataStream         = response.GetResponseStream();
                StreamReader reader             = new StreamReader(dataStream);
                string       responseFromServer = reader.ReadToEnd();

                Products = JsonConvert.DeserializeObject <ProductList>(responseFromServer);

                reader.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        private void _searchProductsButton_Click(object sender, EventArgs e)
        {
            ArrayList   _searchStringArray = CreateProductSearchString();
            ArrayList   _fieldArray        = new ArrayList();
            ProductList productList        = new ProductList();

            string queryString = productList.QueryString(_searchStringArray, _fieldArray);
            string showString  = productList.ShowString();

            BestBuyAPI.ProductRequest(queryString, showString);

            if (BestBuyAPI.Products.products != null)
            {
                for (int i = 0; i < BestBuyAPI.Products.products.Count; i++)
                {
                    _resultsListBox.Items.Add(BestBuyAPI.Products.products[i].ToString());
                }
            }
            else
            {
                _resultsListBox.Items.Add("No products found.");
            }
            _requestTextBox.Text = BestBuyAPI.UrlRequest;
        }
Exemplo n.º 4
0
        public static void ProductRequest(string queryString, string showString)
        {
            try
            {
                UrlRequest = url + queryString + showString + "&apiKey=" + _best_buy_api_key.Key;

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(UrlRequest);
                ((HttpWebRequest)request).UserAgent = ".NET Framework Example Client";
                WebResponse response = request.GetResponse();

                Stream dataStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream);
                string responseFromServer = reader.ReadToEnd();

                Products = JsonConvert.DeserializeObject<ProductList>(responseFromServer);

                reader.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }