Exemplo n.º 1
0
        private FindCompletedItemsRequest CreateCompletedItemsRequest(Search searchItem, int pageNumber)
        {
            // Completed items, new only
            var request = new FindCompletedItemsRequest();
            List<ItemFilter> filters = new List<ItemFilter>();

            // Search term
            foreach (SearchCriteria criteria in searchItem.SearchCriteria)
            {
                switch (criteria.Criteria)
                {
                    case "Title":
                        request.keywords = criteria.Value;
                        break;

                    case "Condition":
                        filters.Add(new ItemFilter() { name = ItemFilterType.Condition, value = new string[] { criteria.Value, "1000" } });
                        break;

                    case "SoldItemsOnly":
                        filters.Add(new ItemFilter() { name = ItemFilterType.SoldItemsOnly, value = new string[] { criteria.Value } });
                        break;

                    case "Currency":
                        filters.Add(new ItemFilter() { name = ItemFilterType.Currency, value = new string[] { criteria.Value } });
                        break;
                }
            }

            // Filters to specify new, sold and GBP
            // Wire up default values

            if (String.IsNullOrEmpty(request.keywords))
                request.keywords = searchItem.Name;

            if (filters.Find(f => f.name == ItemFilterType.Currency) == null)
                filters.Add(new ItemFilter() { name = ItemFilterType.Currency, value = new string[] { "GBP" } });

            //if (filters.Find(f => f.name == ItemFilterType.Condition) == null)
            //    filters.Add(new ItemFilter() { name = ItemFilterType.Condition, value = new string[] { "New" , "1000"} });

            if (filters.Find(f => f.name == ItemFilterType.SoldItemsOnly) == null)
                filters.Add(new ItemFilter() { name = ItemFilterType.SoldItemsOnly, value = new string[] { "True" } });

            // Have we recently updated ... if so, ask for items since we last updated
            if (searchItem.LastRun != null)
            {
                filters.Add(
                    new ItemFilter() { name = ItemFilterType.EndTimeFrom, value = new string[] { searchItem.LastRun.ToString("s") } }
                    );
            }

            // Add the page number
            request.paginationInput = new PaginationInput();
            request.paginationInput.pageNumber = pageNumber;
            request.paginationInput.pageNumberSpecified = true;

            request.itemFilter = filters.ToArray();
            request.sortOrder = SortOrderType.EndTimeSoonest;

            return request;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Actual fetch of seller's completed items
 /// </summary>
 /// <param name="service"></param>
 /// <param name="request"></param>
 /// <param name="currentPageNumber"></param>
 /// <returns>FindCompletedItemsResponse</returns>
 private static FindCompletedItemsResponse GetCompletedItems(CustomFindSold service, FindCompletedItemsRequest request, int currentPageNumber)
 {
     request.paginationInput = GetNextPage(currentPageNumber);
     return(service.findCompletedItems(request));
 }
Exemplo n.º 3
0
        static List<VideoCard> GrabPricesFromEbay(string keyword)
        {
            List<VideoCard> foundCards = new List<VideoCard>();

            //setup for console logging of api results
            LoggerService.SetLogger(new ConsoleLogger());
            ILogger logger = LoggerService.GetLogger();

            try
            {
                ClientConfig config = new ClientConfig();
                // Initialize service end-point configuration
                config.EndPointAddress = "http://svcs.sandbox.ebay.com/services/search/FindingService/v1";
                // set eBay developer account AppID
                config.ApplicationId = "JackPetr-b629-4a64-94a2-cb909b9c0c47";

                // Create a service client
                FindingServicePortTypeClient client = FindingServiceClientFactory.getServiceClient(config);

                // Create request object
                FindCompletedItemsRequest completedItemsRequest = new FindCompletedItemsRequest();

                // Set request parameters
                keyword = keyword + " -water -block -waterblock -heatsink -heat -sink";
                completedItemsRequest.keywords = keyword;

                DateTime today = DateTime.UtcNow;
                DateTime month = new DateTime(today.Year, today.Month, 1);
                DateTime lastMonth = month.AddMonths(-1);

                ItemFilter if1 = new ItemFilter();
                if1.name = ItemFilterType.EndTimeFrom;
                if1.value = new string[] {lastMonth.ToString("o")};

                ItemFilter if2 = new ItemFilter();
                if2.name = ItemFilterType.EndTimeTo;
                if2.value = new string[] { today.ToString("o") };

                ItemFilter if3 = new ItemFilter();
                if3.name = ItemFilterType.MinPrice;
                if3.paramName = "Currency";
                if3.paramValue = "USD";
                if3.value = new string[] {"50"};

                ItemFilter if4 = new ItemFilter();
                if4.name = ItemFilterType.MaxPrice;
                if4.paramName = "Currency";
                if4.paramValue = "USD";
                if4.value = new string[] { "1100" };

                ItemFilter if5 = new ItemFilter();
                if5.name = ItemFilterType.ExcludeCategory;
                if5.value = new string[] {"179"};

                ItemFilter[] ifa = new ItemFilter[5];
                ifa[0] = if1;
                ifa[1] = if2;
                ifa[2] = if3;
                ifa[3] = if4;
                ifa[4] = if5;
                completedItemsRequest.itemFilter = ifa;

                PaginationInput pi = new PaginationInput();
                pi.entriesPerPage = 200;
                pi.entriesPerPageSpecified = true;
                completedItemsRequest.paginationInput = pi;

                // Call the service
                FindCompletedItemsResponse response = client.findCompletedItems(completedItemsRequest);

                // Show output
                if (Debug)
                    if (response.ack.ToString().Equals("Failure"))
                    {
                        int tries = 0;
                        while (tries < 3)
                        {
                            if (response.ack.ToString().Equals("Failure"))
                            {
                                //retry
                                tries++;
                                response = client.findCompletedItems(completedItemsRequest);
                            }else
                            {
                                break;
                            }
                    }
                }
                logger.Info("Ack = " + response.ack);
                logger.Info("Find " + response.searchResult.count + " items.");
                SearchItem[] items = response.searchResult.item;

                if(Debug){logSearchResultsToFile(items);}
                foreach (SearchItem item in items)
                {
                    if (item.sellingStatus.sellingState.Equals("EndedWithSales"))
                    {
                        VideoCard trackCard = new VideoCard();
                        trackCard.SetCardName(item.title);
                        trackCard.SetPrice(item.sellingStatus.currentPrice.Value);
                        foundCards.Add(trackCard);

                        logger.Info("Item" + item.title + "added!");
                        logger.Info(item.sellingStatus.currentPrice.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle exception if any
                logger.Error(ex);
            }

            return foundCards;
        }