Thursday 5 January 2017

Fetching recent sold products and their sold quantity of ebay's seller through Ruby On Rails


For fetching recent sold products of ebay's seller, we will call GetSellerTransactions 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 GetSellerTransactions api through this ebay client.

def get_recent_sold_items
  begin
    inference_hash = {}
    recent_sold_items = @ebay_client.get_seller_transactions.payload
    transactions = recent_sold_items[:transaction_array][:transaction] rescue []
    transactions.each do |transaction|
      item = transaction[:item] rescue nil
      if item
        inference_hash[item[:item_id]] ||= {sold_count: 0, last_sold_at: (Time.now - 10.years)}
        inference_hash[item[:item_id]][:last_sold_at] = transaction[:created_date] if transaction[:created_date] > inference_hash[item[:item_id]][:last_sold_at]
        inference_hash[item[:item_id]][:sold_count] = (inference_hash[item[:item_id]][:sold_count] + item[:selling_status][:quantity_sold].to_i)
      end
    end
  rescue => e
    Rails.logger.debug("Exception occurred while fetching/get_recent_sold_items: #{e.message}")
    nil
end

From above method you will get recent sold product and their sold quantity.

No comments:

Post a Comment