public void GetEtsyShopListingAll() { int shopId = testShops["C"]; EtsyAPIProxy ec = this.etsyAPI; EtsyDataContainer <Listing> requestedShop = ec.GetActiveListingsByShop(shopId, limit: 6); Assert.Equal <int>(requestedShop.Count, requestedShop.Results.Count); }
public void GetInvalidShopID() { int invalidShopID = int.MaxValue; EtsyAPIProxy ec = this.etsyAPI; EtsyDataContainer <Listing> requestedShop = ec.GetActiveListingsByShop(invalidShopID, 100, 0); Assert.Null(requestedShop); }
/// <summary> /// Determine the difference in listing from now to the last cached listing. /// </summary> /// <param name="shopID"></param> /// <returns></returns> public InventoryStatus GetInventoryStatus(int shopID) { Shop shop = getShopSmart(shopID); //Indicated that ShopId Invalud if (shop is null) { return(new InventoryStatus() { Shop = new Shop() { Shop_id = shopID, Shop_name = null }, IsShopIdValid = false }); } ShopInventory previousInventoryState = syncDatabase.ReadShopInventory(shopID); EtsyDataContainer <Listing> listingsFromEtsy = estyAPI.GetActiveListingsByShop(shopID); syncDatabase.PersistShopInventory(shop, listingsFromEtsy.Results); //Indicates first time request for synchronization. if (previousInventoryState == null) { return(new InventoryStatus() { Shop = shop, AsOfDate = DateTime.Today, Added = listingsFromEtsy.Results, Removed = new List <Listing>() }); } //Determine the changes between the two lists. Deltas <Listing> deltas = determineListingsDeltas(listingsFromEtsy, previousInventoryState.Listings); InventoryStatus invStat = new InventoryStatus() { Shop = shop, AsOfDate = DateTime.Today, Added = deltas.Adds, Removed = deltas.Deletes }; return(invStat); }
public EtsyDataContainer <Listing> GetActiveListingsByShop(int shopID, int limit = 100) { EtsyDataContainer <Listing> lisitingContainer = GetActiveListingsByShop(shopID, limit, 0); int iterCnt = (int)Math.Ceiling(lisitingContainer.Count / (double)limit); if (iterCnt > 0) { for (int i = 1; i < iterCnt; i++) { EtsyDataContainer <Listing> shopContainerAdded = GetActiveListingsByShop(shopID, limit, limit * i); lisitingContainer.Results.AddRange(shopContainerAdded.Results); } } return(lisitingContainer); }
private Shop getShopSmart(int shopId) { ShopInventory previousInventoryState = syncDatabase.ReadShopInventory(shopId); if (previousInventoryState != null) { return(previousInventoryState.Shop); } EtsyDataContainer <Shop> testShop = estyAPI.GetShop(shopId); if (testShop != null && testShop.Count == 1) { return(testShop.Results[0]); } else { return(null); } }
private Deltas <Listing> determineListingsDeltas(EtsyDataContainer <Listing> listingsFromEtsy, List <Listing> previousList) { Dictionary <int, Listing> prevListingAsHashTable = previousList.ToDictionary((l) => l.Listing_id); Dictionary <int, Listing> currListingAsHashTable = listingsFromEtsy.Results.ToDictionary((l) => l.Listing_id); listingsFromEtsy.Results.ForEach((l) => { if (prevListingAsHashTable.ContainsKey(l.Listing_id)) { prevListingAsHashTable.Remove(l.Listing_id); currListingAsHashTable.Remove(l.Listing_id); } }); Deltas <Listing> changes = new Deltas <Listing>() { Adds = currListingAsHashTable.Values.ToList(), Deletes = prevListingAsHashTable.Values.ToList() }; return(changes); }
public EtsyDataContainer <Shop> GetShops(IEnumerable <int> shopIDs, int limit = 100) { EtsyDataContainer <Shop> shopContainer = GetShops(shopIDs, limit, 0); if (shopContainer == null) { return(null); } int iterCnt = (int)Math.Ceiling(shopContainer.Count / 100.0); if (iterCnt > 0) { for (int i = 1; i <= iterCnt; i++) { EtsyDataContainer <Shop> shopContainerAdded = GetShops(shopIDs, limit, limit * i); shopContainer.Results.AddRange(shopContainerAdded.Results); } } return(shopContainer); }