Delete product images using the Ruby bootic API client.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bootic_client' | |
# Configure the client with your credentials | |
BooticClient.configure do |c| | |
c.client_id = 'MY_CLIENT_ID' | |
c.client_secret = 'MY_CLIENT_SECRET' | |
c.logger = Logger.new(STDOUT) # optional | |
c.logging = true # optional | |
c.cache_store = Rails.cache # optional | |
end | |
# Instantiate a client | |
client = BooticClient.client(:client_credentials, scope: 'admin') | |
# Fetch the root resource and your default shop | |
root = client.root | |
shop = root.shops.first | |
# Iterate products and delete all images. | |
# | |
shop.products(status: 'all').full_set.each do |product| | |
# Fetch each product's detail resource | |
# so we can get ALL of its images | |
product = product.self | |
if product.has?(:images) | |
product.images.each do |a| | |
if a.has?(:delete_product_asset) | |
a.delete_product_asset | |
puts "Deleted #{product.slug}: #{a.file_name}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment