public static AmazonItem[] GetItems(string[] ASINs) { AmazonItem[] items = new AmazonItem[ASINs.Length]; //max 10 items allowed per request, do multiple requests for (int i = 0; i < ASINs.Length; i += 10) { // create an array with 10 ASINs string[] ASINArray = new string[10]; for (int j = i; j < i + 10 && j < ASINs.Length; j++) { ASINArray[j] = ASINs[i + j]; } // get response from amazon api Item[] returnedItems = DoAmazonItemLookup(ASINArray); // create AmazonItem objects from Item objects and add them to the array // if there is a problem with any items, or if there are duplicates, amazon will return less items. so if ASINs do not match, skip ASIN (increase skipped) int skipped = 0; for (int k = 0; k < returnedItems.Length; k++) { while (ASINs[i + k + skipped] != returnedItems[k].ASIN) { skipped++; } items[i + k + skipped] = new AmazonItem(returnedItems[k]); } } return(items); }
public static AmazonItem GetItem(string ASIN) { AmazonItem foundItem = null; // make an array with only one string and use it to find items on amazon Item[] returnedItems = DoAmazonItemLookup(new string[] { ASIN }); if (returnedItems == null) { // request did not return any items, a product with this ASIN doesnt exist return(null); } //create AmazonItem object from returned Item object foundItem = new AmazonItem(returnedItems[0]); return(foundItem); }