Tuesday 27 December 2016

Fetching top 50 sold products and their hit count of ebay's seller through Ruby On Rails

For fetching top 50 sold products of ebay's seller, we will call GetSellerEvents api of Trading Api.

As we know that ebay provide Trading Api's.Trading API follows eBay’s traditional listing model, where all aspects of a listing (description, product details, quantity and price, etc.) are created and managed.

So, we will integrate Trading Api's in our application. For this please follow my previous blog :

Authentication for ebay's seller and use Trading Api for getting seller information.

From above mentioned blog you can get ebay client. Which is necessary to call any api's of Trading Api.

Now, we will call GetSellerEvents api through this ebay client.

def get_top_selling_items(limit= 50)
      begin
        @ebay_client.get_seller_events(:StartTimeFrom => (Time.now.utc - 120.days).to_s).payload[:item_array][:item]
            .collect { |item| {item_id: item[:item_id],
                               sold_quantity: item[:selling_status][:quantity_sold],
                               item_title: item[:title],
                               hit_count: item[:hit_count]} }
            .sort { |x, y| y[:sold_quantity] <=> x[:sold_quantity] }
            .take(limit)
      rescue => e
        Rails.logger.debug("Exception occurred while fetching/get_top_selling_items: #{e.message}")
        nil
      end
    end

In above code you can set any Time of within last four month. Because ebay provides information of only last four month.

As you can see that in above code we are fetching seller events of last four month. After that we collecting sold quantity and hit count of that particular item. After collecting we are sorting it on the basis of sold quantity.

On the behalf of this, it will provide top 50 sold products and their hit count of that seller.

1 comment:

  1. really Good blog post.provided a helpful information.I hope that you will post more updates like thisRuby on Rails Online Course Bangalore

    ReplyDelete