Ejemplo n.º 1
0
        public List <MarketplaceCategoryDto> GetSuggestedCategories(string keyword)
        {
            // create and init the API Context
            var context = new ApiContext();

            context.ApiCredential    = RequestHelper.ApiCredential;
            context.SoapApiServerUrl = RequestHelper.ServiceUrl;

            try
            {
                // create the API call object and pass the keyword
                var apiCall    = new GetSuggestedCategoriesCall(context);
                var categories = apiCall.GetSuggestedCategories(keyword);

                var results = new List <MarketplaceCategoryDto>();
                foreach (SuggestedCategoryType item in categories)
                {
                    results.Add(new MarketplaceCategoryDto
                    {
                        Id   = Convert.ToInt32(item.Category.CategoryID),
                        Name = string.Format("{0} > {1}", string.Join(" > ", item.Category.CategoryParentName.ToArray()),
                                             item.Category.CategoryName)
                    });
                }

                return(results.OrderBy(o => o.Name).ToList());
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEntryType.eBayProductProvider,
                                 string.Format("Unexpected error in getting suggested categories for \"{0}\". Err Message: {1}", keyword, EisHelper.GetExceptionMessage(ex)),
                                 ex.StackTrace);
                return(null);
            }
        }
Ejemplo n.º 2
0
        private void BtnGetSuggestedCategories_Click(object sender, System.EventArgs e)
        {
            try
            {
                LstCategories.Items.Clear();

                GetSuggestedCategoriesCall apicall = new GetSuggestedCategoriesCall(Context);

                SuggestedCategoryTypeCollection cats = apicall.GetSuggestedCategories(TxtQuery.Text);

                if (cats != null)
                {
                    foreach (SuggestedCategoryType category in cats)
                    {
                        string[] listparams = new string[3];
                        listparams[0] = category.Category.CategoryID;
                        listparams[1] = String.Join(" : ", category.Category.CategoryParentName.ToArray()) + " : " + category.Category.CategoryName;
                        listparams[2] = category.PercentItemFound.ToString();

                        ListViewItem vi = new ListViewItem(listparams);
                        this.LstCategories.Items.Add(vi);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public static SuggestedCategoryType[] FindCategories(string eBayToken, string searchTerm)
        {
            var client = GetSdkClient();

            client.ApiCredential.eBayToken = eBayToken;
            var req        = new GetSuggestedCategoriesCall(client);
            var categories = req.GetSuggestedCategories(searchTerm).Cast <SuggestedCategoryType>().ToArray();

            return(categories);
        }
        public void GetSuggestedCategories()
        {
            GetSuggestedCategoriesCall api = new GetSuggestedCategoriesCall(this.apiContext);

            api.Query = "DVD";
            SuggestedCategoryTypeCollection cats = api.GetSuggestedCategories(api.Query);

            //check whether the call is success.
            Assert.IsTrue(api.ApiResponse.Ack == AckCodeType.Success || api.ApiResponse.Ack == AckCodeType.Warning, "the call is failure!");
            Assert.IsNotNull(cats);
            Assert.IsTrue(cats.Count > 0);
            //check the category number is right
            Assert.AreEqual(cats.Count, api.ApiResponse.CategoryCount);
        }
        public async Task <SuggestedCategoryTypeCollection> GetSuggestedCategories(CommerceContext commerceContext, string query)
        {
            using (var activity = CommandActivity.Start(commerceContext, this))
            {
                try
                {
                    var getSuggestedCategories = new GetSuggestedCategoriesCall(await GetEbayContext(commerceContext).ConfigureAwait(false));
                    var result = getSuggestedCategories.GetSuggestedCategories(query);

                    return(result);
                }
                catch (Exception ex)
                {
                    commerceContext.Logger.LogError($"Ebay.GetCategories.Exception: Message={ex.Message}");
                    //await commerceContext.AddMessage("Error", "Ebay.GetCategories.Exception", new Object[] { ex }, ex.Message);
                }
                return(new SuggestedCategoryTypeCollection());
            }
        }
        public eBayCategoryResult GeteBaySuggestedCategories(string eisSku, string keyword)
        {
            try
            {
                // create the API call object and pass the keyword
                var apiCall    = new GetSuggestedCategoriesCall(_context);
                var categories = apiCall.GetSuggestedCategories(keyword);
                if (categories == null)
                {
                    Console.WriteLine("NO EBAY SUGGESSTED CATEGORIES FOUND FOR {0} - {1}", eisSku, keyword);
                    _logger.LogWarning(LogEntryType.eBaySuggestedCategoriesWorker, string.Format("No eBay categories found for EIS SKU: {0} - Keyword: {1}", eisSku, keyword));
                    return(null);
                }

                var results = new List <eBayCategory>();
                foreach (SuggestedCategoryType item in categories)
                {
                    results.Add(new eBayCategory
                    {
                        Id   = Convert.ToInt32(item.Category.CategoryID),
                        Name = string.Format("{0} > {1}", string.Join(" > ", item.Category.CategoryParentName.ToArray()),
                                             item.Category.CategoryName)
                    });
                }

                return(new eBayCategoryResult
                {
                    EisSKU = eisSku,
                    Categories = results
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEntryType.eBaySuggestedCategoriesWorker,
                                 string.Format("Unexpected error in getting suggested categories for \"{0}\". Err Message: {1}", keyword, EisHelper.GetExceptionMessage(ex)),
                                 ex.StackTrace);
                return(null);
            }
        }