Sha256: b4aaebc5771b4bb194766b81aded53bb68ab1c36d4199b33fcaccc4ceb712d4f

Contents?: true

Size: 535 Bytes

Versions: 9

Compression:

Stored size: 535 Bytes

Contents

require 'active_interaction'
require 'net/http'
require 'oga'

module MercadolibreApi
  module Products
    module Queries
      class SoldQuantity < ActiveInteraction::Base
        string :product_url

        def execute
          response = Net::HTTP.get(product_uri).force_encoding('UTF-8')
          document = Oga.parse_html(response)
          document.at_css('.item-conditions').text.scan(/\d+/).join.to_i
        end

        private

        def product_uri
          URI(product_url)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mercadolibre_api-0.10 lib/mercadolibre_api/products/queries/sold_quantity.rb
mercadolibre_api-0.9 lib/mercadolibre_api/products/queries/sold_quantity.rb
mercadolibre_api-0.8 lib/mercadolibre_api/products/queries/sold_quantity.rb
mercadolibre_api-0.7 lib/mercadolibre_api/products/queries/sold_quantity.rb
mercadolibre_api-0.6 lib/mercadolibre_api/products/queries/sold_quantity.rb
mercadolibre_api-0.5 lib/mercadolibre_api/products/queries/sold_quantity.rb
mercadolibre_api-0.4 lib/mercadolibre_api/products/queries/sold_quantity.rb
mercadolibre_api-0.3 lib/mercadolibre_api/products/queries/sold_quantity.rb
mercadolibre_api-0.2 lib/mercadolibre_api/products/queries/sold_quantity.rb