Sha256: 9828bde8abcd21c9a32285abe8f5d9f96a4543873d8bb5b523f51d205e0c2357
Contents?: true
Size: 1009 Bytes
Versions: 5
Compression:
Stored size: 1009 Bytes
Contents
require 'active_interaction' require 'net/http' module MercadolibreApi module Products module Queries class Find < ActiveInteraction::Base string :product_id def execute response = Net::HTTP.get_response(product_uri) response_body = JSON.parse(response.body, symbolize_names: true) sold_quantity = MercadolibreApi::Products::Queries::SoldQuantity.run!(product_url: response_body[:permalink]) description = MercadolibreApi::Products::Descriptions::Queries::Find.run!( product_id: product_id, description_id: response_body[:descriptions].dig(0, :id) ) response_body[:description] = description response_body[:confirmed_sold_quantity] = sold_quantity MercadolibreApi::Products::Entities::Product.represent(response_body).as_json end private def product_uri URI("https://api.mercadolibre.com/items/#{product_id}") end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems