public static DataTable DownloadXMLData(Constants.APITypeURL type)//, object sender, EventArgs e) { //WebClient client = new WebClient(); //client.Headers.Add("Fk-Affiliate-Id", Constants.FlipKart_AffiliateId); //client.Headers.Add("Fk-Affiliate-Token", Constants.FlipKart_AffiliateToken); XElement xele; DataTable dt = new DataTable(); //switch (type) //{ // case Constants.APITypeURL.AmericanSwanCPA: // xele = XElement.Load(Constants.AmericanSwanCPA); // dt = clsFileToTable.XElementToDataTable(xele); // break; // case Constants.APITypeURL.JabongcomSales: // xele = XElement.Load(Constants.JabongcomSales); // dt = clsFileToTable.XElementToDataTable(xele); // break; // case Constants.APITypeURL.KoovscomCostPerSale: // xele = XElement.Load(Constants.KoovscomCostPerSale); // dt = clsFileToTable.XElementToDataTable(xele); // break; // case Constants.APITypeURL.MyntracomSaleExistingUser: // xele = XElement.Load(Constants.MyntracomSaleExistingUser); // dt = clsFileToTable.XElementToDataTable(xele); // break; // case Constants.APITypeURL.PaytmPaytmnonrecharge: // xele = XElement.Load(Constants.PaytmPaytmnonrecharge); // dt = clsFileToTable.XElementToDataTable(xele); // break; // case Constants.APITypeURL.TrendincomCostPerSale: // xele = XElement.Load(Constants.TrendincomCostPerSale); // dt = clsFileToTable.XElementToDataTable(xele); // break; // case Constants.APITypeURL.ZoviComSale: // xele = XElement.Load(Constants.ZoviComSale); // dt = clsFileToTable.XElementToDataTable(xele); // break; // default: // break; //} return(dt); }
// Constants.NameOfMerchants api; protected void btnRunAPI_Click(object sender, EventArgs e) { if (uc_MerchantListItem.SelectedMerchant != string.Empty) { string strFlipKart = uc_MerchantListItem.SelectedMerchantText; //Response.Write(strFlipKart); //api = (Constants.NameOfMerchants)Enum.Parse(typeof(Constants.NameOfMerchants), strFlipKart.Contains(Constants.NameOfMerchants.FlipKart.ToString()) ? "FlipKart" : ""); Constants.APITypeURL type = (Constants.APITypeURL)Enum.Parse(typeof(Constants.APITypeURL), rdbApiTypeURL.SelectedValue.ToString()); DownloadData(type, sender, e, uc_MerchantListItem.SelectedMerchant); //switch (api) //{ // case Constants.NameOfMerchants.FlipKart: // Constants.APITypeURL type = (Constants.APITypeURL)Enum.Parse(typeof(Constants.APITypeURL), rdbApiTypeURL.SelectedValue.ToString()); // DownloadData(type, sender, e, uc_MerchantListItem.SelectedMerchant); // break; // default: // break; //} } }
public void DownloadData(Constants.APITypeURL type, object sender, EventArgs e, string MID) { WebClient client = new WebClient(); client.Headers.Add("Fk-Affiliate-Id", Constants.FlipKart_AffiliateId); client.Headers.Add("Fk-Affiliate-Token", Constants.FlipKart_AffiliateToken); switch (type) { case Constants.APITypeURL.FlipKart_DOTD_OffersAPI: //var test = client.DownloadString(" https://affiliate-api.flipkart.net/affiliate/feeds/aashishsh/category/v1:reh.xml?expiresAt=1425146502079&sig=6259329061d2b8a0b81b7982eaf07d70"); var dotd = client.DownloadString(Constants.FlipKart_DOTD_Offers_API); DataContractJsonSerializer sdotd = new DataContractJsonSerializer(typeof(DOTD)); using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(dotd))) { // deserialize the JSON object using the WeatherData type.//Repeater1.DataSource = weatherData.dotdList;//Repeater1.DataBind(); var itemDotd = (DOTD)sdotd.ReadObject(ms); int itemNo = 0; foreach (DotdList item in itemDotd.dotdList) { this.CategoryID_N = clsGetAppIDs.GetCategoryIDByText("DOTD"); if (this.CategoryID_N > 0) { this.Title = item.title; this.Description = item.description; this.NavigationURL = item.url; this.Availability = item.availability; this.Ad_Type = Constants.APITypeURL.FlipKart_DOTD_OffersAPI; //this.Ad_For =Convert.ToInt16(MID); this.MID = Convert.ToInt16(MID); this.ImageUrl = item.imageUrls[0].url; itemNo = itemNo + 1; this.SerialNo = itemNo; CreateProduct(sender, e); } } } break; case Constants.APITypeURL.FlipKart_TOP_Offers_API: var topOffer = client.DownloadString(Constants.FlipKart_TOP_Offers_API); DataContractJsonSerializer serializertopOff = new DataContractJsonSerializer(typeof(TopOffer)); using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(topOffer))) { var topOff = (TopOffer)serializertopOff.ReadObject(ms); int itemNo = 0; foreach (TopOffersList item in topOff.topOffersList) { this.CategoryID_N = clsGetAppIDs.GetCategoryIDByText("Top Offer"); if (this.CategoryID_N > 0) { this.Title = item.title; this.Description = item.description; this.NavigationURL = item.url; this.Availability = item.availability; this.Ad_Type = Constants.APITypeURL.FlipKart_TOP_Offers_API; //this.Ad_For = api; this.MID = Convert.ToInt16(MID); this.ImageUrl = item.imageUrls[0].url; itemNo = itemNo + 1; this.SerialNo = itemNo; CreateProduct(sender, e); } } } break; case Constants.APITypeURL.FlipKart_Product_Feeds_API: HttpWebRequest webRequest = HttpWebRequest.Create(ddlCategory.SelectedValue.ToString()) as HttpWebRequest; webRequest.Method = WebRequestMethods.Http.Get; webRequest.ContentType = "text/xml; charset=utf-8"; webRequest.Headers.Add("Fk-Affiliate-Id", Constants.FlipKart_AffiliateId); webRequest.Headers.Add("Fk-Affiliate-Token", Constants.FlipKart_AffiliateToken); //webRequest.ContentType = "application/x"; using (HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse) { if (response.StatusCode == HttpStatusCode.OK) { Encoding encoding; try { encoding = Encoding.GetEncoding(response.CharacterSet); } catch { encoding = Encoding.UTF8; } StreamReader reader = new StreamReader(response.GetResponseStream(), encoding); var categoryItems = reader.ReadLine(); XmlDocument doc = new XmlDocument(); doc.Load(reader); //XElementToDataTable(categoryItems, sender, e); } } // var categoryItems = client.DownloadString(); //XElementToDataTable(categoryItems, sender, e); break; default: break; } }