我shopify_api在 Ruby 中使用 Shopify 的 gem。
我正在从外部来源更新每个产品的成本和价格,但是我达到了 API 限制并收到了429 Too Many Requests(https://help.shopify.com/en/api/reference/rest-admin-api-rate-limits)。
如何编辑以下内容以遵守 API 限制?
我宁愿使用X-Shopify-Shop-Api-Call-Limit和中提供的数据Retry-After,而不是添加固定的sleep.
products = ShopifyAPI::Product.find(:all, :params => {:limit => limit})
products.each do |product|
variant = ShopifyAPI::Variant.find(product.variants.first.id)
variant.price = price
variant.save
inventoryitem = ShopifyAPI::InventoryItem.find(product.variants.first.inventory_item_id)
inventoryitem.cost = cost
inventoryitem.save
end
end
Run Code Online (Sandbox Code Playgroud) 如何在Ruby中为数字添加百分比?
在这个例子中,我想添加20%到32.92:
irb(main):001:0> 32.92 * (1 + (20 / 100))
=> 32.92
Run Code Online (Sandbox Code Playgroud)
Google回答正确的答案;39.50。